confighandler.cpp

来自「这是整套横扫千军3D版游戏的源码」· C++ 代码 · 共 82 行

CPP
82
字号
/**
 * @file ConfigHandler.cpp
 * @brief config implementation
 * @author Christopher Han <xiphux@gmail.com>
 * 
 * Implementation of config structure class
 * Copyright (C) 2005.  Licensed under the terms of the
 * GNU GPL, v2 or later.
 */
#include "StdAfx.h"
#include "ConfigHandler.h"
#ifdef _WIN32
#include "Win/RegHandler.h"
#elif defined(__APPLE__)
extern "C" void PreInitMac();
#include "Mac/UserDefsHandler.h"
#else
#include "Linux/DotfileHandler.h"
#endif
#include <sstream>


/**
 * @brief instance
 *
 * Default instantiation of ConfigHandler instance
 * is NULL.
 */
ConfigHandler* ConfigHandler::instance=0;

/**
 * Returns reference to the current platform's config class.
 * If none exists, create one.
 */
ConfigHandler& ConfigHandler::GetInstance()
{
	if (!instance) {
#ifdef _WIN32
		instance = SAFE_NEW RegHandler("Software\\SJ\\spring");
#elif defined(__APPLE__)
		PreInitMac();
		instance = SAFE_NEW UserDefsHandler(); // Config path is based on bundle id
#else
		instance = SAFE_NEW DotfileHandler(DOTCONFIGPATH);
#endif
	}
	return *instance;
}

/**
 * Destroys existing ConfigHandler instance.
 */
void ConfigHandler::Deallocate()
{
	if (instance)
		delete instance;
	instance = 0;
}

ConfigHandler::~ConfigHandler()
{
}

float ConfigHandler::GetFloat(const std::string& name, const float def)
{
	std::ostringstream buf1;
	buf1 << def;
	
	std::istringstream buffer(GetString(name, buf1.str()));
	float val;
	buffer >> val;
	return val;
}

void ConfigHandler::SetFloat(const std::string& name, float value)
{
	std::ostringstream buffer;
	buffer << value;

	SetString(name, buffer.str());
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?