⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dotconf.cpp

📁 访问unix风格的配置文件
💻 CPP
字号:
/*  * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "ace/Synch_Traits.h"#include "ace/Recursive_Thread_Mutex.h"#include "ace/Singleton.h"#include "dotconfpp/dotconfpp.h"#include "dotconf.h"DOTConf* DOTConf::dot_conf_ = 0;int DOTConf::delete_dot_conf_ = 0;DOTConf::DOTConf() : mConf(0){}DOTConf::~DOTConf(){    if (mConf)        delete mConf;}bool DOTConf::SetSource(const char *file, bool ignorecase){    mConf = new DOTCONFDocument(ignorecase ?        DOTCONFDocument::CASEINSENSETIVE :    DOTCONFDocument::CASESENSETIVE);    if (mConf->setContent(file) == -1)    {        delete mConf;        mConf = 0;        return false;    }    return true;}bool DOTConf::GetString(const char* name, std::string *value){    if(!mConf)        return false;    DOTCONFDocumentNode const *node = mConf->findNode(name);    if(!node || !node->getValue())        return false;    *value = node->getValue();    return true;}std::string DOTConf::GetStringDefault(const char* name, const char* def){    if(!mConf)        return std::string(def);    DOTCONFDocumentNode const *node = mConf->findNode(name);    if(!node || !node->getValue())        return std::string(def);    return std::string(node->getValue());}bool DOTConf::GetBool(const char* name, bool *value){    if(!mConf)        return false;    DOTCONFDocumentNode const *node = mConf->findNode(name);    if(!node || !node->getValue())        return false;    const char* str = node->getValue();    if(strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||        strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||        strcmp(str, "1") == 0)    {        *value = true;    }    else        *value = false;    return true;}bool DOTConf::GetBoolDefault(const char* name, const bool def){    bool val;    return GetBool(name, &val) ? val : def;}bool DOTConf::GetInt(const char* name, int *value){    if(!mConf)        return false;    DOTCONFDocumentNode const *node = mConf->findNode(name);    if(!node || !node->getValue())        return false;    *value = atoi(node->getValue());    return true;}bool DOTConf::GetFloat(const char* name, float *value){    if(!mConf)        return false;    DOTCONFDocumentNode const *node = mConf->findNode(name);    if(!node || !node->getValue())        return false;    *value = atof(node->getValue());    return true;}int DOTConf::GetIntDefault(const char* name, const int def){    int val;    return GetInt(name, &val) ? val : def;}float DOTConf::GetFloatDefault(const char* name, const float def){    float val;    return (GetFloat(name, &val) ? val : def);}DOTConf * DOTConf::instance(void){	if (DOTConf::dot_conf_ == 0)	{		ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, 								*ACE_Static_Object_Lock::instance(), 0));		if (DOTConf::dot_conf_ == 0)		{			ACE_NEW_RETURN (DOTConf::dot_conf_, 							DOTConf,							0);			DOTConf::delete_dot_conf_ = 1;		}	}		return DOTConf::dot_conf_;}DOTConf * DOTConf::instance(DOTConf *conf){	ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon,							*ACE_Static_Object_Lock::instance(), 0));	DOTConf *old_conf = DOTConf::dot_conf_;	DOTConf::delete_dot_conf_ = 0;		DOTConf::dot_conf_ = conf;	return old_conf;}void DOTConf::close_singleton(void){	ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon,					*ACE_Static_Object_Lock::instance()));	if (DOTConf::delete_dot_conf_)	{		delete DOTConf::dot_conf_;		DOTConf::dot_conf_ = 0;		DOTConf::delete_dot_conf_ = 0;	}}

⌨️ 快捷键说明

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