50 BaseClass::msgOut(
const int& msgCode_h,
const string& msg_h,
const bool& refreshGUI_h)
const {
52 msgOut2(msgCode_h, msg_h, refreshGUI_h);
66 msgOut2(msgCode_h, i2s(msg_h), refreshGUI_h);
78 BaseClass::msgOut(
const int& msgCode_h,
const double& msg_h,
const bool& refreshGUI_h)
const {
79 msgOut2(msgCode_h, d2s(msg_h), refreshGUI_h);
101 prefix=
"**WARNING: ";
107 prefix=
"****CRITICAL ERROR: ";
110 cerr<<
"I got an unknow error code: "<<msgCode_h<<
" ("<<msg_h<<
")"<<endl;
114 string message = prefix+msg_h;
115 if (MTHREAD && MTHREAD->usingGUI()){
116 MTHREAD->msgOut(msgCode_h, message);
119 string totalMsg = prefix+msg_h;
120 cout<< totalMsg <<endl;
123 if(refreshGUI_h) {refreshGUI();}
143 if (MTHREAD && MTHREAD->usingGUI()){
144 MTHREAD->refreshGUI();
150 if (string_h ==
"")
return 0;
152 stringstream ss(string_h);
153 ss >> valueAsInteger;
154 return valueAsInteger;
172 if (string_h ==
"")
return 0.;
173 double valueAsDouble;
174 istringstream totalSString( string_h );
175 totalSString >> valueAsDouble;
176 return valueAsDouble;
196 string valueAsString = string_h;
198 replace(valueAsString.begin(), valueAsString.end(),
',',
'.');
199 return s2d(valueAsString);
201 return s2d(string_h);
209 if (string_h ==
"true" || string_h ==
"vero" || string_h ==
"TRUE" || string_h ==
"VRAI" || string_h ==
"1" || string_h ==
"True")
211 else if (string_h ==
"false" || string_h ==
"falso" || string_h ==
"FALSE" || string_h ==
"FAUX" || string_h ==
"0" || string_h ==
"" || string_h ==
"False")
214 msgOut(
MSG_CRITICAL_ERROR,
"Conversion string to bool failed. Some problems with the data? (got\""+string_h+
"\")");
224 snprintf ( outChar,
sizeof(outChar),
"%d", int_h );
225 return string(outChar);
234 snprintf ( outChar,
sizeof(outChar),
"%f", double_h );
235 return string(outChar);
240 if (bool_h)
return "true";
246 vector <int> valuesAsInteger;
247 for (uint i=0;i<string_h.size();i++){
248 valuesAsInteger.push_back(s2i(string_h[i]));
250 return valuesAsInteger;
255 BaseClass::s2d (
const vector <string>& string_h,
const bool& replaceComma)
const{
256 vector <double> valuesAsDouble;
257 for (uint i=0;i<string_h.size();i++){
259 string valueAsString = string_h[i];
261 replace(valueAsString.begin(), valueAsString.end(),
',',
'.');
262 valuesAsDouble.push_back(
s2d(valueAsString));
264 valuesAsDouble.push_back(s2d(string_h[i]));
267 return valuesAsDouble;
273 vector <bool> valuesAsBool;
274 for (uint i=0;i<string_h.size();i++){
275 valuesAsBool.push_back(s2b(string_h[i]));
282 vector <string> valuesAsString;
283 for (uint i=0;i<int_h.size();i++){
284 valuesAsString.push_back(i2s(int_h[i]));
286 return valuesAsString;
291 vector <string> valuesAsString;
292 for (uint i=0;i<double_h.size();i++){
293 valuesAsString.push_back(d2s(double_h[i]));
295 return valuesAsString;
300 vector <string> valuesAsString;
301 for (uint i=0;i<bool_h.size();i++){
302 if(bool_h[i]) valuesAsString.push_back(
"true");
303 else valuesAsString.push_back(
"false");
305 return valuesAsString;
312 if (type_h ==
"int") toReturn =
TYPE_INT;
313 else if (type_h ==
"double") toReturn =
TYPE_DOUBLE;
314 else if (type_h ==
"string") toReturn =
TYPE_STRING;
315 else if (type_h ==
"bool") toReturn =
TYPE_BOOL;
321 template<
typename T> std::string
323 std::ostringstream oss;
331 if(minval != NULL && maxval != NULL){
332 if (maxval <= minval){
333 msgOut(
MSG_CRITICAL_ERROR,
"Error in normSample: the maxvalue is lower than the minvalue");
337 normal_distribution<double> d(avg,stdev);
338 double c = d(*MTHREAD->gen);
339 if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
347 template<
typename T> T
349 std::istringstream iss(s);
358 for(vector < vector<int> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
359 toReturn += accumulate(j->begin(),j->end(),0);
366 double toReturn = 0.0;
367 for(vector < vector<double> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
368 toReturn += accumulate(j->begin(),j->end(),0.0);
376 string::size_type lastPos = str.find_first_not_of(delimiter, 0);
378 string::size_type pos = str.find_first_of(delimiter, lastPos);
380 while (string::npos != pos || string::npos != lastPos)
383 tokens.push_back(str.substr(lastPos, pos - lastPos));
385 lastPos = str.find_first_not_of(delimiter, pos);
387 pos = str.find_first_of(delimiter, lastPos);
397 for(
int i=0;i<tokens.size();i++){
400 if(i != (tokens.size()-1)){
423 if(op2.
i == i && op2.
s == s){
431 if(op2.
i == i && op2.
s == s){
439 if (i < op2.
i )
return true;
441 if (s < op2.
s)
return true;
448 if (i > op2.
i )
return true;
450 if (s > op2.
s)
return true;
457 if (i < op2.
i )
return true;
459 if (s <= op2.
s)
return true;
466 if (i > op2.
i )
return true;
468 if (s >= op2.
s)
return true;
491 if(op2.
i == i && op2.
i2 == i2 && op2.
s == s){
499 if(op2.
i == i && op2.
i2 == i2 && op2.
s == s){
507 if (i < op2.
i ) {
return true;}
509 if (i2 < op2.
i2 ) {
return true;}
511 if (s < op2.
s) {
return true;}
519 if (i > op2.
i ) {
return true;}
521 if (i2 > op2.
i2 ) {
return true;}
523 if (s > op2.
s) {
return true;}
531 if (i < op2.
i ) {
return true;}
533 if (i2 < op2.
i2 ) {
return true;}
535 if (s <= op2.
s) {
return true;}
543 if (i > op2.
i ) {
return true;}
545 if (i2 > op2.
i2 ) {
return true;}
547 if (s >= op2.
s) {
return true;}
573 if(op2.
i == i && op2.
i2 == i2 && op2.
s == s && op2.
s2 == s2){
581 if(op2.
i == i && op2.
i2 == i2 && op2.
s == s && op2.
s2 == s2){
589 if (i < op2.
i ) {
return true;}
591 if (i2 < op2.
i2 ) {
return true;}
593 if (s < op2.
s) {
return true;}
595 if (s2 < op2.
s2) {
return true;}
604 if (i > op2.
i ) {
return true;}
606 if (i2 > op2.
i2 ) {
return true;}
608 if (s > op2.
s) {
return true;}
610 if (s2 > op2.
s2) {
return true;}
619 if (i < op2.
i ) {
return true;}
621 if (i2 < op2.
i2 ) {
return true;}
623 if (s < op2.
s) {
return true;}
625 if (s2 <= op2.
s2) {
return true;}
634 if (i > op2.
i ) {
return true;}
636 if (i2 > op2.
i2 ) {
return true;}
638 if (s > op2.
s) {
return true;}
640 if (s2 >= op2.
s2) {
return true;}
649 if( (key_h.
i == NULL || key_h.
i==i) &&
650 (key_h.
i2 == NULL || key_h.
i2==i2) &&
651 (key_h.
s ==
"" || key_h.
s==s) &&
652 (key_h.
s2 ==
"" || key_h.
s2==s2) )
return true;
660 snprintf ( outChar1,
sizeof(outChar1),
"%d", i);
661 snprintf ( outChar2,
sizeof(outChar2),
"%d", i2);
662 return string(outChar1)+
'\t'+string(outChar2)+
'\t'+s+
'\t'+s2;
Class to provide a simple integer-integer-string-string key in std maps.
bool operator!=(const iskey &op2) const
Print an ERROR message, but don't stop the model.
Class to provide a simple integer-integer-string key in std maps.
int getType(const string &type_h) const
Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) ...
double normSample(const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only a...
bool operator==(const iisskey &op2) const
Do not actually output any message.
The required data is a string.
string i2s(const int &int_h) const
integer to string conversion
void tokenize(const string &str, vector< string > &tokens, const string &delimiter=" ") const
Tokenize a string using a delimiter (default is space)
The required data is a bool.
bool operator<=(const iiskey &op2) const
string b2s(const bool &bool_h) const
bool to string conversion
T stringTo(const std::string &s) const
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
iiskey()
iiskey class (note the double ii) ///
bool operator!=(const iisskey &op2) const
vector< double > s2d(const vector< string > &string_h, const bool &replaceComma=false) const
string to double conversion (vector)
bool operator<=(const iisskey &op2) const
bool filter(const iisskey &key_h) const
void untokenize(string &str, vector< string > &tokens, const string &delimiter=" ") const
string toString(const T &x) const
Class to provide a simple integer-string key to be used in std maps.
Print an error message and stop the model.
string d2s(const double &double_h) const
double to string conversion
bool operator>=(const iskey &op2) const
int vSum(const vector< int > &vector_h) const
bool operator<=(const iskey &op2) const
Print a debug message, normally filtered out.
The required data is a double.
bool operator<(const iskey &op2) const
bool operator==(const iiskey &op2) const
void msgOut2(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
Do the job of the overloaded functions.
bool operator<(const iiskey &op2) const
int s2i(const string &string_h) const
string to integer conversion
bool operator>(const iiskey &op2) const
The required data is an integer.
bool operator>=(const iisskey &op2) const
bool operator==(const iskey &op2) const
void refreshGUI() const
Ping to periodically return the control to the GUI.
bool operator>(const iskey &op2) const
bool s2b(const string &string_h) const
string to bool conversion
bool operator>=(const iiskey &op2) const
bool operator!=(const iiskey &op2) const
double s2d(const string &string_h) const
string to double conversion
bool operator>(const iisskey &op2) const
This file is the header of BaseClass and it is included by ALL compiled code.
iisskey()
iisskey class (note the double ii and double ss) ///
bool operator<(const iisskey &op2) const