/xbmc/visualizations/Vortex/angelscript/add_on/scriptdictionary/scriptdictionary.h

http://github.com/xbmc/xbmc · C++ Header · 98 lines · 52 code · 23 blank · 23 comment · 0 complexity · 4dd814485f2c83ac273b483daa4ada5b MD5 · raw file

  1. #ifndef SCRIPTDICTIONARY_H
  2. #define SCRIPTDICTIONARY_H
  3. // The dictionary class relies on the script string object, thus the script
  4. // string type must be registered with the engine before registering the
  5. // dictionary type
  6. #include <angelscript.h>
  7. #include <string>
  8. #ifdef _MSC_VER
  9. // Turn off annoying warnings about truncated symbol names
  10. #pragma warning (disable:4786)
  11. #endif
  12. #include <map>
  13. BEGIN_AS_NAMESPACE
  14. class CScriptDictionary
  15. {
  16. public:
  17. // Memory management
  18. CScriptDictionary(asIScriptEngine *engine);
  19. void AddRef();
  20. void Release();
  21. // Sets/Gets a variable type value for a key
  22. void Set(const std::string &key, void *value, int typeId);
  23. bool Get(const std::string &key, void *value, int typeId) const;
  24. // Sets/Gets an integer number value for a key
  25. void Set(const std::string &key, asINT64 &value);
  26. bool Get(const std::string &key, asINT64 &value) const;
  27. // Sets/Gets a real number value for a key
  28. void Set(const std::string &key, double &value);
  29. bool Get(const std::string &key, double &value) const;
  30. // Returns true if the key is set
  31. bool Exists(const std::string &key) const;
  32. // Deletes the key
  33. void Delete(const std::string &key);
  34. // Deletes all keys
  35. void DeleteAll();
  36. // Garbage collections behaviours
  37. int GetRefCount();
  38. void SetGCFlag();
  39. bool GetGCFlag();
  40. void EnumReferences(asIScriptEngine *engine);
  41. void ReleaseAllReferences(asIScriptEngine *engine);
  42. protected:
  43. // The structure for holding the values
  44. struct valueStruct
  45. {
  46. union
  47. {
  48. asINT64 valueInt;
  49. double valueFlt;
  50. void *valueObj;
  51. };
  52. int typeId;
  53. };
  54. // We don't want anyone to call the destructor directly, it should be called through the Release method
  55. virtual ~CScriptDictionary();
  56. // Don't allow assignment
  57. CScriptDictionary &operator =(const CScriptDictionary &other);
  58. // Helper methods
  59. void FreeValue(valueStruct &value);
  60. // Our properties
  61. asIScriptEngine *engine;
  62. int refCount;
  63. std::map<std::string, valueStruct> dict;
  64. };
  65. // This function will determine the configuration of the engine
  66. // and use one of the two functions below to register the dictionary object
  67. void RegisterScriptDictionary(asIScriptEngine *engine);
  68. // Call this function to register the math functions
  69. // using native calling conventions
  70. void RegisterScriptDictionary_Native(asIScriptEngine *engine);
  71. // Use this one instead if native calling conventions
  72. // are not supported on the target platform
  73. void RegisterScriptDictionary_Generic(asIScriptEngine *engine);
  74. END_AS_NAMESPACE
  75. #endif