Skip to content
Snippets Groups Projects
Commit 27bc0a85 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

add optional attributes

parent ef2f8b43
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ namespace onelab{ ...@@ -47,7 +47,7 @@ namespace onelab{
// display the parameter in a GUI). Should allow richer encoding // display the parameter in a GUI). Should allow richer encoding
// (UTF? HTML?) // (UTF? HTML?)
std::string _shortHelp, _help; std::string _shortHelp, _help;
// client code(s) that use this parameter // clients (computing steps) that use this parameter
std::set<std::string> _clients; std::set<std::string> _clients;
// flag to check if the parameter has been changed since the last run // flag to check if the parameter has been changed since the last run
bool _changed; bool _changed;
...@@ -66,6 +66,10 @@ namespace onelab{ ...@@ -66,6 +66,10 @@ namespace onelab{
void setHelp(const std::string &help){ _help = help; } void setHelp(const std::string &help){ _help = help; }
void setChanged(bool changed){ _changed = changed; } void setChanged(bool changed){ _changed = changed; }
void setVisible(bool visible){ _visible = visible; } void setVisible(bool visible){ _visible = visible; }
void setAttribute(const std::string &key, const std::string &value)
{
_attributes[key] = value;
}
void setClients(std::set<std::string> &clients){ _clients = clients; } void setClients(std::set<std::string> &clients){ _clients = clients; }
void addClient(const std::string &client){ _clients.insert(client); } void addClient(const std::string &client){ _clients.insert(client); }
void addClients(std::set<std::string> &clients) void addClients(std::set<std::string> &clients)
...@@ -82,6 +86,12 @@ namespace onelab{ ...@@ -82,6 +86,12 @@ namespace onelab{
const std::string &getHelp() const { return _help; } const std::string &getHelp() const { return _help; }
bool getChanged() const { return _changed; } bool getChanged() const { return _changed; }
bool getVisible() const { return _visible; } bool getVisible() const { return _visible; }
std::string getAttribute(const std::string &key)
{
std::map<std::string, std::string>::iterator it = _attributes.find(key);
if(it != _attributes.end()) return it->second;
return "";
}
const std::set<std::string> &getClients() const { return _clients; } const std::set<std::string> &getClients() const { return _clients; }
static char charSep(){ return '|' /* '\0' */; } static char charSep(){ return '|' /* '\0' */; }
static double maxNumber(){ return 1e200; } static double maxNumber(){ return 1e200; }
...@@ -96,8 +106,13 @@ namespace onelab{ ...@@ -96,8 +106,13 @@ namespace onelab{
{ {
std::ostringstream sstream; std::ostringstream sstream;
sstream << getType() << charSep() << sanitize(getName()) << charSep() sstream << getType() << charSep() << sanitize(getName()) << charSep()
<< sanitize(getShortHelp()) << charSep() << sanitize(getHelp()) << sanitize(getShortHelp()) << charSep()
<< charSep() << getVisible() ? 1 : 0; << sanitize(getHelp()) << charSep()
<< (getVisible() ? 1 : 0) << charSep()
<< _attributes.size() << charSep();
for(std::map<std::string, std::string>::iterator it = _attributes.begin();
it != _attributes.end(); it++)
sstream << it->first << charSep() << it->second << charSep();
return sstream.str(); return sstream.str();
} }
virtual void fromChar(const std::string &msg){} virtual void fromChar(const std::string &msg){}
...@@ -167,7 +182,7 @@ namespace onelab{ ...@@ -167,7 +182,7 @@ namespace onelab{
std::string toChar() std::string toChar()
{ {
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << charSep() << _value << charSep() sstream << parameter::toChar() << _value << charSep()
<< _min << charSep() << _max << charSep() << _step << charSep() << _min << charSep() << _max << charSep() << _step << charSep()
<< _choices.size() << charSep(); << _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
...@@ -186,6 +201,11 @@ namespace onelab{ ...@@ -186,6 +201,11 @@ namespace onelab{
setShortHelp(getNextToken(msg, pos)); setShortHelp(getNextToken(msg, pos));
setHelp(getNextToken(msg, pos)); setHelp(getNextToken(msg, pos));
setVisible(atoi(getNextToken(msg, pos).c_str())); setVisible(atoi(getNextToken(msg, pos).c_str()));
int numAttributes = atoi(getNextToken(msg, pos).c_str());
for(int i = 0; i < numAttributes; i++){
std::string key(getNextToken(msg, pos));
setAttribute(key, getNextToken(msg, pos));
}
setValue(atof(getNextToken(msg, pos).c_str())); setValue(atof(getNextToken(msg, pos).c_str()));
setMin(atof(getNextToken(msg, pos).c_str())); setMin(atof(getNextToken(msg, pos).c_str()));
setMax(atof(getNextToken(msg, pos).c_str())); setMax(atof(getNextToken(msg, pos).c_str()));
...@@ -229,7 +249,7 @@ namespace onelab{ ...@@ -229,7 +249,7 @@ namespace onelab{
std::string toChar() std::string toChar()
{ {
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << charSep() << sanitize(_value) << charSep() sstream << parameter::toChar() << sanitize(_value) << charSep()
<< _choices.size() << charSep(); << _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
sstream << sanitize(_choices[i]) << charSep(); sstream << sanitize(_choices[i]) << charSep();
...@@ -247,6 +267,11 @@ namespace onelab{ ...@@ -247,6 +267,11 @@ namespace onelab{
setShortHelp(getNextToken(msg, pos)); setShortHelp(getNextToken(msg, pos));
setHelp(getNextToken(msg, pos)); setHelp(getNextToken(msg, pos));
setVisible(atoi(getNextToken(msg, pos).c_str())); setVisible(atoi(getNextToken(msg, pos).c_str()));
int numAttributes = atoi(getNextToken(msg, pos).c_str());
for(int i = 0; i < numAttributes; i++){
std::string key(getNextToken(msg, pos));
setAttribute(key, getNextToken(msg, pos));
}
setValue(getNextToken(msg, pos)); setValue(getNextToken(msg, pos));
_choices.resize(atoi(getNextToken(msg, pos).c_str())); _choices.resize(atoi(getNextToken(msg, pos).c_str()));
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
...@@ -278,7 +303,7 @@ namespace onelab{ ...@@ -278,7 +303,7 @@ namespace onelab{
std::string toChar() std::string toChar()
{ {
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << charSep() << _value << charSep() sstream << parameter::toChar() << _value << charSep()
<< _choices.size() << charSep(); << _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
sstream << _choices[i] << charSep(); sstream << _choices[i] << charSep();
...@@ -337,7 +362,7 @@ namespace onelab{ ...@@ -337,7 +362,7 @@ namespace onelab{
std::string toChar() std::string toChar()
{ {
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << charSep() << sanitize(_value) << charSep() sstream << parameter::toChar() << sanitize(_value) << charSep()
<< _pieceWiseValues.size() << charSep(); << _pieceWiseValues.size() << charSep();
for(std::map<std::string, std::string>::const_iterator it = for(std::map<std::string, std::string>::const_iterator it =
_pieceWiseValues.begin(); it != _pieceWiseValues.end(); it++) _pieceWiseValues.begin(); it != _pieceWiseValues.end(); it++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment