| cocos2d-x 3.0 | 
   
)- 类列表 - 类索引 - 类继承关系 - 类成员
全部) 类) 命名空间) 文件) 函数) 变量) 类型定义) 枚举) 枚举值) 属性) 友元) 宏定义) 组) 页)
Public 成员函数 | 静态 Public 成员函数 | Public 属性 | 所有成员列表
Dictionary类 参考 [Data Structures](../../df/db3/groupdata__structures.html)
Dictionary 就像 Obj-C 中的 NSDictionary . 更多…
#include 
类 __Dictionary 继承关系图:
 
  
| ## Public 成员函数 | |
| __Dictionary () | |
| Dictionary的构造函数. 更多… | |
| ~__Dictionary () | |
| Dictionary的析构函数 NA NA. 更多… | |
| bool | init () | 
| 初始化dictionary. 更多… | |
| unsigned int | count () | 
| 获取Dictionary中元素个数. 更多… | |
| __Array | allKeys () | 
| 返回所有元素的 key. 更多… | |
| __Array | allKeysForObject (Ref object) | 
| 获取根据指定对象条件下的所有key. 更多… | |
| Ref | objectForKey (const std::string &key) | 
| 根据这个特定的string key,获取所有的object. 更多… | |
| Ref | objectForKey (intptr_t key) | 
| 根据特殊的integer key获取object. 更多… | |
| const __String | valueForKey (const std::string &key) | 
| 根据特定的string key,获取值. 更多… | |
| const __String | valueForKey (intptr_t key) | 
| 根据特定的integer key获取值. 更多… | |
| void | setObject (Ref pObject, const std::string &key) | 
| 插入一个对象进dictionary, 匹配插入特定的string key. 更多… | |
| void | setObject (Ref pObject, intptr_t key) | 
| 插入一个对象进dictionary, 用特定的string key匹配它. 更多… | |
| void | removeObjectForKey (const std::string &key) | 
| 根据特定的string key移除对应的对象. 更多… | |
| void | removeObjectForKey (intptr_t key) | 
| 根据特定的integer key,移除对象的对象. 更多… | |
| void | removeObjectsForKeys (__Array pKeyArray) | 
| 根据array中得keys移除对应的所有对象. 更多… | |
| void | [removeObjectForElememt](../../d0/d1a/classcocos2d11_dictionary.html#a9ac330143c005e24307869a8d24af105) (DictElement pElement) | 
| 根据某个元素移除对应的对象 更多… | |
| void | removeAllObjects () | 
| 移除dictionary中所有对象. 更多… | |
| Ref | randomObject () | 
| 返回dictionary中随机的一个对象. 更多… | |
| bool | writeToFile (const char fullPath) | 
| 往plist文件中写入一个dictionary. 更多… | |
| virtual void | acceptVisitor (DataVisitor &visitor) | 
| virtual __Dictionary | clone () const | 
| NA NA 更多… | |
  Public 成员函数 继承自 Ref | |
| void | retain () | 
| 保留所有权. 更多… | |
| void | release () | 
| 立即释放所有权. 更多… | |
| Ref | autorelease () | 
| 自动释放所有权在不久的将来. 更多… | |
| unsigned int | getReferenceCount () const | 
| 返回Ref对象当前的引用计数. 更多… | |
| virtual | ~Ref () | 
| NA NA 更多… | |
  Public 成员函数 继承自 Clonable | |
| virtual | ~Clonable () | 
| NA NA 更多… | |
| CC_DEPRECATED_ATTRIBUTE Ref | copy () const | 
| 返回Ref对象的一份拷贝. 更多… | |
| ## 静态 Public 成员函数 | |
| static __Dictionary | create () | 
| 创建一个dictionary. 更多… | |
| static __Dictionary | createWithDictionary (__Dictionary srcDict) | 
| 根据现存的dictionary创建一个新的dictionary. 更多… | |
| static __Dictionary | createWithContentsOfFile (const char pFileName) | 
| 根据plist文件创建一个dictionary. 更多… | |
| static __Dictionary | createWithContentsOfFileThreadSafe (const char *pFileName) | 
| 根据plist文件创建一个dictionary. 更多… | |
| ## Public 属性 | |
| DictElement * | _elements | 
| dictionary中得所有元素. 更多… | |
| ## 额外继承的成员函数 | |
  Protected 成员函数 继承自 Ref | |
| Ref () | |
| 构造函数 更多… | |
  Protected 属性 继承自 Ref | |
| unsigned int | _referenceCount | 
| 引用计数 更多… | |
详细描述
Dictionary 就像 Obj-C 中的 NSDictionary .
- 注解
 - 只有对象的指针 或者它的子类 能往 Dictionary里面插入数据.
 
// 创建一个dictionary, 返回autorelease object.
Dictionary* pDict = Dictionary::create();
// 插入对象进Dictionary
String* pValue1 = String::create("100");
String* pValue2 = String::create("120");
Integer* pValue3 = Integer::create(200);
pDict->setObject(pValue1, "key1");
pDict->setObject(pValue2, "key2");
pDict->setObject(pValue3, "key3");
// 获取object的key
String pStr1 = static_cast<String>(pDict->objectForKey("key1"));
log("{ key1: %s }", pStr1->getCString());
Integer pInteger = static_cast<Integer>(pDict->objectForKey("key3"));
log("{ key3: %d }", pInteger->getValue());
构造及析构函数说明
| __Dictionary | ( | ) | 
Dictionary的构造函数.
NA NA
| ~__Dictionary | ( | ) | 
Dictionary的析构函数 NA NA.
成员函数说明
 
 
  |  virtual | 
| __Array* allKeys | ( | ) | 
返回所有元素的 key.
- 返回
 - 数组包含所有元素的key. 它也是autorelease类型. NA
 
| __Array allKeysForObject | ( | Ref | object | ) | 
获取根据指定对象条件下的所有key.
- 警告
 - 使用 '==' 比较两个对象
 
- 返回
 - 数组 包含指定条件下的所有key对应的对象. 它也是autorelease object. NA
 
 
 
  |  virtual | 
NA NA
实现了 Clonable.
| unsigned int count | ( | ) | 
获取Dictionary中元素个数.
- 返回
 - 元素个数. NA
 
 
 
  |  static | 
创建一个dictionary.
- 返回
 - 返回一个autorelease dictionary.
 
- 参见
 - createWithDictionary(Dictionary), [createWithContentsOfFile(const char)](../../d0/d1a/classcocos2d_1_1_dictionary.html#ab95c95638bd14908873312b78cd70497), createWithContentsOfFileThreadSafe(const char*). NA
 
 
 
  |  static | 
根据plist文件创建一个dictionary.
- 参数
 pFileNameplist文件的名字.
- 返回
 - 一个autorelease类型的dictionary.
 
- 参见
 - create(), createWithDictionary(Dictionary), [createWithContentsOfFileThreadSafe(const char)](../../d0/d1a/classcocos2d_1_1_dictionary.html#a9b09179c67f6919b779b9aa656274e33). NA
 
 
 
  |  static | 
根据plist文件创建一个dictionary.
- 注解
 - 返回值不是autorelease类型. 这能确保在新的线程中不适用autorelease pool. 因此, 你需要管理好返回对象的生命周期. 这意味着你不需要它时, CC_SAFE_RELEASE 需要被调用.
 
- 参数
 pFileNameplist 文件.
- 返回
 - 不是autorelease类型的dictionary. NA NA
 
 
 
  |  static | 
根据现存的dictionary创建一个新的dictionary.
- 参数
 srcDict现存的dictionary.
- 返回
 - 一个autorelease类型的dictionary.
 
- 参见
 - create(), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*). NA
 
| bool init | ( | ) | 
初始化dictionary.
如果初始化成功,返回true . NA NA
| Ref* objectForKey | ( | const std::string & | key | ) | 
根据这个特定的string key,获取所有的object.
- 注解
 - 这个 dictionary 需要使用string类型的key. 如果使用integer, 可能引发断言.
 
- 参数
 key用于搜索的string类型的key.
- 返回
 - 这个 object必须匹配 key. 你需要强制转换为你知道的那个类型.
 
// 假设这个元素是 String* pointers. 转换代码如下.
String pStr = static_cast<String>(pDict->objectForKey("key1"));
// Do something about pStr.
// 如果你不知道这个对象的类型, 最好使用 dynamic_cast
String pStr2 = dynamic_cast<String>(pDict->objectForKey("key1"));
if (pStr2 != NULL) {
// Do something about pStr2
}
| Ref* objectForKey | ( | intptr_t | key | ) | 
根据特殊的integer key获取object.
- 注解
 - 这个dictionary 需要使用integer作为key. 如果是加入string类型的key, 将会发生断言.
 
- 参数
 key用于搜索的 integer key.
- 返回
 - 这个object 匹配 key.
 
| Ref* randomObject | ( | ) | 
返回dictionary中随机的一个对象.
- 返回
 - The random object.
 
| void removeAllObjects | ( | ) | 
移除dictionary中所有对象.
- 参见
 - removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), removeObjectsForKeys(__Array*), removeObjectForElememt(DictElement*). NA
 
| void removeObjectForElememt | ( | DictElement * | pElement | ) | 
根据某个元素移除对应的对象
- 参数
 pElement这个element对应的对象将被移除.
- 参见
 - removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), removeObjectsForKeys(__Array*), removeAllObjects(). NA NA
 
