/**
* CCDictionary is a class like NSDictionary in Obj-C .
*
* @note Only the pointer of CCObject or its subclass can be inserted to CCDictionary.
* @code
* // Create a dictionary, return an autorelease object.
* CCDictionary* pDict = CCDictionary::create();
*
* // Insert objects to dictionary
* CCString* pValue1 = CCString::create("100");
* CCString* pValue2 = CCString::create("120");
* CCInteger* pValue3 = CCInteger::create(200);
* pDict->setObject(pValue1, "key1");
* pDict->setObject(pValue2, "key2");
* pDict->setObject(pValue3, "key3");
*
* // Get the object for key
* CCString* pStr1 = (CCString*)pDict->objectForKey("key1");
* CCLog("{ key1: %s }", pStr1->getCString());
* CCInteger* pInteger = (CCInteger*)pDict->objectForKey("key3");
* CCLog("{ key3: %d }", pInteger->getValue());
* @endcode
*
*/ class CC_DLL CCDictionary : public CCObject
{
public:
/**
* The constructor of CCDictionary.
*/
CCDictionary(); /**
* The destructor of CCDictionary
*/
~CCDictionary(); /**
* Get the count of elements in CCDictionary.
*
* @return The count of elements.
*/
unsigned int count(); /**
* Return all keys of elements.
*
* @return The array contains all keys of elements. It's an autorelease object yet.
*/
CCArray* allKeys(); /**
* 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.
*/
CCArray* allKeysForObject(CCObject* object); /**
* 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
* // Assume that the elements are CCString* pointers. Convert it by following code.
* CCString* pStr = (CCString*)pDict->objectForKey("key1");
* // Do something about pStr.
* // If you don't know the object type, properly you need to use dynamic_cast<SomeType*> to check it.
* CCString* pStr2 = dynamic_cast<CCString*>(pDict->objectForKey("key1"));
* if (pStr2 != NULL) {
* // Do something about pStr2
* }
* @endcode
* @see objectForKey(intptr_t)
*/
CCObject* objectForKey(const std::string& key); /**
* 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&)
*/
CCObject* objectForKey(intptr_t key); /** Get the value according to the specified string key.
*
* @note Be careful to use this function since it assumes the objects in the dictionary are CCString pointer.
* @param key The string key for searching
* @return An instance of CCString.
* It will return an empty string if the objects aren't CCString pointer or the key wasn't found.
* @see valueForKey(intptr_t)
*/
const CCString* valueForKey(const std::string& key); /** Get the value according to the specified integer key.
*
* @note Be careful to use this function since it assumes the objects in the dictionary are CCString pointer.
* @param key The string key for searching.
* @return An instance of CCString.
* It will return an empty string if the objects aren't CCString pointer or the key wasn't found.
* @see valueForKey(intptr_t)
*/
const CCString* valueForKey(intptr_t key); /** Insert an object to dictionary, and match it with the specified string key.
*
* @note Whe 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.
* @see setObject(CCObject*, intptr_t)
*/
void setObject(CCObject* pObject, const std::string& key); /** 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.
* @see setObject(CCObject*, const std::string&)
*/
void setObject(CCObject* pObject, intptr_t key); /**
* Remove an object by the specified string key.
*
* @param key The string key for searching.
* @see removeObjectForKey(intptr_t), removeObjectsForKeys(CCArray*),
* removeObjectForElememt(CCDictElement*), removeAllObjects().
*/
void removeObjectForKey(const std::string& key); /**
* Remove an object by the specified integer key.
*
* @param key The integer key for searching.
* @see removeObjectForKey(const std::string&), removeObjectsForKeys(CCArray*),
* removeObjectForElememt(CCDictElement*), removeAllObjects().
*/
void removeObjectForKey(intptr_t key); /**
* Remove objects by an array of keys.
*
* @param pKeyArray The array contains keys to be removed.
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
* removeObjectForElememt(CCDictElement*), removeAllObjects().
*/
void removeObjectsForKeys(CCArray* pKeyArray); /**
* Remove an object by an element.
*
* @param pElement The element need to be removed.
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
* removeObjectsForKeys(CCArray*), removeAllObjects().
*/
void removeObjectForElememt(CCDictElement* pElement); /**
* Remove all objects in the dictionary.
*
* @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t),
* removeObjectsForKeys(CCArray*), removeObjectForElememt(CCDictElement*).
*/
void removeAllObjects(); /// @{
/// @name Function override
/**
* This function is used for deepcopy elements from source dictionary to destination dictionary.
* You shouldn't invoke this function manually since it's called by CCObject::copy.
*/
virtual CCObject* copyWithZone(CCZone* pZone);
/// @} /**
* Return a random object in the dictionary.
*
* @return The random object.
* @see objectForKey(intptr_t), objectForKey(const std::string&)
*/
CCObject* randomObject(); /**
* Create a dictionary.
* @return A dictionary which is an autorelease object.
* @see createWithDictionary(CCDictionary*), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*).
*/
static CCDictionary* create(); /**
* 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*).
*/
static CCDictionary* createWithDictionary(CCDictionary* srcDict); /**
* 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(CCDictionary*), createWithContentsOfFileThreadSafe(const char*).
*/
static CCDictionary* createWithContentsOfFile(const char *pFileName); /**
* 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.
*/
static CCDictionary* createWithContentsOfFileThreadSafe(const char *pFileName); private:
/**
* For internal usage, invoked by setObject.
*/
void setObjectUnSafe(CCObject* pObject, const std::string& key);
void setObjectUnSafe(CCObject* pObject, const intptr_t key); 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.
*/
CCDictElement* m_pElements;
private: /** The support type of dictionary, it's confirmed when setObject is invoked. */
enum CCDictType
{
kCCDictUnknown = ,
kCCDictStr,
kCCDictInt
}; /**
* The type of dictionary, it's assigned to kCCDictUnknown by default.
*/
CCDictType m_eDictType;
};

