13 #include "param_codec.hh" 14 #include "param_json.hh" 66 scarab::param_translator translator;
67 scarab::param_ptr_t configFromFile = translator.read_file( configFilePath.native() );
68 if( configFromFile == NULL )
70 throw KTException() <<
"[KTApplication] error parsing config file";
72 if( ! configFromFile->is_node() )
74 throw KTException() <<
"[KTApplication] configuration file must consist of an object/node";
82 scarab::param_input_json inputJSON;
83 scarab::param_ptr_t configFromJSON = inputJSON.read_string( clJSON );
84 if( ! configFromJSON->is_node() )
86 throw KTException() <<
"[KTApplication] command line json must be an object";
92 if (clConfigOverride != NULL)
124 fCLHandler->
AddOption(
"Config File Options",
"Configuration flag: " + rootName, rootName,
false);
126 else if (param.is_value())
128 fCLHandler->
AddOption<
string >(
"Config File Options",
"Configuration value: " + rootName, rootName,
false);
130 else if (param.is_array())
132 string nextRootName(rootName);
133 if (! rootName.empty() && rootName.back() !=
'.') nextRootName +=
".";
135 const scarab::param_array& paramArray = param.as_array();
136 unsigned arraySize = paramArray.size();
137 for (
unsigned iParam = 0; iParam < arraySize; ++iParam)
142 else if (param.is_node())
144 string nextRootName(rootName);
145 if (! rootName.empty()) nextRootName +=
".";
147 const scarab::param_node& paramNode = param.as_node();
148 for (scarab::param_node::const_iterator nodeIt = paramNode.begin(); nodeIt != paramNode.end(); ++nodeIt)
bool GetPrintVersionMessage() const
const scarab::param_node * GetConfigOverride() const
bool AddOption(const std::string &aTitle, const std::string &aHelpMsg, const std::string &aLongOpt, char aShortOpt, bool aWarnOnDuplicate=true)
Simple option adding function, with short option (flag only; no values allowed)
bool ProcessCommandLine(int argC, char **argV)
const std::string & GetConfigFilename() const
Return the file name provided by the user on the command line for the config file.
bool GetPrintHelpMessageAfterConfigFlag() const
const std::string & GetCommandLineJSON() const
Return the string of json provided by the user on the command line.
Abstract base class for event loops.
virtual void PrintVersionMessage()
void RemoveEventLoop(KTEventLoop *loop)
Adds loop to the set of event loops overseen by KTApplication. Does NOT assume ownership of an event ...
Parses and stores command-line options.
void Merge(const scarab::param_node &aNode)
virtual bool Configure(const scarab::param_node &node)
Should perform parameter store and command-line configurations.
virtual void PrintHelpMessage()
bool DelayedCommandLineProcessing()
Parses the remaining command line options (those that weren't parsed during the InitialCommandLinePro...
KTLOGGER(applog, "KTApplication")
std::string fConfigFilename
KTCommandLineHandler * fCLHandler
Removes loop from the set of event loops overseen by KTApplication. Does not stop the loop...
bool GetPrintHelpMessageFlag() const
std::set< KTEventLoop *> fEventLoops
bool FinalizeNewOptionGroups()
Adds the groups of options to the set of usable options groups (note: this must be called to make the...
KTConfigurator * fConfigurator
Contains the logger class and macros, based on Kasper's KLogger class.
void AddConfigOptionsToCLHandler(const scarab::param ¶m, const std::string &rootName)
void AddEventLoop(KTEventLoop *loop)
scarab::param_node & Config()