2013-10-12 15:25:45 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2012 cocos2d-x.org
|
2015-12-03 20:00:51 +08:00
|
|
|
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCDICTIONARY_H__
|
|
|
|
#define __CCDICTIONARY_H__
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "base/uthash.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "deprecated/CCArray.h"
|
2014-04-09 22:30:49 +08:00
|
|
|
#include "deprecated/CCString.h"
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-12-11 14:39:21 +08:00
|
|
|
class __Dictionary;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup data_structures
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DictElement is used for traversing Dictionary.
|
|
|
|
*
|
|
|
|
* A DictElement is one element of Dictionary, it contains two properties, key and object.
|
|
|
|
* Its key has two different type (integer and string).
|
|
|
|
*
|
|
|
|
* @note The key type is unique, all the elements in Dictionary has the same key type(integer or string).
|
|
|
|
* @code
|
|
|
|
* DictElement* pElement;
|
|
|
|
* CCDICT_FOREACH(dict, pElement)
|
|
|
|
* {
|
|
|
|
* const char*key = pElement->getStrKey();
|
|
|
|
* // You certainly know the type of value, so we assume that it's a Sprite.
|
|
|
|
* Sprite* pSprite = static_cast<Sprite*>(pElement->getObject());
|
|
|
|
* // ......
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class CC_DLL DictElement
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Constructor of DictElement. It's only for internal usage. Dictionary is its friend class.
|
|
|
|
*
|
|
|
|
* @param pszKey The string key of this element.
|
|
|
|
* @param pObject The object of this element.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
DictElement(const char* pszKey, Ref* pObject);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of DictElement. It's only for internal usage. Dictionary is its friend class.
|
|
|
|
*
|
|
|
|
* @param iKey The integer key of this element.
|
|
|
|
* @param pObject The object of this element.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
DictElement(intptr_t iKey, Ref* pObject);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The destructor of DictElement.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
~DictElement();
|
|
|
|
|
|
|
|
// Inline functions need to be implemented in header file on Android.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the string key of this element.
|
|
|
|
* @note This method assumes you know the key type in the element.
|
|
|
|
* If the element's key type is integer, invoking this method will cause an assert.
|
|
|
|
*
|
|
|
|
* @return The string key of this element.
|
|
|
|
*/
|
|
|
|
inline const char* getStrKey() const
|
|
|
|
{
|
|
|
|
CCASSERT(_strKey[0] != '\0', "Should not call this function for integer dictionary");
|
|
|
|
return _strKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the integer key of this element.
|
|
|
|
* @note This method assumes you know the key type in the element.
|
|
|
|
* If the element's key type is string, invoking this method will cause an assert.
|
|
|
|
*
|
|
|
|
* @return The integer key of this element.
|
|
|
|
*/
|
|
|
|
inline intptr_t getIntKey() const
|
|
|
|
{
|
|
|
|
CCASSERT(_strKey[0] == '\0', "Should not call this function for string dictionary");
|
|
|
|
return _intKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the object of this element.
|
|
|
|
*
|
|
|
|
* @return The object of this element.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
inline Ref* getObject() const { return _object; }
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// The max length of string key.
|
|
|
|
#define MAX_KEY_LEN 256
|
|
|
|
// char array is needed for HASH_ADD_STR in UT_HASH.
|
|
|
|
// So it's a pain that all elements will allocate 256 bytes for this array.
|
|
|
|
char _strKey[MAX_KEY_LEN]; // hash key of string type
|
|
|
|
intptr_t _intKey; // hash key of integer type
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* _object; // hash value
|
2013-10-12 15:25:45 +08:00
|
|
|
public:
|
|
|
|
UT_hash_handle hh; // makes this class hashable
|
2013-12-11 14:39:21 +08:00
|
|
|
friend class __Dictionary; // declare Dictionary as friend class
|
2013-10-12 15:25:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** The macro for traversing dictionary
|
|
|
|
*
|
|
|
|
* @note It's faster than getting all keys and traversing keys to get objects by objectForKey.
|
|
|
|
* It's also safe to remove elements while traversing.
|
|
|
|
*/
|
|
|
|
#define CCDICT_FOREACH(__dict__, __el__) \
|
|
|
|
DictElement* pTmp##__dict__##__el__ = nullptr; \
|
|
|
|
if (__dict__) \
|
|
|
|
HASH_ITER(hh, (__dict__)->_elements, __el__, pTmp##__dict__##__el__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dictionary is a class like NSDictionary in Obj-C .
|
|
|
|
*
|
|
|
|
* @note Only the pointer of Object or its subclass can be inserted to Dictionary.
|
|
|
|
* @code
|
|
|
|
* // Create a dictionary, return an autorelease object.
|
|
|
|
* Dictionary* pDict = Dictionary::create();
|
|
|
|
*
|
|
|
|
* // Insert objects to dictionary
|
2013-12-12 09:53:50 +08:00
|
|
|
* String* pValue1 = String::create("100");
|
|
|
|
* String* pValue2 = String::create("120");
|
2013-10-12 15:25:45 +08:00
|
|
|
* Integer* pValue3 = Integer::create(200);
|
|
|
|
* pDict->setObject(pValue1, "key1");
|
|
|
|
* pDict->setObject(pValue2, "key2");
|
|
|
|
* pDict->setObject(pValue3, "key3");
|
|
|
|
*
|
|
|
|
* // Get the object for key
|
2013-12-12 09:53:50 +08:00
|
|
|
* String* pStr1 = static_cast<String*>(pDict->objectForKey("key1"));
|
|
|
|
* log("{ key1: %s }", pStr1->getCString());
|
|
|
|
* Integer* pInteger = static_cast<Integer*>(pDict->objectForKey("key3"));
|
2013-10-12 15:25:45 +08:00
|
|
|
* log("{ key3: %d }", pInteger->getValue());
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL __Dictionary : public Ref, public Clonable
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The constructor of Dictionary.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
__Dictionary();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The destructor of Dictionary
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
~__Dictionary();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/** Initializes the dictionary. It returns true if the initializations was successful.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
bool init();
|
|
|
|
/**
|
|
|
|
* Get the count of elements in Dictionary.
|
|
|
|
*
|
|
|
|
* @return The count of elements.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
unsigned int count();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all keys of elements.
|
|
|
|
*
|
|
|
|
* @return The array contains all keys of elements. It's an autorelease object yet.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-07 10:48:02 +08:00
|
|
|
__Array* allKeys();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all keys according to the specified object.
|
|
|
|
* @warning We use '==' to compare two objects
|
|
|
|
* @return The array contains all keys for the specified object. It's an autorelease object yet.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
__Array* allKeysForObject(Ref* object);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the object according to the specified string key.
|
|
|
|
*
|
|
|
|
* @note The dictionary needs to use string as key. If integer is passed, an assert will appear.
|
|
|
|
* @param key The string key for searching.
|
|
|
|
* @return The object matches the key. You need to force convert it to the type you know.
|
|
|
|
* @code
|
2013-12-12 09:53:50 +08:00
|
|
|
* // Assume that the elements are String* pointers. Convert it by following code.
|
|
|
|
* String* pStr = static_cast<String*>(pDict->objectForKey("key1"));
|
2013-10-12 15:25:45 +08:00
|
|
|
* // Do something about pStr.
|
|
|
|
* // If you don't know the object type, properly you need to use dynamic_cast<SomeType*> to check it.
|
2013-12-12 09:53:50 +08:00
|
|
|
* String* pStr2 = dynamic_cast<String*>(pDict->objectForKey("key1"));
|
2013-10-12 15:25:45 +08:00
|
|
|
* if (pStr2 != NULL) {
|
|
|
|
* // Do something about pStr2
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
* @see objectForKey(intptr_t)
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* objectForKey(const std::string& key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the object according to the specified integer key.
|
|
|
|
*
|
|
|
|
* @note The dictionary needs to use integer as key. If string is passed, an assert will appear.
|
|
|
|
* @param key The integer key for searching.
|
|
|
|
* @return The object matches the key.
|
|
|
|
* @see objectForKey(const std::string&)
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* objectForKey(intptr_t key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/** Get the value according to the specified string key.
|
|
|
|
*
|
2013-12-11 17:15:27 +08:00
|
|
|
* @note Be careful to use this function since it assumes the objects in the dictionary are __String pointer.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @param key The string key for searching
|
2013-12-12 09:53:50 +08:00
|
|
|
* @return An instance of String.
|
2013-12-11 17:15:27 +08:00
|
|
|
* It will return an empty string if the objects aren't __String pointer or the key wasn't found.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @see valueForKey(intptr_t)
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-11 17:15:27 +08:00
|
|
|
const __String* valueForKey(const std::string& key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/** Get the value according to the specified integer key.
|
|
|
|
*
|
2013-12-11 17:15:27 +08:00
|
|
|
* @note Be careful to use this function since it assumes the objects in the dictionary are __String pointer.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @param key The string key for searching.
|
2013-12-12 09:53:50 +08:00
|
|
|
* @return An instance of String.
|
2013-12-11 17:15:27 +08:00
|
|
|
* It will return an empty string if the objects aren't __String pointer or the key wasn't found.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @see valueForKey(intptr_t)
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-11 17:15:27 +08:00
|
|
|
const __String* valueForKey(intptr_t key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/** Insert an object to dictionary, and match it with the specified string key.
|
|
|
|
*
|
2016-02-18 15:16:36 +08:00
|
|
|
* @note When the first time this method is invoked, the key type will be set to string.
|
2013-10-12 15:25:45 +08:00
|
|
|
* After that you can't setObject with an integer key.
|
|
|
|
* If the dictionary contains the key you passed, the object matching the key will be released and removed from dictionary.
|
|
|
|
* Then the new object will be inserted after that.
|
|
|
|
*
|
|
|
|
* @param pObject The Object to be inserted.
|
|
|
|
* @param key The string key for searching.
|
2014-02-20 10:53:49 +08:00
|
|
|
* @see setObject(Ref*, intptr_t)
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
void setObject(Ref* pObject, const std::string& key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/** Insert an object to dictionary, and match it with the specified string key.
|
|
|
|
*
|
|
|
|
* @note Then the first time this method is invoked, the key type will be set to string.
|
|
|
|
* After that you can't setObject with an integer key.
|
|
|
|
* If the dictionary contains the key you passed, the object matching the key will be released and removed from dictionary.
|
|
|
|
* Then the new object will be inserted after that.
|
|
|
|
* @param pObject The Object to be inserted.
|
|
|
|
* @param key The string key for searching.
|
2014-02-20 10:53:49 +08:00
|
|
|
* @see setObject(Ref*, const std::string&)
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
void setObject(Ref* pObject, intptr_t key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an object by the specified string key.
|
|
|
|
*
|
|
|
|
* @param key The string key for searching.
|
2013-12-07 10:48:02 +08:00
|
|
|
* @see removeObjectForKey(intptr_t), removeObjectsForKeys(__Array*),
|
2013-10-12 15:25:45 +08:00
|
|
|
* removeObjectForElememt(DictElement*), removeAllObjects().
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void removeObjectForKey(const std::string& key);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an object by the specified integer key.
|
|
|
|
*
|
|
|
|
* @param key The integer key for searching.
|
2013-12-07 10:48:02 +08:00
|
|
|
* @see removeObjectForKey(const std::string&), removeObjectsForKeys(__Array*),
|
2013-10-12 15:25:45 +08:00
|
|
|
* removeObjectForElememt(DictElement*), removeAllObjects().
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void removeObjectForKey(intptr_t key);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove objects by an array of keys.
|
|
|
|
*
|
2013-12-12 09:53:50 +08:00
|
|
|
* @param pKeyArray The array contains keys to be removed.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
|
|
|
|
* removeObjectForElememt(DictElement*), removeAllObjects().
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-07 10:48:02 +08:00
|
|
|
void removeObjectsForKeys(__Array* pKey__Array);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an object by an element.
|
|
|
|
*
|
|
|
|
* @param pElement The element need to be removed.
|
|
|
|
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
|
2013-12-07 10:48:02 +08:00
|
|
|
* removeObjectsForKeys(__Array*), removeAllObjects().
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void removeObjectForElememt(DictElement* pElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all objects in the dictionary.
|
|
|
|
*
|
|
|
|
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
|
2013-12-07 10:48:02 +08:00
|
|
|
* removeObjectsForKeys(__Array*), removeObjectForElememt(DictElement*).
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void removeAllObjects();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random object in the dictionary.
|
|
|
|
*
|
|
|
|
* @return The random object.
|
|
|
|
* @see objectForKey(intptr_t), objectForKey(const std::string&)
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* randomObject();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dictionary.
|
|
|
|
* @return A dictionary which is an autorelease object.
|
|
|
|
* @see createWithDictionary(Dictionary*), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*).
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
static __Dictionary* create();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dictionary with an existing dictionary.
|
|
|
|
*
|
|
|
|
* @param srcDict The exist dictionary.
|
|
|
|
* @return A dictionary which is an autorelease object.
|
|
|
|
* @see create(), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*).
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
static __Dictionary* createWithDictionary(__Dictionary* srcDict);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dictionary with a plist file.
|
|
|
|
* @param pFileName The name of the plist file.
|
|
|
|
* @return A dictionary which is an autorelease object.
|
|
|
|
* @see create(), createWithDictionary(Dictionary*), createWithContentsOfFileThreadSafe(const char*).
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
static __Dictionary* createWithContentsOfFile(const char *pFileName);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a dictionary to a plist file.
|
2015-09-22 16:08:23 +08:00
|
|
|
* @param fullPath The full path of the plist file. You can get writable path by getWritablePath()
|
|
|
|
* @return true if succeeded, false if failed
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
bool writeToFile(const char *fullPath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dictionary with a plist file.
|
|
|
|
*
|
|
|
|
* @note the return object isn't an autorelease object.
|
|
|
|
* This can make sure not using autorelease pool in a new thread.
|
|
|
|
* Therefore, you need to manage the lifecycle of the return object.
|
|
|
|
* It means that when you don't need it, CC_SAFE_RELEASE needs to be invoked.
|
|
|
|
*
|
|
|
|
* @param pFileName The name of the plist file.
|
|
|
|
* @return A dictionary which isn't an autorelease object.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
static __Dictionary* createWithContentsOfFileThreadSafe(const char *pFileName);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/* override functions
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void acceptVisitor(DataVisitor &visitor);
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-11 14:39:21 +08:00
|
|
|
virtual __Dictionary* clone() const;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* For internal usage, invoked by setObject.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
void setObjectUnSafe(Ref* pObject, const std::string& key);
|
|
|
|
void setObjectUnSafe(Ref* pObject, const intptr_t key);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* All the elements in dictionary.
|
|
|
|
*
|
|
|
|
* @note For internal usage, we need to declare this member variable as public since it's used in UT_HASH.
|
|
|
|
*/
|
|
|
|
DictElement* _elements;
|
|
|
|
private:
|
|
|
|
|
|
|
|
/** The support type of dictionary, it's confirmed when setObject is invoked. */
|
|
|
|
enum DictType
|
|
|
|
{
|
|
|
|
kDictUnknown = 0,
|
|
|
|
kDictStr,
|
|
|
|
kDictInt
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of dictionary, it's assigned to kDictUnknown by default.
|
|
|
|
*/
|
|
|
|
DictType _dictType;
|
|
|
|
};
|
|
|
|
|
|
|
|
// end of data_structure group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|
2013-10-12 15:25:45 +08:00
|
|
|
#endif /* __CCDICTIONARY_H__ */
|