CCDictionary的更多相关文章

  1. cocos2d CCDictionary

    CCDictionary* dict=CCDictionary::create(); CCString* str1=CCString::create("); CCString* str2=C ...

  2. CCDictionary&CCArray执行retain()重要点

    CCDictionary也需要执行retain(),否则则跟CCArray,返回则释放对象. 在Lua中,忘记了retain(),导致一些出现gCCDictionary:objectForKey(ke ...

  3. 7.数据本地化CCString,CCArray,CCDictionary,tinyxml2,写入UserDefault.xml文件,操作xml,解析xml

     数据本地化 A CCUserDefault 系统会在默认路径cocos2d-x-2.2.3\projects\Hello\proj.win32\Debug.win32下生成一个名为UserDef ...

  4. CCDictionary(转)

    #ifndef __CCDICTIONARY_H__ #define __CCDICTIONARY_H__ //需要哈希表的支持 #include "support/data_support ...

  5. cocos2d-x3.0 用CCDictionary写文件

    bool CDownLoad_LocalData::WriteToConfigFile( DownLoadLocalData* downdata ){ CCDictionary* pDict = CC ...

  6. CCDictionary 用调试器查看问题

    if(dic->objectForKey("uid")) uid = dic->valueForKey("uid")->getCString( ...

  7. !cocos2d ccdictionary->retain()的问题

    我再a类当中生命了一个dict,将它带入到b类当中,但没有在b类初始化时retain,于是在update当中找不到了.啃爹不.记得retain()

  8. 【Cocos2d-x for WP8 学习整理】(5)文字显示全整理

    学习 Cocos2d-x 有一阵了,现在要做个小东西,第一步就遇到了文字展示的问题,于是想把可能遇到的问题统统整理一下.这一部分也不局限于wp8,全平台应该都是一个解决方案. 先在脑袋里大致想了一下, ...

  9. [原创]cocos2d-x研习录-第三阶 特性之瓦片地图集

    由于一张大的世界地图或背景图片往往可以由屈指可数的几种地形来表示,每种地形对应于一张小的图片,我们称这些小的地形图片为瓦片.把这些瓦片拼接在一起,组合成一个完整的地图,这就是瓦片地图集的基本原理. C ...

随机推荐

  1. Kafka 配置

    安装 解压放到/opt/kafka, 软链一个latest出来, 先要启动zookeeper. 可以使用独立的zookeeper服务, 也可以用kafka自带的, 在lib目录下带了zookeeper ...

  2. Ubuntu x86-64汇编(1)

    x86-64 Assembly Language Programming with Ubuntu 的读书记录 x86计算机体系架构 架构总览 CPU, RAM, 存储, 输入输出设备等, 数据的尺寸( ...

  3. ios 中sqlite的用法

    #import <sqlite3.h> @interface ViewController () { sqlite3 *_sqldb; } @end @implementation Vie ...

  4. CocoaAsyncSocket UDP发送数据超过包大小限制(Message too long)

    最近在做iOS上,基于UDP传输音视频时遇到的一个问题,这边纪录一下: 由于考虑实时性比较高,所以采用了 CocoaAsyncSocket 的UDP框架来实现,将视频切割成一帧帧的图片发给服务端,不过 ...

  5. java节假日api--关于节假日想到的

    http://goseek.cn/index.php. 跟一园友讨论节假日问题得之一网址...涨姿势...(仅限中国节假日) http://api.goseek.cn/ 另一网友整理了测试类: htt ...

  6. Using PHP as a Spring MVC View via Quercus(转)

    原贴: http://blog.caucho.com/2009/04/14/using-php-as-a-spring-mvc-view-via-quercus/ This week, I’ve be ...

  7. 【RS】Local Latent Space Models for Top- N Recommendation-利用局部隐含空间模型进行Top-N推荐

    [论文标题]Local Latent Space Models for Top- N Recommendation  (KDD-2018 ) [论文作者]—Evangelia Christakopou ...

  8. 最新的 CocoaPods 的使用教程(一)

    发布开源库到CocoaPods的时候.对CocoaPods重新学习了一下. 1.CocoaPods的日常使用 2.创建CocoaPods的私有库 3.创建CocoaPods的开源库 一. CocoaP ...

  9. 使用JMeter对网站并发性测试

    目录结构: contents structure [+] 1. 下载JMeter 2. 启动JMeter 1) 建立线程. 2) 设置请求服务器.压力链接等信息 3) 查看运行结果 3,分析数据 Ap ...

  10. 【struts2】<s:url>标签

    <s:url>标签一般和超链接 <a>一起使用,用于带多个参数. <a href=" <s:url action=""> < ...