Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

OptionAgent Class Reference

Inheritance diagram for OptionAgent:

Inheritance graph
[legend]
Collaboration diagram for OptionAgent:

Collaboration graph
[legend]

Detailed Description

Game options.

Definition at line 16 of file OptionAgent.h.

Public Member Functions

void parseCmdOpt (int argc, char *argv[], const OptionParams &params)
 Parse command line options.
void setParam (const std::string &name, const std::string &value)
 Set param.
void setParam (const std::string &name, long value)
 Store this integer value like string param.
void setPersistent (const std::string &name, const std::string &value)
 Set param also on disk.
void setPersistent (const std::string &name, long value)
void setDefault (const std::string &name, const std::string &value)
 Set value when it is empty.
void setDefault (const std::string &name, int value)
std::string getParam (const std::string &name, const std::string &implicit="") const
 Return value.
int getAsInt (const std::string &name, int implicit=0) const
 Returns number value.
bool getAsBool (const std::string &name, bool implicit=false) const
 Returns boolean value.
void addWatcher (const std::string &name, BaseMsg *msg)
void removeWatchers (const std::string &listenerName)
void receiveString (const StringMsg *msg)
 Handle incoming message.

Protected Member Functions

virtual void own_init ()
 Set user and sytem dir and process "script/options.lua" - this will set user and system paths and process "script/init.lua".
virtual void own_shutdown ()
 Save user config.


Member Function Documentation

void OptionAgent::addWatcher const std::string &  name,
BaseMsg msg
 

Definition at line 336 of file OptionAgent.cpp.

00337 {
00338     m_environ->addWatcher(name, msg);
00339 }

bool OptionAgent::getAsBool const std::string &  name,
bool  implicit = false
const
 

Returns boolean value.

Implicit value is false.

Parameters:
name param name
implicit default value = false
Returns:
stored boolean value or implicit value

Definition at line 279 of file OptionAgent.cpp.

00281 {
00282     return m_environ->getAsBool(name, implicit);
00283 }

int OptionAgent::getAsInt const std::string &  name,
int  implicit = 0
const
 

Returns number value.

Implicit value is zero.

Parameters:
name param name
implicit default value = 0
Returns:
number or implicit

Definition at line 264 of file OptionAgent.cpp.

00266 {
00267     return m_environ->getAsInt(name, implicit);
00268 }

std::string OptionAgent::getParam const std::string &  name,
const std::string &  implicit = ""
const
 

Return value.

Implicit value is "".

Parameters:
name param name
implicit default value = ""
Returns:
value or implicit value

Definition at line 249 of file OptionAgent.cpp.

00251 {
00252     return m_environ->getParam(name, implicit);
00253 }

void OptionAgent::own_init  )  [protected, virtual]
 

Set user and sytem dir and process "script/options.lua" - this will set user and system paths and process "script/init.lua".

Reimplemented from BaseAgent.

Definition at line 51 of file OptionAgent.cpp.

00052 {
00053     m_environ = new Environ();
00054     prepareVersion();
00055     prepareDataPaths();
00056     prepareLang();
00057 }

void OptionAgent::own_shutdown  )  [protected, virtual]
 

Save user config.

Delete left messages.

Reimplemented from BaseAgent.

Definition at line 64 of file OptionAgent.cpp.

00065 {
00066     delete m_environ;
00067 }

void OptionAgent::parseCmdOpt int  argc,
char *  argv[],
const OptionParams params
 

Parse command line options.

Format: $0 [name=value ...]

Exceptions:
LogicException when format is wrong

Definition at line 136 of file OptionAgent.cpp.

00137 {
00138     if (argc >= 1) {
00139         setParam("program", argv[0]);
00140     }
00141 
00142     for (int i = 1; i < argc; ++i) {
00143         if (argv[i][0] == '-') {
00144             parseDashOpt(argv[i], params);
00145         }
00146         else {
00147             parseParamOpt(argv[i], params);
00148         }
00149     }
00150 }

void OptionAgent::receiveString const StringMsg msg  )  [virtual]
 

Handle incoming message.

Messages:

  • param_changed(systemdir) ... reread system options
  • param_changed(userdir) ... reread user options

Exceptions:
UnknownMsgException 

Reimplemented from BaseListener.

Definition at line 379 of file OptionAgent.cpp.

00380 {
00381     if (msg->equalsName("param_changed")) {
00382         std::string param = msg->getValue();
00383         if ("systemdir" == param) {
00384             readSystemConfig();
00385         }
00386         else if ("userdir" == param) {
00387             readUserConfig();
00388         }
00389         else {
00390             throw UnknownMsgException(msg);
00391         }
00392     }
00393     else {
00394         throw UnknownMsgException(msg);
00395     }
00396 }

void OptionAgent::removeWatchers const std::string &  listenerName  ) 
 

Definition at line 342 of file OptionAgent.cpp.

00343 {
00344     m_environ->removeWatchers(listenerName);
00345 }

void OptionAgent::setDefault const std::string &  name,
int  value
 

Definition at line 330 of file OptionAgent.cpp.

00331 {
00332     m_environ->setParam(name, m_environ->getAsInt(name, value));
00333 }

void OptionAgent::setDefault const std::string &  name,
const std::string &  value
 

Set value when it is empty.

Definition at line 324 of file OptionAgent.cpp.

00325 {
00326     m_environ->setParam(name, m_environ->getParam(name, value));
00327 }

void OptionAgent::setParam const std::string &  name,
long  value
 

Store this integer value like string param.

Definition at line 235 of file OptionAgent.cpp.

00236 {
00237     m_environ->setParam(name, value);
00238 }

void OptionAgent::setParam const std::string &  name,
const std::string &  value
 

Set param.

Notice watchers. When watcher is not available, it will be removed.

Parameters:
name param name
value param value

Definition at line 226 of file OptionAgent.cpp.

00227 {
00228     m_environ->setParam(name, value);
00229 }

void OptionAgent::setPersistent const std::string &  name,
long  value
 

Definition at line 315 of file OptionAgent.cpp.

00316 {
00317     setPersistent(name, StringTool::toString(value));
00318 }

void OptionAgent::setPersistent const std::string &  name,
const std::string &  value
 

Set param also on disk.

Preserve all current params in options file.

Definition at line 290 of file OptionAgent.cpp.

00291 {
00292     //NOTE: path must be created before change of environ
00293     Path config = Path::dataWritePath(CONFIG_FILE);
00294 
00295     Environ *swap_env = m_environ;
00296     m_environ = new Environ();
00297 
00298     try {
00299         if (config.exists()) {
00300             ScriptAgent::agent()->doFile(config);
00301         }
00302     }
00303     catch (ScriptException &e) {
00304         LOG_WARNING(e.info());
00305     }
00306     setParam(name, value);
00307     m_environ->store(config);
00308 
00309     delete m_environ;
00310     m_environ = swap_env;
00311     setParam(name, value);
00312 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:56:06 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2