| void removeObjectForKey | ( | const std::string & | key | ) | 
根据特定的string key移除对应的对象.
- 参数
 key用于搜索的string key.
- 参见
 - removeObjectForKey(intptr_t), removeObjectsForKeys(__Array*), removeObjectForElememt(DictElement*), removeAllObjects(). NA
 
| void removeObjectForKey | ( | intptr_t | key | ) | 
根据特定的integer key,移除对象的对象.
- 参数
 key用于搜索的integer key.
- 参见
 - removeObjectForKey(const std::string&), removeObjectsForKeys(__Array*), removeObjectForElememt(DictElement*), removeAllObjects(). NA
 
| void removeObjectsForKeys | ( | __Array * | pKey__Array | ) | 
根据array中得keys移除对应的所有对象.
- 参数
 pKeyArray包含这个keys的数组里的对象都会被移除.
- 参见
 - removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), removeObjectForElememt(DictElement*), removeAllObjects(). NA
 
| void setObject | ( | Ref * | pObject, | 
| const std::string & | key | ||
| ) | 
插入一个对象进dictionary, 匹配插入特定的string key.
- 注解
 - 当这个方法首次调用时, 这个key将被设置为string类型. 这之后你不能使用 setObject 设置integer key. 如果Dictionary包含了你传递的key, 匹配这个key的对象将被释放,从这个dictionary 里移除.然后新的对象将被插入。
 
