PageRenderTime 33ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

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