Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / misc / variable.cpp
blob16953f990e08b00f864009780ab945ed9db7466f
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdmisc.h"
19 #include "nel/misc/variable.h"
21 using namespace std;
22 using namespace NLMISC;
24 #ifdef DEBUG_NEW
25 #define new DEBUG_NEW
26 #endif
28 namespace NLMISC {
31 void cbVarChanged (CConfigFile::CVar &cvar)
33 CCommandRegistry &cr = CCommandRegistry::getInstance();
34 for (CCommandRegistry::TCommand::iterator comm = cr._Commands.begin(); comm != cr._Commands.end(); comm++)
36 if (comm->second->Type == ICommand::Variable && comm->second->getName() == cvar.Name)
38 IVariable *var = static_cast<IVariable*>(comm->second);
39 string val = cvar.asString();
40 nlinfo ("VAR: Setting variable '%s' with value '%s' from config file", cvar.Name.c_str(), val.c_str());
41 var->fromString(val, true);
47 void IVariable::init (NLMISC::CConfigFile &configFile)
49 CCommandRegistry::getInstance().initVariables(configFile);
52 void CCommandRegistry::initVariables(NLMISC::CConfigFile &configFile)
54 for (TCommand::iterator comm = _Commands.begin(); comm != _Commands.end(); comm++)
56 if (comm->second->Type == ICommand::Variable)
58 IVariable *var = static_cast<IVariable *>(comm->second);
59 if (var->_UseConfigFile)
61 configFile.setCallback(var->_CommandName, cbVarChanged);
62 CConfigFile::CVar *cvar = configFile.getVarPtr(var->_CommandName);
63 if (cvar != 0)
65 string val = cvar->asString();
66 //nldebug("VAR: Setting variable '%s' with value '%s' from config file '%s'", var->_CommandName.c_str(), val.c_str(), configFile.getFilename().c_str());
67 var->fromString(val, true);
69 else
71 //nldebug("VAR: No variable '%s' in config file '%s'", var->_CommandName.c_str(), configFile.getFilename().c_str());
78 } // NLMISC