Commit 6ea516ce authored by kraus's avatar kraus
Browse files

adding functionality to CmdArguments

parent e55a1dec
......@@ -21,3 +21,25 @@ void CmdArguments::split(std::string &name,
boost::trim(name);
boost::trim(value);
}
char** CmdArguments::getArguments() const {
const unsigned int size = arguments_.size();
char** args = new char*[2 * size];
unsigned int i = 0;
auto it = arguments_.cbegin();
const auto end = arguments_.cend();
for (; it != end; ++ it) {
const std::string &key = it->first;
char* argname = new char[key.length() + 1];
strcpy(argname, key.c_str());
args[i ++] = argname;
const std::string &value = it->second;
char* argvalue = new char[value.length() + 1];
strcpy(argvalue, value.c_str());
args[i ++] = argvalue;
}
return args;
}
\ No newline at end of file
......@@ -31,6 +31,9 @@ public:
addArguments(argc, argv);
}
CmdArguments()
{}
~CmdArguments()
{}
......@@ -84,6 +87,36 @@ public:
return value;
}
template <class T>
void addArgument(const std::string &name, const T &value) {
std::ostringstream oss;
oss << value;
if (arguments_.find(name) != arguments_.end()) {
throw OptPilotException("CmdArguments::addArgument",
"Argument '" + name + "' exists");
}
arguments_.insert(std::make_pair(name, oss.str()));
}
template <class T>
void replaceArgument(const std::string &name, const T &value) {
std::ostringstream oss;
oss << value;
if (arguments_.find(name) == arguments_.end()) {
arguments_.insert(std::make_pair(name, oss.str()));
return;
}
arguments_.at(name) = oss.str();
}
char** getArguments() const;
unsigned int getNumArguments() const {
return arguments_.size();
}
//template<>
//size_t getArg<size_t>(const std::string name, bool isFatal = false) {
//return getArg<size_t>(name, 0, isFatal);
......@@ -135,4 +168,4 @@ private:
typedef boost::shared_ptr<CmdArguments> CmdArguments_t;
#endif
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment