23#include <unordered_map>
33 jevois::
Component(instanceID), itsCommandLineArgs((char const **)(argv), (char const **)(argv+argc)),
40 itsCommandLineArgs = std::vector<std::string>((
char const **)(argv), (
char const **)(argv+argc));
51 if (itsGotArgs ==
false)
52 LERROR(
"No command-line arguments given; did you forget to call jevois::Manager::setArgs()?");
54 if (itsCommandLineArgs.size() > 0) itsRemainingArgs = parseCommandLine(itsCommandLineArgs);
62 if (help::get()) { printHelpMessage();
LINFO(
"JeVois: exit after help message"); exit(0); }
69#if !defined(JEVOIS_TRACE_ENABLE) || !defined(JEVOIS_LDEBUG_ENABLE)
70 tracelevel::freeze(
true);
78 constructHelpMessage(std::cout);
84 std::unordered_map<std::string,
85 std::unordered_map<std::string,
86 std::vector<std::pair<std::string,
90 this->populateHelpMessage(
"", helplist,
false);
95 boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
96 for (std::shared_ptr<jevois::Component> c : itsSubComponents) c->populateHelpMessage(
"", helplist);
100 if (helplist.empty()) { out <<
"NO PARAMETERS.";
return; }
102 out <<
"PARAMETERS:" << std::endl << std::endl;
104 for (
auto & c : helplist)
107 out << c.first << std::endl;
110 for (
auto const & n : c.second)
112 out << n.first << std::endl;
116 out <<
" Exported By: ";
117 for (
auto const & cp : n.second)
120 if (cp.second.empty() ==
false) out <<
" value=[" << cp.second <<
']';
121 if (cp != *(n.second.end()-1)) out <<
", ";
133std::vector<std::string>
const jevois::Manager::parseCommandLine(std::vector<std::string>
const & commandLineArgs)
136 std::vector<std::string> remainingArgs;
137 remainingArgs.push_back(commandLineArgs[0]);
140 std::vector<std::string>::const_iterator argIt;
141 for (argIt = commandLineArgs.begin() + 1; argIt != commandLineArgs.end(); ++argIt)
144 if (argIt->length() < 2 || (*argIt)[0] !=
'-' || (*argIt)[1] !=
'-') { remainingArgs.push_back(*argIt);
continue; }
147 if (*argIt ==
"--")
break;
150 size_t const equalsPos = argIt->find_first_of(
'=');
151 if (equalsPos < 3)
LFATAL(
"Cannot parse command-line argument with no name [" << *argIt <<
']');
153 std::string
const parameterName = argIt->substr(2, equalsPos - 2);
154 std::string
const parameterValue = (equalsPos == std::string::npos) ?
"true" : argIt->substr(equalsPos + 1);
158 setParamString(parameterName, parameterValue);
162 while (argIt != commandLineArgs.end()) { remainingArgs.push_back(*argIt); ++argIt; }
164 return remainingArgs;
169{
return itsRemainingArgs; }
176 boost::upgrade_lock<boost::shared_mutex> uplck(itsSubMtx);
178 for (
auto itr = itsSubComponents.begin(); itr != itsSubComponents.end(); ++itr)
179 if ((*itr)->instanceName() == instance)
181 doRemoveSubComponent(itr, uplck,
"Component");
185 if (warnIfNotFound)
LERROR(
"Component [" << instance <<
"] not found. Ignored.");
197#ifdef JEVOIS_LDEBUG_ENABLE
206#if !defined(JEVOIS_TRACE_ENABLE) || !defined(JEVOIS_LDEBUG_ENABLE)
208 LERROR(
"Debug trace has been disabled at compile-time, re-compile with -DJEVOIS_LDEBUG_ENABLE=ON and "
209 "-DJEVOIS_TRACE_ENABLE=ON to see trace info");
A component of a model hierarchy.
void setCommandLineArgs(int argc, char const *argv[])
Set the command-line arguments, call this before start() if args were not passed at construction.
void removeComponent(std::shared_ptr< Comp > &component)
Remove a top-level Component from the Manager, by shared_ptr.
void onParamChange(manager::loglevel const ¶m, manager::LogLevel const &newval) override
Parameter callback.
void postInit() override
Checks for the –help flag.
virtual ~Manager()
Destructor.
void constructHelpMessage(std::ostream &out) const
Constructs a help message from all parameters in the model, and outputs it to 'out'.
std::vector< std::string > const & remainingArgs() const
Get the remaining arguments that were not parsed by the command line.
void printHelpMessage() const
Constructs a help message and tries to send it to /usr/bin/less.
void preInit() override
Calls parseCommandLine()
int logLevel
Current log level.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
int traceLevel
Current trace level.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Main namespace for all JeVois classes and functions.