当前位置: 首页>>代码示例>>C++>>正文


C++ CCDictionary::init方法代码示例

本文整理汇总了C++中CCDictionary::init方法的典型用法代码示例。如果您正苦于以下问题:C++ CCDictionary::init方法的具体用法?C++ CCDictionary::init怎么用?C++ CCDictionary::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCDictionary的用法示例。


在下文中一共展示了CCDictionary::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: array_Value

static void array_Value(CCArray * aArray, const cocos2d::ValueVector & value)
{
    cocos2d::ValueVector::const_iterator beg = value.begin();
    cocos2d::ValueVector::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const Value & v = *beg;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * dict = new CCDictionary();
            dict->init();
            dictionary_Value(dict, v.asValueMap());
            aArray->addObject(dict);
            dict->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * arr = new CCArray();
            arr->init();
            array_Value(arr, v.asValueVector());
            aArray->addObject(arr);
            arr->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aArray->addObject(str);
            str->release();
        }
    }
}
开发者ID:JackKa325,项目名称:cocos2d-x-tools,代码行数:35,代码来源:YHDataManagerImp.cpp

示例2: dictionary_Value

static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value)
{
    cocos2d::ValueMap::const_iterator beg = value.begin();
    cocos2d::ValueMap::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const std::string & key = (*beg).first;
        const cocos2d::Value & v = (*beg).second;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * d = new CCDictionary();
            d->init();
            dictionary_Value(d, v.asValueMap());
            aDict->setObject(d, key);
            d->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * a = new CCArray();
            a->init();
            array_Value(a, v.asValueVector());
            aDict->setObject(a, key);
            a->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aDict->setObject(str, key);
            str->release();
        }
    }
}
开发者ID:JackKa325,项目名称:cocos2d-x-tools,代码行数:36,代码来源:YHDataManagerImp.cpp

示例3: if

CCObject * YHDataManagerImp::loadFile(const std::string & fullpath)
{
    string suffix = pathExtensionWithString(fullpath);
    asciiToLower(suffix);
    
    // 装载对应的对象
    CCObject * obj = NULL;
    if (suffix.compare("plist-array") == 0)
    {
        ValueVector vv = CCFileUtils::getInstance()->getValueVectorFromFile(fullpath);
        CCArray * arr = new CCArray();
        arr->initWithCapacity((ssize_t)vv.size());
        array_Value(arr, vv);
        obj = arr;
    }
    else if (suffix.compare("plist-dictionary") == 0)
    {
        ValueMap vm = FileUtils::getInstance()->getValueMapFromFile(fullpath);
        CCDictionary * dic = new CCDictionary();
        dic->init();
        dictionary_Value(dic, vm);
        obj = dic;
    }
    else if (suffix.compare("png") == 0 || suffix.compare("jpg") == 0 || suffix.compare("jpeg") == 0
             || suffix.compare("tif") == 0 || suffix.compare("tiff") == 0 || suffix.compare("webp") == 0)
    {
        Image * image = new Image();
        image->initWithImageFile(fullpath);
        obj = image;
    }
    else if (suffix.compare("plist") == 0)
    {
		ValueMap vm = CCFileUtils::getInstance()->getValueMapFromFile(fullpath);
		if (vm.size())
		{
			CCDictionary * dic = new CCDictionary();
			dic->init();
			dictionary_Value(dic, vm);
			obj = dic;
		}
		else
		{
			ValueVector vv = CCFileUtils::getInstance()->getValueVectorFromFile(fullpath);
			if (vv.size())
			{
				CCArray * arr = new CCArray();
				arr->initWithCapacity((ssize_t)vv.size());
				array_Value(arr, vv);
				obj = arr;
			}
			else
			{
				CCASSERT(false, "没有找到适合的解析文件方式。");
			}
		}
    }
    else
    {
        std::string data = FileUtils::getInstance()->getStringFromFile(fullpath);
        YHByteArray * bytes = new YHByteArray();
        bytes->init(data.length() + 1);
        bytes->writeBytes((char *)data.c_str(), data.length() + 1);
        obj = bytes;
    }
    
    return obj;
}
开发者ID:KAndQ,项目名称:cocos2dx-utils,代码行数:67,代码来源:YHDataManagerImp.cpp


注:本文中的CCDictionary::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。