Addons.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include <angelscript.h>
  25. // Adapted from Angelscript's scriptarray & scriptstdstring add-ons, but with garbage collection disabled
  26. struct SArrayBuffer;
  27. /// %Script array type.
  28. class CScriptArray
  29. {
  30. public:
  31. CScriptArray(asUINT length, asIObjectType *ot);
  32. CScriptArray(asUINT length, void *defVal, asIObjectType *ot);
  33. virtual ~CScriptArray();
  34. void AddRef() const;
  35. void Release() const;
  36. // Type information
  37. asIObjectType *GetArrayObjectType() const;
  38. int GetArrayTypeId() const;
  39. int GetElementTypeId() const;
  40. void Resize(asUINT numElements);
  41. asUINT GetSize() const;
  42. // Get a pointer to an element. Returns 0 if out of bounds
  43. void *At(asUINT index);
  44. CScriptArray &operator=(const CScriptArray&);
  45. void InsertAt(asUINT index, void *value);
  46. void RemoveAt(asUINT index);
  47. void InsertLast(void *value);
  48. void RemoveLast();
  49. void SortAsc();
  50. void SortDesc();
  51. void SortAsc(asUINT index, asUINT count);
  52. void SortDesc(asUINT index, asUINT count);
  53. void Sort(asUINT index, asUINT count, bool asc);
  54. void Reverse();
  55. int Find(void *value);
  56. int Find(asUINT index, void *value);
  57. protected:
  58. mutable int refCount;
  59. mutable bool gcFlag;
  60. asIObjectType *objType;
  61. SArrayBuffer *buffer;
  62. int elementSize;
  63. int cmpFuncId;
  64. int eqFuncId;
  65. int subTypeId;
  66. bool Less(const void *a, const void *b, bool asc, asIScriptContext *ctx);
  67. void *GetArrayItemPointer(int index);
  68. void *GetDataPointer(void *buffer);
  69. void Copy(void *dst, void *src);
  70. void Precache();
  71. bool CheckMaxSize(asUINT numElements);
  72. void Resize(int delta, asUINT at);
  73. void SetValue(asUINT index, void *value);
  74. void CreateBuffer(SArrayBuffer **buf, asUINT numElements);
  75. void DeleteBuffer(SArrayBuffer *buf);
  76. void CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src);
  77. void Construct(SArrayBuffer *buf, asUINT start, asUINT end);
  78. void Destruct(SArrayBuffer *buf, asUINT start, asUINT end);
  79. bool Equals(const void *a, const void *b, asIScriptContext *ctx);
  80. };
  81. /// Register the array type to script.
  82. void RegisterArray(asIScriptEngine* engine);
  83. /// Register String to script.
  84. void RegisterString(asIScriptEngine* engine);