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


C++ ConfigFile::Set方法代码示例

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


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

示例1: Load

bool Config::Load(){

  serverPort = 666;
  isPublic = true;
  memset(serverName,0,SERVERNAME_MAX); sprintf(serverName,"G Server");
  enableLogging = true;
  ignoreUnknownPackets = false;
  spriteMaxX = 50;
  spriteMaxY = 50;
  usernameMax = 20;

  ConfigFile file; file.Construct();

  if(file.Load(CONFIG_FILE)){
    file.Get("serverPort",&serverPort);
    file.Get("isPublic",&isPublic);
    file.Get("serverName",serverName,SERVERNAME_MAX);
    file.Get("enableLogging",&enableLogging);
    file.Get("ignoreUnknownPackets",&ignoreUnknownPackets);
    file.Get("spriteMaxX",&spriteMaxX);
    file.Get("spriteMaxY",&spriteMaxY);
    file.Get("usernameMax",&usernameMax);
  }else{
    fprintf(stderr,"WARNING: %s not found. Generating with default settings.\n",CONFIG_FILE);
  }

  file.Clear();
  file.Set("serverPort",serverPort);
  file.Set("isPublic",isPublic);
  file.Set("serverName",serverName);
  file.Set("enableLogging",enableLogging);
  file.Set("ignoreUnknownPackets",ignoreUnknownPackets);
  file.Set("spriteMaxX",spriteMaxX);
  file.Set("spriteMaxY",spriteMaxY);
  file.Set("usernameMax",usernameMax);

  if(file.Save(CONFIG_FILE)){
    file.Destruct();
    return true;
  }else{
    fprintf(stderr,"ERROR: Unable to save %s.\n",CONFIG_FILE);
    file.Destruct();
    return false;
  }

}
开发者ID:stal888,项目名称:gnet,代码行数:46,代码来源:global.cpp

示例2: Compile


//.........这里部分代码省略.........
				for (LinkedList<AtlasFrame*>::Iterator animiter = frames.Begin(); animiter != frames.End(); animiter++)
				{
					AtlasFrame* anim = *animiter;

					if (anim->Name.size() > split_left.size() + split_right.size())
					{
						if (anim->Name.substr(0, split_left.size()) == split_left &&
							anim->Name.substr((anim->Name.size() - split_right.size()), split_right.size()) == split_right)
						{
							AtlasFrame* frame = atlas->Get_Frame(anim->Name.c_str());
							DBG_ASSERT(frame != NULL, "Invalid frame name '%s' in animation '%s'.", anim->Name, name);
							out_frames.push_back(frame);
						}
					}
				}
			}
			else
			{
				DBG_ASSERT_STR(false, "Unknown or invalid frame type '%s'", frame_type);
			}
		}

		// Add the animation.
		atlas->Add_Animation(name, speed, anim_mode, out_frames);
	}

	// Save compiled file.
	atlas->Unlock_Textures();

	// Configuration settings.
	ConfigFile config;
	
	// Store configuration settings.
	config.Set<const char*>("settings/texture-size",		m_config_file->Get<const char*>("settings/texture-size"));
	config.Set<const char*>("settings/max-textures",		m_config_file->Get<const char*>("settings/max-textures"));

	// Save pngs.
	int texture_count = 0;
	AtlasTexture** textures = atlas->Get_Textures(texture_count);

	for (int i = 0; i < texture_count; i++)
	{
		AtlasTexture* texture = textures[i];		

		std::string output_path = (m_output_path + "." + StringHelper::To_String(i) + ".png");

		// Save texture file.
		TextureFactory::Save(output_path.c_str(), texture->Texture, TextureFlags::None);

		// Store texture spec in xml.
		ConfigFileNode node = config.New_Node("textures/texture");
		config.Set(NULL, output_path.c_str(), node, false);
	}

	// Save frame configuration.
	config.New_Node("frames");
	HashTable<AtlasFrame*, unsigned int>& frames = atlas->Get_Frames();
	for (HashTable<AtlasFrame*, unsigned int>::Iterator iter = frames.Begin(); iter != frames.End(); iter++)
	{
		AtlasFrame* frame = iter.Get_Value();
		
		// Store character spec in xml.
		ConfigFileNode node = config.New_Node("frames/frame");
		config.Set("name",			frame->Name.c_str(),				node, true);
		config.Set("namehash",		frame->NameHash,					node, true);
		config.Set("texture",		frame->TextureIndex,				node, true);
开发者ID:HampsterEater,项目名称:VoxelEngine,代码行数:67,代码来源:AtlasResourceCompiler.cpp

示例3: SaveSettingsMap

    void ConfigManager::SaveSettingsMap(Urho3D::String section, SettingsMap& map, ConfigFile& configFile)
    {
        // Save out parameters
        for (auto itr = map.Begin(); itr != map.End(); itr++)
        {
            // Skip over sub-sections
            if (itr->second_.GetType() == Urho3D::VAR_VOIDPTR)
            {
                continue;
            }

            auto value = itr->first_;

            // Set parameter
            if (itr->second_.GetType() == Urho3D::VAR_STRING)
                configFile.Set(section, value, itr->second_.GetString());

            if (itr->second_.GetType() == Urho3D::VAR_INT)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetInt()));

            if (itr->second_.GetType() == Urho3D::VAR_BOOL)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetBool()));

            if (itr->second_.GetType() == Urho3D::VAR_FLOAT)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetFloat()));

            if (itr->second_.GetType() == Urho3D::VAR_VECTOR2)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetVector2()));

            if (itr->second_.GetType() == Urho3D::VAR_VECTOR3)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetVector3()));

            if (itr->second_.GetType() == Urho3D::VAR_VECTOR4)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetVector4()));

            if (itr->second_.GetType() == Urho3D::VAR_QUATERNION)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetQuaternion()));

            if (itr->second_.GetType() == Urho3D::VAR_COLOR)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetColor()));

            if (itr->second_.GetType() == Urho3D::VAR_INTRECT)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetIntRect()));

            if (itr->second_.GetType() == Urho3D::VAR_INTVECTOR2)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetIntVector2()));

            if (itr->second_.GetType() == Urho3D::VAR_MATRIX3)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetMatrix3()));

            if (itr->second_.GetType() == Urho3D::VAR_MATRIX3X4)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetMatrix3x4()));

            if (itr->second_.GetType() == Urho3D::VAR_MATRIX4)
                configFile.Set(section, value, Urho3D::String(itr->second_.GetMatrix4()));
        }

        // Save out sub-sections
        for (auto itr = map.Begin(); itr != map.End(); itr++)
        {
            // Skip over parameter
            if (itr->second_.GetType() != Urho3D::VAR_VOIDPTR)
            {
                continue;
            }

            Urho3D::String path = section;
            path.Append(itr->first_);

            auto fsdf = map[section];
            auto value = static_cast<SettingsMap*>(itr->second_.GetVoidPtr());

            if (value)
            {
                // Save sub-section
                SaveSettingsMap(path, *value, configFile);
            }
        }
    }
开发者ID:carnalis,项目名称:urho_map,代码行数:79,代码来源:ConfigManager.cpp


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