Addons.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 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. void Clear();
  42. asUINT GetSize() const;
  43. bool IsEmpty() const;
  44. // Get a pointer to an element. Returns 0 if out of bounds
  45. void* At(asUINT index);
  46. CScriptArray& operator = (const CScriptArray&);
  47. // TODO: Add methods Sort, Reverse, Find, etc
  48. void InsertAt(asUINT index, void *value);
  49. void RemoveAt(asUINT index);
  50. void InsertLast(void *value);
  51. void RemoveLast();
  52. protected:
  53. mutable int refCount;
  54. mutable bool gcFlag;
  55. asIObjectType* objType;
  56. SArrayBuffer* buffer;
  57. bool isArrayOfHandles;
  58. int elementSize;
  59. bool CheckMaxSize(asUINT numElements);
  60. void Resize(int delta, asUINT at);
  61. void SetValue(asUINT index, void *value);
  62. void CreateBuffer(SArrayBuffer** buf, asUINT numElements);
  63. void DeleteBuffer(SArrayBuffer* buf);
  64. void CopyBuffer(SArrayBuffer* dst, SArrayBuffer* src);
  65. void Construct(SArrayBuffer* buf, asUINT start, asUINT end);
  66. void Destruct(SArrayBuffer* buf, asUINT start, asUINT end);
  67. };
  68. /// Register the array type to script
  69. void RegisterArray(asIScriptEngine* engine);
  70. /// Register String to script
  71. void RegisterString(asIScriptEngine* engine);