- 参数
 pObject被插入的对象. key用于搜索的string key.
| void setObject | ( | Ref * | pObject, | 
| intptr_t | key | ||
| ) | 
插入一个对象进dictionary, 用特定的string key匹配它.
- 注解
 - 当这个方法首次被调用时, 这个key的类型将被设置为string类型. 这之后你不能setObject为integer类型. 如果dictionary中已经存在了这个key, 这个key所对应的对象将被释放和移除. 新的对象将会插入.
 
- 参数
 pObject被插入的对象. key用于搜索的string key.
| const __String* valueForKey | ( | const std::string & | key | ) | 
根据特定的string key,获取值.
- 注解
 - 小心使用这个函数由于它假设这个dictionary里面的对象是__String pointer.
 
- 参数
 key用于搜索的 string key
- 返回
 - 返回一个String实例. 如果没被找到或者这个string不存在,将返回空.
 
| const __String* valueForKey | ( | intptr_t | key | ) | 
根据特定的integer key获取值.
- 注解
 - 小心使用这个函数由于它假设这个dictionary里面的对象是__String pointer.
 
- 参数
 key用于搜索的 string key.
- 返回
 - 返回一个String实例. 如果没被找到或者这个string不存在,将返回空.
 
| bool writeToFile | ( | const char * | fullPath | ) | 
往plist文件中写入一个dictionary.
- 参数
 fullPathplist文件的全路径. 通过 getWritablePath()可以获取可写的路径
- 返回
 - true 表示创建成功, false 表示创建失败 NA NA
 
类成员变量说明
| DictElement* _elements | 
dictionary中得所有元素.
- 注解
 - 对于内部使用, 我们需要把这个成员变量声明为public,因为它在UT_HASH中使用.
 
该类的文档由以下文件生成:
- /Users/zeroyang/Documents/github/cocos2d-x/cocos/deprecated/CCDictionary.h
 
- cocos2d
 - __Dictionary
 - 生成于 2014年 五月 29日 星期四 09:41:43 , 为 cocos2d-x使用  
 1.8.6   
 Public 成员函数 继承自 