Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Param.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be usefulen,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include <Base/Common/W32Compat.hh>
26 
27 #include <stdlib.h>
28 //#include <unistd.h>
29 
30 #ifdef WIN32
31 # include <Base/Common/getopt_W32.h>
32 #else //not WIN32
33 # include <getopt.h>
34 #endif //WIN32
35 
36 #include <stdio.h>
37 #include <iostream>
38 #include <iomanip>
39 #include <fstream>
40 #include <sstream>
41 #include <time.h>
42 #include <algorithm>
43 
44 #include "Param.hh"
45 #include "ParamTypes.hh"
46 
47 // for umask
48 #include <sys/types.h>
49 #include <sys/stat.h>
50 #include <locale.h>
51 
52 
53 using namespace BIAS;
54 using namespace std;
55 
56 // we set a typedef here, as we need const iterators very often...
57 typedef map<const std::string,BIAS::ParamTypeBase*>::const_iterator CI;
58 
59 
60 // JW
62 {}
63 
65 {}
66 
67 
69  const std::string & /*paramname*/,
70  const void * /*data*/)
71 {}
72 
73 
74 Param::Param(bool DisableDestructorWarning)
75 {
76  DestructorWarning_ = !DisableDestructorWarning;
77  // init some members
78  ParamMap_.clear();
79  AddParamString("writeconfig","Write file with current configuration");
80  AddParamString("readconfig","Read configuration from file");
81 #ifdef BIAS_HAVE_XML2
82  AddParamString("writeconfigXML","Write XML file with current configuration");
83  AddParamString("readconfigXML","Read configuration from XML file");
84 #endif
85  AddParamBool("expert","Expert Mode: also show and write parameters marked "
86  "as enhanced");
87  SetParameterWriteToFile("writeconfig",false);
88  SetParameterWriteToFile("readconfig",false);
89 #ifdef BIAS_HAVE_XML2
90  SetParameterWriteToFile("writeconfigXML",false);
91  SetParameterWriteToFile("readconfigXML",false);
92 #endif
93  SetParameterWriteToFile("expert", false);
94  // needed to ensure consistent ,/. behavior in different envs
95  setlocale(LC_ALL, "C");
96  //setlocale(LC_NUMERIC, "C");
97  //setlocale(LC_CTYPE , "C");
98 
99  // default Write-options
100  WriteComments_ = true;
101  WriteIndent_ = false;
102  WriteEnhanced_ = false;
103  WriteFlagSet_ = false;
104 }
105 
106 
108 {
109  // destroy all listitems...
110  for ( CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
111  // cerr << " deleting "<<it->first<<endl;
112  delete it->second;
113  }
114  //#ifdef BIAS_DEBUG
115  // if (DestructorWarning_)
116  // BIASERR("\n Warning: Parameter are held in class Param. Don't delete this class, if you're still using the parameter somewhere.\n\n");
117  //#endif
118 }
119 
120 
121 void Param::ShowData(std::ostream &os, int grp, bool showenhanced)
122 {
123  int namew=GetSizeOfLongestParamName()+2, typew=7;
124  int valw=GetSizeOfLongestParamValueString()+2;
125 
126  namew=(namew<20)?(20):namew;
127  valw=(valw<7)?(7):valw;
128 
129  int pos = 0;
130 
131  CI it;
132 
133  os <<"idx"<<setw(namew)<<"name"<<setw(typew)
134  <<"type"<<setw(valw)<<"value"<<" options"<<endl;
135 
136  if (grp==GRP_ALL){
137  vector<int> grps=UniqueSortedGroups();
138  vector<int>::iterator git;
139  for (git=grps.begin(); git!=grps.end(); git++){
140  os <<"\n############### Group ID "<<*git<<" : "<<GetGroupName(*git)
141  <<" #######################\n";
142  for(it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
143  if ((*it).second->Group_==*git){
144  if ((showenhanced || (!(*it).second->Enhanced_)) &&
145  (!(*it).second->Hidden_)) {
146  os << pos << ": " << setw(namew) << it->first;
147  os << setw(typew) << it->second->GetTypeName()<<" "
148  << setw(valw) << it->second->GetValueString() <<" "
149  << it->second->ShortCmd_ ;
150  if ((*it).second->Enhanced_) os << " (enhanced)";
151  os << endl;
152  pos++;
153  }
154  }
155  }
156  }
157  } else {
158  for(it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
159  if ((*it).second->Group_==grp){
160  if ((showenhanced || (!(*it).second->Enhanced_)) &&
161  (!(*it).second->Hidden_)) {
162  os << pos << ": " << setw(namew) << it->first;
163  os << setw(typew) << it->second->GetTypeName()<<" "
164  << setw(valw) << it->second->GetValueString() <<" "
165  << it->second->ShortCmd_;
166  if ((*it).second->Enhanced_) os << " (enhanced)";
167  os << endl;
168  pos++;
169  }
170  }
171  }
172  }
173 }
174 
175 
176 void Param::Usage(std::ostream &os)
177 {
178  int namew = 0;
179  int typew = 8;
180  char tmpstr[256]; // max. length of name is assumed to be < 254
181  bool expert = *GetParamBool("expert");
182 
183  if (WriteIndent_)
184  {
185  // search the length of the largest name to compute indentation
186  for (CI it = ParamMap_.begin(); it != ParamMap_.end(); it++) {
187  if ((!it->second->Enhanced_ || expert) && !it->second->Hidden_) {
188  int len = it->first.length();
189  if (len > namew) namew = len;
190  }
191  }
192  }
193 
194  os << endl;
195  os << "Available Parameters : ";
196  os << endl;
197 
198  vector<int> grps = UniqueSortedGroups();
199  for (vector<int>::iterator git = grps.begin(); git!=grps.end(); git++)
200  {
201  if (*git > -1)
202  os << endl << " ---- " << GetGroupName(*git) << " ------------";
203  os << endl;
204  for (CI it = ParamMap_.begin(); it != ParamMap_.end(); it++)
205  {
206  if (it->second->Group_ == *git && !it->second->Hidden_ &&
207  (expert || !it->second->Enhanced_))
208  {
209  sprintf(tmpstr, "--%s", it->first.c_str());
210  if (WriteIndent_)
211  os << setfill(' ') << setw(namew+2);
212  os << left << tmpstr;
213  if (it->second->ShortCmd_ == 0)
214  os << " ";
215  else if (WriteIndent_)
216  os << " -" << it->second->ShortCmd_ << " ";
217  else
218  os << ", -" << it->second->ShortCmd_ << " ";
219  if (WriteIndent_)
220  os << setfill(' ') << setw(typew);
221  if (dynamic_cast<ParamTypeInt*>(it->second))
222  {
223  // element is of type INTEGER
224  os << left << "INT";
225  }
226  else if (dynamic_cast<ParamTypeBool*>(it->second))
227  {
228  // element is of type BOOLEAN
229  os << left << "BOOL";
230  }
231  else if (dynamic_cast<ParamTypeDouble*>(it->second))
232  {
233  // element is of type DOUBLE
234  os << left << "DOUBLE";
235  }
236  else if (dynamic_cast<ParamTypeString*>(it->second))
237  {
238  // element is of type STRING
239  os << left << "STRING";
240  }
241  else if (dynamic_cast<ParamTypeVecDbl*>(it->second))
242  {
243  // element is of type VECTOR OF DOUBLE
244  os << left << "VECDBL";
245  }
246  else if (dynamic_cast<ParamTypeVecInt*>(it->second))
247  {
248  // element is of type VECTOR OF INTEGER
249  os << left << "VECINT";
250  }
251  else if (dynamic_cast<ParamTypeEnum*>(it->second))
252  {
253  // element is of type VECTOR OF INTEGER
254  os << left << "ENUM";
255  // now output all possible enum values
256  os << "\n\t[ " << dynamic_cast<ParamTypeEnum*>(it->second)->GetHint() << " ]";
257  }
258  else
259  {
260  os << left << "unknown";
261  }
262  os <<" : \n\t";
263  if (it->second->Help_ != "")
264  os << it->second->Help_;
265  else
266  os << "No help available";
267  os << endl;
268  }
269  }
270  os << endl;
271  }
272 }
273 
274 // ADDING routines ---------------------------------------------------
275 
276 int * Param::AddParamInt( const std::string &name,
277  const std::string &help, int deflt,
278  int min, int max ,char cmdshort, int Group)
279 {
280  if ( ParamMap_.find(name)!=ParamMap_.end() )
281  {
282  BIASERR("Cannot add parameter "<<name<<". Already in list!");
283  return NULL;
284  }
285 
286  ParamTypeInt * NewItem = new ParamTypeInt();
287  BIASASSERT(NewItem!=NULL);
288 
289  NewItem->Name_ = name;
290  NewItem->Help_ = help;
291  NewItem->ShortCmd_ = cmdshort;
292  NewItem->Group_ = Group;
293  NewItem->WriteToFile_ = true;
294  NewItem->value_ = deflt;
295  NewItem->default_ = deflt;
296  NewItem->min_ = min;
297  NewItem->max_ = max;
298  pair<string, ParamTypeBase*> NewPair(name, NewItem);
299  ParamMap_.insert(ParamMap_.end(), NewPair );
300 
301  return &(NewItem->value_);;
302 }
303 
304 
305 bool * Param::AddParamBool( const std::string &name, const std::string &help,
306  bool deflt, char cmdshort, int Group )
307 {
308  if ( ParamMap_.find(name)!=ParamMap_.end() )
309  {
310  BIASERR("Cannot add parameter "<<name<<". Already in list!");
311  return NULL;
312  }
313  ParamTypeBool * NewItem = new ParamTypeBool();
314  NewItem->Name_ = name;
315  NewItem->Help_ = help;
316  NewItem->ShortCmd_ = cmdshort;
317  NewItem->Group_ = Group;
318  NewItem->WriteToFile_ = true;
319  NewItem->value_ = deflt;
320  NewItem->default_ = deflt;
321  pair<string, ParamTypeBase*> NewPair(name,NewItem);
322  ParamMap_.insert(ParamMap_.end(), NewPair );
323  return &(NewItem->value_);
324 }
325 
326 
327 std::string * Param::AddParamString( const std::string &name,
328  const std::string &help,
329  std::string deflt, char cmdshort,
330  int Group )
331 {
332  if ( ParamMap_.find(name)!=ParamMap_.end() )
333  {
334  BIASERR("Cannot add parameter "<<name<<". Already in list!");
335  return NULL;
336  }
337  ParamTypeString * NewItem = new ParamTypeString();
338  NewItem->Name_ = name;
339  NewItem->Help_ = help;
340  NewItem->ShortCmd_ = cmdshort;
341  NewItem->Group_ = Group;
342  NewItem->WriteToFile_ = true;
343  NewItem->value_ = deflt;
344  NewItem->default_ = deflt;
345  pair<string, ParamTypeBase*> NewPair(name,NewItem);
346  ParamMap_.insert(ParamMap_.end(), NewPair );
347  return &(NewItem->value_);;
348 }
349 
350 
351 double * Param::AddParamDouble( const std::string &name,
352  const std::string &help,
353  double deflt,
354  double min, double max,
355  char cmdshort, int Group)
356 {
357  if ( ParamMap_.find(name)!=ParamMap_.end() )
358  {
359  BIASERR("Cannot add parameter "<<name<<". Already in list!");
360  return NULL;
361  }
362  ParamTypeDouble * NewItem = new ParamTypeDouble();
363  NewItem->Name_ = name;
364  NewItem->Help_ = help;
365  NewItem->ShortCmd_ = cmdshort;
366  NewItem->Group_ = Group;
367  NewItem->WriteToFile_ = true;
368  NewItem->value_ = deflt;
369  NewItem->default_ = deflt;
370  NewItem->min_ = min;
371  NewItem->max_ = max;
372  pair<string, ParamTypeBase*> NewPair(name,NewItem);
373  ParamMap_.insert(ParamMap_.end(), NewPair );
374  return &(NewItem->value_);;
375 }
376 
377 
378 BIAS::Vector<double> * Param::AddParamVecDbl( const std::string &name,
379  const std::string &help,
380  const Vector<double> &deflt,
381  char cmdshort, int Group )
382 {
383  if ( ParamMap_.find(name)!=ParamMap_.end() )
384  {
385  BIASERR("Cannot add parameter "<<name<<". Already in list!");
386  return NULL;
387  }
388  ParamTypeVecDbl * NewItem = new ParamTypeVecDbl();
389  NewItem->Name_ = name;
390  NewItem->Help_ = help;
391  NewItem->Group_ = Group;
392  NewItem->ShortCmd_ = cmdshort;
393  NewItem->WriteToFile_ = true;
394  NewItem->value_ = deflt;
395  NewItem->default_ = deflt;
396  pair<string, ParamTypeBase*> NewPair(name,NewItem);
397  ParamMap_.insert(ParamMap_.end(), NewPair );
398  return &(NewItem->value_);
399 }
400 
401 BIAS::Vector<double> * Param::AddParamVecDbl( const std::string &name,
402  const std::string &help,
403  const std::string &deflt,
404  char cmdshort,
405  int Group )
406 {
407  std::vector<double> parsedValues;
408  BIAS::Vector<double> values;
409 
410  std::stringstream defStream(deflt);
411  double temp;
412  while (defStream.good()) {
413  defStream>>temp;
414  parsedValues.push_back(temp);
415  }
416  values.newsize(parsedValues.size());
417  for (unsigned int i=0;i<parsedValues.size();i++)
418  values[i]=parsedValues[i];
419  return AddParamVecDbl(name, help, values, cmdshort,Group);
420 }
421 
422 
423 BIAS::Vector<int> * Param::AddParamVecInt( const std::string &name,
424  const std::string &help,
425  const Vector<int> &deflt,
426  char cmdshort, int Group )
427 {
428  if ( ParamMap_.find(name)!=ParamMap_.end() )
429  {
430  BIASERR("Cannot add parameter "<<name<<". Already in list!");
431  return NULL;
432  }
433  ParamTypeVecInt * NewItem = new ParamTypeVecInt();
434  NewItem->Name_ = name;
435  NewItem->Help_ = help;
436  NewItem->Group_ = Group;
437  NewItem->ShortCmd_ = cmdshort;
438  NewItem->WriteToFile_ = true;
439  NewItem->value_ = deflt;
440  NewItem->default_ = deflt;
441  pair<string, ParamTypeBase*> NewPair(name,NewItem);
442  ParamMap_.insert(ParamMap_.end(), NewPair );
443  return &(NewItem->value_);;
444 }
445 
446 BIAS::Vector<int> * Param::AddParamVecInt( const std::string &name,
447  const std::string &help,
448  const std::string &deflt,
449  char cmdshort,
450  int Group )
451 {
452  std::vector<int> parsedValues;
453  BIAS::Vector<int> values;
454 
455  std::stringstream defStream(deflt);
456  int temp;
457  while (defStream.good()) {
458  defStream>>temp;
459  parsedValues.push_back(temp);
460  }
461  values.newsize(parsedValues.size());
462  for (unsigned int i=0;i<parsedValues.size();i++)
463  values[i]=parsedValues[i];
464  return AddParamVecInt(name, help, values, cmdshort,Group);
465 }
466 
467 
468 int * Param::AddParamEnum( const std::string &name,
469  const std::string &help,
470  const std::vector<std::string> &enums,
471  const int deflt,
472  const std::vector<int> * IDs,
473  const char cmdshort,
474  const int Group )
475 {
476  if ( ParamMap_.find(name)!=ParamMap_.end() )
477  {
478  BIASERR("Cannot add parameter "<<name<<". Already in list!");
479  return NULL;
480  }
481  if ( enums.empty() )
482  {
483  BIASERR("At least one item is needed for enum type");
484  return NULL;
485  }
486  if ( IDs != NULL && IDs->size() != enums.size() )
487  {
488  BIASERR("You gave "<<enums.size()<< "enums but "<<IDs->size()
489  <<" ID values! Both numbers must be equal!");
490  return NULL;
491  }
492  ParamTypeEnum * NewItem = new ParamTypeEnum();
493  NewItem->Name_ = name;
494  NewItem->Help_ = help;
495  NewItem->Group_ = Group;
496  NewItem->ShortCmd_ = cmdshort;
497  NewItem->WriteToFile_ = true;
498  NewItem->value_ = deflt;
499  NewItem->default_ = deflt;
500  pair<string,int> NewEnumPair;
501  int newID;
502  for(unsigned int i=0; i<enums.size(); i++)
503  {
504  newID = IDs?(*IDs)[i]:i;
505  if ( NewItem->Map_.find(enums[i]) != NewItem->Map_.end() ) {
506  BIASERR("Given enum IDs must be unique!");
507  delete NewItem;
508  return NULL;
509  }
510  NewEnumPair = make_pair(enums[i],newID );
511  NewItem->Map_.insert(NewItem->Map_.end(), NewEnumPair);
512  }
513  // if ( NewItem->Map_.find(deflt) == NewItem->Map_.end() )
514  // {
515  // BIASERR("The given default ID is not in the enum list!");
516  // delete NewItem;
517  // return NULL;
518  // }
519  pair<string, ParamTypeBase*> NewPair(name,NewItem);
520  ParamMap_.insert(ParamMap_.end(), NewPair );
521  return &(NewItem->value_);
522 }
523 
524 
525 ////////////// CheckParam() ///////////////
526 
527 bool Param::CheckParam(const std::string &name)
528 {
529  if ( ParamMap_.find(name) == ParamMap_.end() ) return false;
530  else return true;
531 }
532 
533 // GETTING routines --------------------------------------------------
534 int * Param::GetParamIntByIndex( const int i )const
535 {
536 
537  CI it;
538  int pos = -1;
539  for(it=ParamMap_.begin(); (it!=ParamMap_.end() || (pos == i)); it++){
540  pos++;
541 
542  if (pos == i) {
543  if ( ParamTypeInt *item = dynamic_cast<ParamTypeInt*>(it->second) )
544  return &(item->value_);
545  else{
546  BIASERR("Type of parameter is invalid!");
547  return NULL;
548  }
549  }
550  }
551  BIASERR("Index is invalid!");
552  return NULL;
553 }
554 
555 double * Param::GetParamDoubleByIndex( const int i )const
556 {
557 
558  CI it;
559  int pos = -1;
560  for(it=ParamMap_.begin(); (it!=ParamMap_.end() || (pos == i)); it++){
561  pos++;
562 
563  if (pos == i) {
564  if ( ParamTypeDouble *item = dynamic_cast<ParamTypeDouble*>(it->second) )
565  return &(item->value_);
566  else{
567  BIASERR("Parameter is invalid!");
568  return NULL;
569  }
570  }
571  }
572  BIASERR("Index is invalid!");
573  return NULL;
574 }
575 
576 bool * Param::GetParamBoolByIndex( const int i )const
577 {
578 
579  CI it;
580  int pos = -1;
581  for(it=ParamMap_.begin(); (it!=ParamMap_.end() || (pos == i)); it++){
582  pos++;
583 
584  if (pos == i) {
585  if ( ParamTypeBool *item = dynamic_cast<ParamTypeBool*>(it->second) )
586  return &(item->value_);
587  else{
588  BIASERR("Parameter is invalid!");
589  return NULL;
590  }
591  }
592  }
593  BIASERR("Index is invalid!");
594  return NULL;
595 }
596 
597 std::string * Param::GetParamStringByIndex( const int i )const
598 {
599 
600  CI it;
601  int pos = -1;
602  for(it=ParamMap_.begin(); (it!=ParamMap_.end() || (pos == i)); it++){
603  pos++;
604 
605  if (pos == i) {
606  if ( ParamTypeString *item = dynamic_cast<ParamTypeString*>(it->second) )
607  return &(item->value_);
608  else{
609  BIASERR("Parameter is invalid!");
610  return NULL;
611  }
612  }
613  }
614  BIASERR("Index is invalid!");
615  return NULL;
616 }
617 
618 int * Param::GetParamInt( const std::string &name )const
619 {
620  CI it = ParamMap_.find(name);
621  if ( it==ParamMap_.end() ){
622  BIASERR("int parameter "<<name<<" not found!");
623  return NULL;
624  }
625  else if ( ParamTypeInt *item = dynamic_cast<ParamTypeInt*>(it->second) )
626  return &(item->value_);
627  else{
628  BIASERR("Parameter "<<name<<" is not of type INTEGER!");
629  return NULL;
630  }
631 }
632 
633 bool * Param::GetParamBool( const std::string &name )const
634 {
635  CI it = ParamMap_.find(name);
636  if ( it==ParamMap_.end() ){
637  BIASERR("bool parameter "<<name<<" not found!");
638  return NULL;
639  }
640  else if ( ParamTypeBool *item = dynamic_cast<ParamTypeBool*>(it->second) )
641  return &(item->value_);
642  else{
643  BIASERR("Parameter "<<name<<" is not of type BOOLEAN!");
644  return NULL;
645  }
646 }
647 
648 
649 std::string * Param::GetParamString( const std::string &name )const
650 {
651  CI it = ParamMap_.find(name);
652  if ( it==ParamMap_.end() ){
653  BIASERR("string parameter "<<name<<" not found!");
654  return NULL;
655  }
656  else if (ParamTypeString *item=dynamic_cast<ParamTypeString*>(it->second))
657  return &(item->value_);
658  else{
659  BIASERR("Parameter "<<name<<" is not of type STRING!");
660  return NULL;
661  }
662 }
663 
664 
665 double * Param::GetParamDouble( const std::string &name )const
666 {
667  CI it = ParamMap_.find(name);
668  if ( it==ParamMap_.end() ){
669  BIASERR("double parameter "<<name<<" not found!");
670  return NULL;
671  }
672  else if (ParamTypeDouble *item=dynamic_cast<ParamTypeDouble*>(it->second))
673  return &(item->value_);
674  else{
675  BIASERR("Parameter "<<name<<" is not of type DOUBLE!");
676  return NULL;
677  }
678 }
679 
680 BIAS::Vector<double> * Param::GetParamVecDbl( const std::string &name )const
681 {
682  CI it = ParamMap_.find(name);
683  if ( it==ParamMap_.end() ){
684  BIASERR("vecdbl parameter "<<name<<" not found!");
685  return NULL;
686  }
687  else if (ParamTypeVecDbl *item=dynamic_cast<ParamTypeVecDbl*>(it->second))
688  return &(item->value_);
689  else{
690  BIASERR("Parameter "<<name<<" is not of type VECTOR OF DOUBLE!");
691  return NULL;
692  }
693 }
694 
695 
696 BIAS::Vector<int> * Param::GetParamVecInt( const std::string &name )const
697 {
698  CI it = ParamMap_.find(name);
699  if ( it==ParamMap_.end() ){
700  BIASERR("vecint parameter "<<name<<" not found!");
701  return NULL;
702  }
703  else if (ParamTypeVecInt *item=dynamic_cast<ParamTypeVecInt*>(it->second))
704  return &(item->value_);
705  else{
706  BIASERR("Parameter "<<name<<" is not of type VECTOR OF INTEGER!");
707  return NULL;
708  }
709 }
710 
711 
712 int * Param::GetParamEnum( const std::string &name )const
713 {
714  CI it = ParamMap_.find(name);
715  if ( it==ParamMap_.end() ){
716  BIASERR("enum parameter \""<<name<<"\" not found!");
717  return NULL;
718  }
719  else if ( ParamTypeEnum *item = dynamic_cast<ParamTypeEnum*>(it->second) )
720  return &(item->value_);
721  else{
722  BIASERR("Parameter "<<name<<" is not of type ENUM!");
723  return NULL;
724  }
725 }
726 
727 // SETTING routines --------------------------------------------------
728 
729 int * Param::SetParamInt( const std::string &name, const int &value )
730 {
731  CI it = ParamMap_.find(name);
732  if ( it==ParamMap_.end() )
733  {
734  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
735  <<" returning NULL!");
736  return NULL;
737  }
738  if ( ParamTypeInt *item = dynamic_cast<ParamTypeInt*>(it->second) )
739  {
740  if ( value < item->min_ || value > item->max_ )
741  {
742  BIASERR("Valid values for \""<<name<<"\" are between "
743  <<item->min_<<" and "<<item->max_<<"!");
744  return NULL;
745  }
746  item->value_ = value;
747  return &(item->value_);
748  }
749  else
750  {
751  BIASERR("Parameter "<<name<<" is not of type INTEGER!");
752  return NULL;
753  }
754 }
755 
756 
757 bool * Param::SetParamBool( const std::string &name, const bool &value )
758 {
759  CI it = ParamMap_.find(name);
760  if ( it==ParamMap_.end() )
761  {
762  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
763  <<" returning NULL!");
764  return NULL;
765  }
766  if ( ParamTypeBool *item = dynamic_cast<ParamTypeBool*>(it->second) )
767  {
768  item->value_ = value;
769  return &(item->value_);
770  }
771  else
772  {
773  BIASERR("Parameter "<<name<<" is not of type BOOLEAN!");
774  return NULL;
775  }
776 }
777 
778 
779 std::string * Param::SetParamString( const std::string &name,
780  const std::string &value )
781 {
782  CI it = ParamMap_.find(name);
783  if ( it==ParamMap_.end() )
784  {
785  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
786  <<" returning NULL!");
787  return NULL;
788  }
789  else if( ParamTypeString *item = dynamic_cast<ParamTypeString*>(it->second) )
790  {
791  item->value_ = value;
792  return &(item->value_);
793  }
794  else
795  {
796  BIASERR("Parameter "<<name<<" is not of type STRING!");
797  return NULL;
798  }
799 }
800 
801 
802 double * Param::SetParamDouble( const std::string &name, const double &value )
803 {
804  CI it = ParamMap_.find(name);
805  if ( it==ParamMap_.end() )
806  {
807  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
808  <<" returning NULL!");
809  return NULL;
810  }
811  if ( ParamTypeDouble *item = dynamic_cast<ParamTypeDouble*>(it->second) )
812  {
813  if ( value < item->min_ || value > item->max_ )
814  {
815  BIASERR("Valid values for "<<name<<" are between "
816  <<item->min_<<" and "<<item->max_<<"!");
817  return NULL;
818  }
819  item->value_ = value;
820  return &(item->value_);
821  }
822  else
823  {
824  BIASERR("Parameter "<<name<<" is not of type DOUBLE!");
825  return NULL;
826  }
827 }
828 
829 
830 BIAS::Vector<double> * Param::SetParamVecDbl( const std::string &name,
831  const Vector<double> &value )
832 {
833  CI it = ParamMap_.find(name);
834  if ( it==ParamMap_.end() )
835  {
836  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
837  <<" returning NULL!");
838  return NULL;
839  }
840  if ( ParamTypeVecDbl *item = dynamic_cast<ParamTypeVecDbl*>(it->second) )
841  {
842  // if ( value.size() != item->default_.size() )
843  // {
844  // BIASERR("New vector for "<<name<<" must be of size "
845  // <<item->default_.size()<<" but this one's is "
846  // <<value.size()<<"!");
847  // return NULL;
848  // }
849  item->value_ = value;
850  return &(item->value_);
851  }
852  else
853  {
854  BIASERR("Parameter "<<name<<" is not of type VECTOR OF DOUBLE!");
855  return NULL;
856  }
857 }
858 
859 
860 BIAS::Vector<int> * Param::SetParamVecInt( const std::string &name,
861  const Vector<int> &value )
862 {
863  CI it = ParamMap_.find(name);
864  if ( it==ParamMap_.end() )
865  {
866  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
867  <<" returning NULL!");
868  return NULL;
869  }
870  if ( ParamTypeVecInt *item = dynamic_cast<ParamTypeVecInt*>(it->second) )
871  {
872  // if ( value.size() != item->default_.size() )
873  // {
874  // BIASERR("New vector for "<<name<<" must be of size "
875  // <<item->default_.size()<<" but this one's is "
876  // <<value.size()<<"!");
877  // return NULL;
878  // }
879  item->value_ = value;
880  return &(item->value_);
881  }
882  else
883  {
884  BIASERR("Parameter "<<name<<" is not of type VECTOR OF INTEGER!");
885  return NULL;
886  }
887 }
888 
889 
890 int * Param::SetParamEnum( const std::string &name,const std::string &value )
891 {
892  CI it = ParamMap_.find(name);
893  if ( it==ParamMap_.end() )
894  {
895  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
896  <<" returning NULL!");
897  return NULL;
898  }
899  if ( ParamTypeEnum *item = dynamic_cast<ParamTypeEnum*>(it->second) )
900  {
901  map<string,int>::iterator it;
902  if ( (it=item->Map_.find(value)) == item->Map_.end() ) {
903  BIASERR(value << " is not a valid ID for this enum!");
904  return NULL;
905  }
906  item->value_ = it->second;
907  return &(item->value_);
908  }
909  else
910  {
911  BIASERR("Parameter "<<name<<" is not of type ENUM!");
912  return NULL;
913  }
914 }
915 
916 
917 int * Param::SetParamEnum( const std::string &name, const int &value )
918 {
919  CI it = ParamMap_.find(name);
920  if ( it==ParamMap_.end() )
921  {
922  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
923  <<" returning NULL!");
924  return NULL;
925  }
926  if ( ParamTypeEnum *item = dynamic_cast<ParamTypeEnum*>(it->second) ) {
927  // rush through map and if value is valid, set it
928  map<string, int>::iterator it;
929  for(it=item->Map_.begin(); it!=item->Map_.end(); it++)
930  if ( it->second == value ){
931  item->value_ = value;
932  return &(item->value_);
933  }
934  BIASERR(value << " is not in this enum!");
935  return NULL;
936  }
937  else {
938  BIASERR("Parameter "<<name<<" is not of type ENUM!");
939  return NULL;
940  }
941 }
942 
943 
944 int Param::SetParameterWriteToFile(const std::string &name, bool writeToFile)
945 {
946  CI it = ParamMap_.find(name);
947  if ( it==ParamMap_.end() )
948  {
949  BIASERR("Parameter \""<<name<<"\" not found, cannot set parameter,"
950  <<" returning -1!");
951  return -1;
952  }
953  it->second->WriteToFile_ = writeToFile;
954  return 0;
955 }
956 
957 int Param::SetEnhancedFlag(const std::string &name, bool enhanced)
958 {
959  CI it = ParamMap_.find(name);
960  if ( it==ParamMap_.end() )
961  {
962  BIASERR("Parameter \""<<name<<"\" not found, cannot set to enhanced, "
963  <<" returning -1!");
964  return -1;
965  }
966  it->second->Enhanced_ = enhanced;
967  return 0;
968 }
969 
970 int Param::SetHiddenFlag(const std::string &name, bool hidden)
971 {
972  CI it = ParamMap_.find(name);
973  if ( it==ParamMap_.end() )
974  {
975  BIASERR("Parameter \""<<name<<"\" not found, cannot set to hidden, "
976  <<" returning -1!");
977  return -1;
978  }
979  it->second->Hidden_ = hidden;
980  return 0;
981 }
982 
983 // command line and file processing methods --------------------------
984 
985 int Param::UpdateParameter(int &argc, char *argv[],
986  const std::string &default_filename)
987 {
988  int res;
989  // provide a default file name to readconfig
990  *GetParamString("readconfig")=default_filename;
991  res = ParseCommandLine(argc, argv);
992  string *name=GetParamString("writeconfig");
993  bool *expert=GetParamBool("expert");
994 
995  if (*name!="") {
996  //cerr << "*name "<<*name<<endl;
997  // comments on !
998  SetWriteOptions(WriteIndent_,true,WriteEnhanced_ || *expert);
999  WriteParameter(*name);
1000  BIASDOUT(D_PARAM_CONF_FILE, "wrote default param file "
1001  <<default_filename<<endl);
1002  } else {
1003  // write default parameter file if no parameter file given and default
1004  // file not found
1005  if (*GetParamString("readconfig")==default_filename) {
1006  BIASDOUT(D_PARAM_CONF_FILE, "using default param file "
1007  <<default_filename<<endl);
1008  ifstream is(default_filename.c_str());
1009  if (!is) {
1010  is.close();
1011  SetWriteOptions(WriteIndent_,false,WriteEnhanced_|| *expert); // comments off
1012  WriteParameter(default_filename);
1013  BIASDOUT(D_PARAM_CONF_FILE, "wrote default param file "
1014  <<default_filename<<endl);
1015  } else {
1016  is.close();
1017  BIASDOUT(D_PARAM_CONF_FILE, "found default param file "
1018  <<default_filename<<endl);
1019  }
1020  } else {
1021  BIASDOUT(D_PARAM_CONF_FILE, "using user given param file "
1022  <<*GetParamString("readconfig")<<endl);
1023  }
1024  }
1025  return res;
1026 }
1027 
1028 int Param::ParseCommandLine(int &argc, char *argv[])
1029 {
1030  // if no arguments are given on Cmdl, return index to last non-opt: 1
1031  string *readPrj;
1032  if (argc==1) {
1033  // read configuration file if one is given (see UpdateParameter)
1034  if ( (readPrj = GetParamString("readconfig"))!=NULL ){
1035  if (*readPrj != ""){
1036  //cout <<"Reading configuration from file: "<<*readPrj<<endl;
1037  BIASDOUT(D_PARAM_CONF_FILE, "Reading configuration from file: "
1038  <<*readPrj<<endl);
1039  if (ReadParameter(*readPrj)<0) return -1;
1040  }
1041  }
1042  return 1;
1043  }
1044  BIASDOUT(D_PARAM_PARSECMDL,"Param::ParseCommandLine()");
1045 
1046  // fisrt get a copy of all that if we not already have one
1047  if (ArgV_.size() ==0)
1048  for ( int i=0;i<argc; i++)
1049  ArgV_.push_back(argv[i]);
1050 
1051  //BIASDOUT(D_PARAM_PARSECMDL,"NumParams_: "<<ParamMap_.size());
1052  int itemcount = 0;
1053  // there are NumParams_ shortopts maximum, each may have one arg,
1054  // plus trailing 0
1055  char *shortoptstring=new char[ParamMap_.size()*3+1];
1056  bool bReadConfig =true, bParse=true;
1057  while (bParse) {
1058  // set string empty
1059  shortoptstring[0] = 0;
1060  itemcount = 0;
1061  char tmpstr[2];
1062  tmpstr[1] = 0;
1063 
1064  // prepare array of longopts for getopt_long()
1065  // last element must be zeored
1066  longopts = new struct option[ParamMap_.size()+1];
1067  memset(&longopts[ParamMap_.size()], 0, sizeof(struct option));
1068 
1069  // traverse list of parameters and fill in longopts[]
1070 
1071  for (CI it=ParamMap_.begin(); it!=ParamMap_.end(); ++it)
1072  {
1073  longopts[itemcount].name = (it->first).c_str();
1074  // only type BOOL has an optional argument
1075  if ( dynamic_cast<ParamTypeBool*>(it->second) != NULL )
1076  longopts[itemcount].has_arg = optional_argument;
1077  else longopts[itemcount].has_arg = required_argument;
1078 
1079  // set .flag to NULL, then .val is returned from getopt_long()
1080  longopts[itemcount].flag = NULL;
1081  // set .val to itemcount+offset let us find the target in ParamList_
1082  // much faster. Offset is required to differ from shortopt char
1083  longopts[itemcount].val = itemcount+1000;
1084 
1085  // prepare shortoptstring
1086  if ( it->second->ShortCmd_!=0 ) {
1087  tmpstr[0] = it->second->ShortCmd_;
1088  strcat(shortoptstring, tmpstr);
1089  // append ':' to shortopstring for arguments to options
1090  strcat(shortoptstring, ":");
1091  // append a second ':' to bool, for optional argument
1092  if ( dynamic_cast<ParamTypeBool*>(it->second) != NULL)
1093  strcat(shortoptstring, ":");
1094  }
1095  itemcount++;
1096  }
1097  // reset optind to start scanning from 0
1098  optind = 0;
1099 
1100  bool done = false;
1101  int short_or_index=0;
1102  // now scan
1103  while (!done)
1104  {
1105  // getopt_long() returns a char if the short option was found
1106  // if the long option was found, the longopts.val is returned
1107  // in this case the index to longopts[] + 1000
1108  //getopt_long not present in WIN32
1109  short_or_index = ::getopt_long(argc, argv, shortoptstring,
1110  longopts, NULL);
1111  // short_or_index = getopt(argc, argv, shortoptstring);
1112 
1113  // '?' means unknown option, ':' means missing argument
1114  if (short_or_index == '?' || short_or_index == ':') {
1115  delete [] longopts;
1116  Usage();
1117  return -1;
1118  }
1119 
1120  if (short_or_index == -1)
1121  done = true;
1122  else
1123  {
1124  // decide if short or long found
1125  CI it;
1126  if (short_or_index >=1000){
1127  // long opt found, take name from longopts and search in map
1128  int index = short_or_index -1000;
1129  it = ParamMap_.find(longopts[index].name);
1130  BIASDOUT(D_PARAM_PARSECMDL,"longopt at "<<index
1131  <<" : "<<it->first);
1132  }
1133  else{
1134  for(it=ParamMap_.begin();it!=ParamMap_.end(); it++)
1135  if ( it->second->ShortCmd_==short_or_index ){
1136  BIASDOUT(D_PARAM_PARSECMDL,"shortopt with "
1137  <<(char)short_or_index<<" : "<<it->first);
1138  break;
1139  }
1140  }
1141  // if optarg ==NUL, user specified a bool switch and no argument
1142  // or argument is not connected with '=', so fake argument
1143  const char* optparam;
1144  if (optarg != NULL) {
1145  //optarg="true";
1146  optparam = optarg;
1147  } else {
1148  optparam ="true";
1149  }
1150 
1151  // this calls the method from the correct class to insert into
1152  // (late binding magic)
1153  it->second->SetFromString(optparam);
1154  } // else if (short_or_index == -1)
1155  } //while ()
1156  /// this delete let the program bail out. but it realy should be deleted
1157  delete[] longopts;
1158 
1159  //// check for readconfigXML and readconfig
1160  if (bReadConfig){
1161 #ifdef BIAS_HAVE_XML2
1162  if ( (*(readPrj = GetParamString("readconfigXML")))!="" ){
1163  //cout <<"Reading configuration from XML-file: "<<*readPrj<<endl;
1164  BIASDOUT(D_PARAM_CONF_FILE, "Reading configuration from XML-file: "
1165  <<*readPrj<<endl);
1166  if (ReadParameterXML(*readPrj)<0) return -1;
1167  // second parse to let cmdl override config file
1168  else bParse=true;
1169  } else
1170 #endif
1171  if ( (*(readPrj = GetParamString("readconfig")))!="" ){
1172  //cout <<"Reading configuration from file: "<<*readPrj<<endl;
1173  BIASDOUT(D_PARAM_CONF_FILE, "Reading configuration from file: "
1174  <<*readPrj<<endl);
1175  if (ReadParameter(*readPrj)<0) return -1;
1176  // second parse to let cmdl override config file
1177  else bParse=true;
1178  } else {
1179  bParse=false;
1180  BIASDOUT(D_PARAM_CONF_FILE, "no configuration file given\n");
1181  }
1182  bReadConfig=false;
1183  } else {
1184  bParse=false;
1185  }
1186  } // end while bParse
1187 
1188  string *writePrj;
1189 
1190  // now eventually write config
1191  if (*(writePrj=GetParamString("writeconfig")) != "") {
1192  string s = *writePrj;
1193  SetParamString("writeconfig",(string)"");
1194  bool *expert=GetParamBool("expert");
1195  SetWriteOptions(WriteIndent_,WriteComments_,WriteEnhanced_ || *expert);
1196  WriteParameter(s);
1197  WriteFlagSet_ = true;
1198  }
1199 
1200 #ifdef BIAS_HAVE_XML2
1201  // now eventually write config to XML-file
1202  if (*(writePrj=GetParamString("writeconfigXML")) != "") {
1203  string s = *writePrj;
1204  SetParamString("writeconfigXML",(string)"");
1205  bool *expert=GetParamBool("expert");
1206  SetWriteOptions(WriteIndent_,WriteComments_,WriteEnhanced_ || *expert);
1207  WriteParameterXML(s);
1208  WriteFlagSet_ = true;
1209  }
1210 #endif
1211 
1212 
1213  delete[] shortoptstring;
1214  return optind;
1215 }//////////////// End of ParseCommandLine()
1216 
1217 
1218 #define READPARAM_CHECKDUPES
1219 int Param::ReadParameter(const string &filename)
1220 {
1221  setlocale(LC_ALL, "C");
1222 
1223  ifstream ifs;
1224  string typestr;
1225  string namestr;
1226  string assignstr;
1227  string valstr;
1228  char commentstr[1000];
1229  CI it; // const iterator for our ParamMap_
1230  int line = 0;
1231 
1232 #ifdef READPARAM_CHECKDUPES
1233  map<string,bool> *ExistingNames = new map<string,bool>;
1234  string current;
1235 #endif
1236 
1237 
1238  ifs.open(filename.c_str());
1239  if (!ifs) {
1240  BIASERR("error reading parameter file: "<<filename);
1241  ifs.close();
1242  return -1;
1243  }
1244  while (ifs) {
1245 
1246  line++;
1247 
1248  // try read one word, may be type or comment sign
1249  ifs >> namestr;
1250  if (namestr[0] == '#') {
1251  ifs.getline(commentstr,sizeof(commentstr),'\n');
1252  BIASDOUT(D_PARAM_IO,"Comment read: "<<namestr<<commentstr);
1253 
1254  }
1255  else {
1256  ifs >> assignstr >>valstr ;
1257  // detect strings with whitespace and read them
1258  if (valstr[0] == '"' && valstr[valstr.length()-1] != '"') {
1259  char c = 0;
1260  while ( c != '\"') {
1261  ifs.read(&c,1);
1262  valstr.append(1,c);
1263  }
1264  }
1265 
1266  ifs >> typestr;
1267  if (ifs) {
1268  // cout <<"read: "<<typestr<<" "<<namestr<<" "<<assignstr<<" "<<valstr
1269  // <<endl;
1270 #ifdef READPARAM_CHECKDUPES
1271  current = (string)namestr;
1272  //cout << "checking line " << line << " name "<<current<<endl;
1273  if ( ExistingNames->find(current) != ExistingNames->end() ){
1274  BIASERR("Oops! Found duplicate parameter '" << current
1275  << "' in line " << line << " of file '" << filename
1276  << "' ");
1277  ifs.close();
1278  return -2;
1279  }
1280  else{
1281  pair<string, bool> NewPair(current,true);
1282  ExistingNames->insert(ExistingNames->end(), NewPair );
1283  };
1284 
1285 #endif
1286  // remove double-quotes where necessary
1287  if (valstr[0] == '"' && valstr[valstr.length()-1] == '"') {
1288  valstr = valstr.substr(1,valstr.length()-2);
1289  }
1290  // cout <<"read: "<<typestr<<" "<<namestr<<" "<<assignstr<<" "<<valstr
1291  // <<endl;
1292 
1293  if ( (it=ParamMap_.find(namestr))==ParamMap_.end() ){
1294  BIASERR("Unknown parameter \""<<namestr
1295  <<"\" in file "<<filename<<" line: "<<line);
1296  // ShowData();
1297  } else {
1298  // this calls the method from the correct class to insert
1299  // to (late binding magic)
1300  it->second->SetFromString(valstr);
1301  BIASDOUT(D_PARAM_IO, filename<<" parameter: "<<namestr
1302  <<" type: "<<typestr << " valstr: "<<valstr);
1303  BIASDOUT(D_PARAM_IO, filename<<" parameter: "<<namestr
1304  <<" value after SetFromString(): "
1305  <<it->second->GetValueString());
1306  } // if (item == NULL) else {
1307  } // if(ifs)
1308  } // if (comment) else {
1309  } // While (ifs)
1310  ifs.close();
1311 
1312 #ifdef READPARAM_CHECKDUPES
1313  delete ExistingNames;
1314 #endif
1315  return 0;
1316 }
1317 
1318 #ifdef BIAS_HAVE_XML2
1319 
1320 int Param::ReadParameterXML(const string &filename)
1321 {
1322  // Tree for XML-file...
1323  XMLIO tree;
1324  // vector for SubGroup nodes
1325  vector<xmlNodePtr> subgroups;
1326  // namestring for params
1327  string paramname;
1328  string attribType;
1329 
1330  // read XML-file
1331  xmlNodePtr root = tree.read(filename);
1332 
1333  // if not successful
1334  if (root == NULL){
1335  // exit with error -1
1336  BIASERR("Error reading XML-file: " << filename << endl);
1337  return -1;
1338  }
1339 
1340  xmlNodePtr parent = root;
1341  xmlNodePtr child = tree.getFirstChild(parent);
1342 
1343  // for all child-nodes...
1344  bool done=false;
1345  while (!done)
1346  {
1347  // if child is a groupnode...
1348  if ((tree.getAttributeName(tree.getFirstAttribute(child)) == "SubGroup")||
1349  (tree.getAttributeName(tree.getFirstAttribute(child)) == "GroupID")) {
1350  // ...remind the node for descend...
1351  subgroups.push_back(child);
1352  } else {
1353  // ...else get type of param, ...
1354  xmlAttrPtr attrib = tree.getFirstAttribute(child);
1355  while (tree.getAttributeName(attrib) != "Type") {
1356  attrib = tree.getNextAttribute();
1357  }
1358  attribType = tree.getAttributeValueString(attrib);
1359 
1360  // ...get parametername...
1361  attrib = tree.getFirstAttribute(child);
1362  while (tree.getAttributeName(attrib) != "Name") {
1363  attrib = tree.getNextAttribute();
1364  }
1365  paramname = tree.getAttributeValueString(attrib);
1366 
1367  // ... save value...
1368  attrib = tree.getFirstAttribute(child);
1369  while (tree.getAttributeName(attrib) != "Value") {
1370  attrib = tree.getNextAttribute();
1371  }
1372  if (attribType == "STRING") {
1373  SetParamString(paramname, tree.getAttributeValueString(attrib));
1374  } else if (attribType == "INT") {
1375  SetParamInt(paramname, tree.getAttributeValueInt(attrib));
1376  } else if (attribType == "DOUBLE"){
1377  SetParamDouble(paramname, tree.getAttributeValueDouble(attrib));
1378  } else if (attribType == "BOOL"){
1379  SetParamBool(paramname, tree.getAttributeValueBool(attrib));
1380  } else if (attribType == "VECDBL"){
1381  SetParamVecDbl(paramname,
1382  (Vector<double>)(tree.getAttributeValueVecDbl(attrib)));
1383  } else if (attribType == "VECINT"){
1384  SetParamVecInt(paramname,
1385  (Vector<int>)(tree.getAttributeValueVecInt(attrib)));
1386  } else if (attribType == "ENUM"){
1387  SetParamEnum(paramname, tree.getAttributeValueString(attrib));
1388  } else {
1389  BIASERR("Unknown parametertype: " << attribType << endl);
1390  return -1;
1391  }
1392 
1393  //... and set enhanced flag for param
1394  attrib = tree.getFirstAttribute(child);
1395  while (tree.getAttributeName(attrib) != "Enhanced") {
1396  attrib = tree.getNextAttribute();
1397  }
1398  SetEnhancedFlag(paramname, tree.getAttributeValueBool(attrib));
1399  }
1400 
1401  child = tree.getNextChild();
1402  if ((child == NULL)&&(subgroups.size()>0)) {
1403  // if all childs done but at least one subgroup left --> descend
1404  parent = subgroups[subgroups.size()-1];
1405  subgroups.pop_back();
1406  child = tree.getFirstChild(parent);
1407  } else
1408  // if all childs done and no subgroups left --> end
1409  if ((child == NULL)&&(subgroups.size()==0)) {
1410  done=true;
1411  break;
1412  }
1413 
1414  }
1415 
1416  return 0;
1417 }
1418 
1419 #endif
1420 
1422 {
1423  vector<int> gv=UniqueSortedGroups();
1424  if (gv.size()==0){
1425  return 0;
1426  }
1427  return (*(gv.rbegin()))+1;
1428 }
1429 
1430 int Param::GetGroupID(const string &name)
1431 {
1432  CI it = ParamMap_.find(name);
1433  if (it != ParamMap_.end()){
1434  return it->second->Group_;
1435  }
1436  BIASERR("no parameter with name "<<name);
1437  return GRP_ALL;
1438 }
1439 
1441 {
1442  for (unsigned int i=0;i<GroupNames_.size();i++)
1443  if (GroupNames_[i] == name) return i;
1444  return GRP_ALL;
1445 }
1446 
1447 
1448 int Param::SetGroupName(const int id, const string& name)
1449 {
1450  int res=0;
1451  vector<int> ids=UniqueSortedGroups();
1452  if (find(ids.begin(), ids.end(), id)==ids.end()){
1453  // BIASERR("unused group id "<<id);
1454  res=-1;
1455  } else {
1456  if (((*ids.rbegin())+1)>(int)GroupNames_.size()){
1457  GroupNames_.resize((*ids.rbegin())+1, "");
1458  }
1459  if(id<(int)GroupNames_.size())
1460  GroupNames_[id]=name;
1461  }
1462  return res;
1463 }
1464 
1465 std::string Param::GetGroupName(const int group_id)
1466 {
1467  if (group_id==GRP_ALL){
1468  return "all";
1469  }
1470  if (group_id==GRP_NOSHOW){
1471  return "no show";
1472  }
1473  if (group_id>(int)(GroupNames_.size())-1 || group_id<0){
1474  BIASERR("invalid group id or no name given. "
1475  "group_id="<<group_id<<"GroupNames_.size()="<<GroupNames_.size())
1476  BIASBREAK;
1477  return "";
1478  }
1479  return GroupNames_[group_id];
1480 }
1481 
1482 
1484 {
1485  vector<int> res;
1486  CI it;
1487  for (it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1488  if (it->second->WriteToFile_) res.push_back(it->second->Group_);
1489  }
1490  sort(res.begin(), res.end());
1491  vector<int>::iterator end = unique(res.begin(), res.end());
1492  res.erase(end, res.end());
1493  return res;
1494 }
1495 
1496 bool Param::IsUsedGroupID(const int group_id)
1497 {
1498  vector<int> ids=UniqueSortedGroups();
1499  return (find(ids.begin(), ids.end(), group_id)!=ids.end());
1500 }
1501 
1503 {
1504  unsigned length=0;
1505  // search for longest name
1506  unsigned i=0;
1507  for (CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1508  if (it->second->Name_.size()>length &&
1509  !it->second->Enhanced_ && !it->second->Hidden_)
1510  length=it->second->Name_.size();
1511  i++;
1512  }
1513  return (int)length;
1514 }
1515 
1517 {
1518  unsigned length=0;
1519  // search for longest name
1520  for (CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1521  if (it->second->GetValueString().size()>length &&
1522  !it->second->Enhanced_ && !it->second->Hidden_)
1523  length=it->second->GetValueString().size();
1524  }
1525  return (int)length;
1526 }
1527 
1528 
1529 
1530 
1531 int Param::WriteParameter(const string &filename)
1532 {
1533  ofstream ofs;
1534  // search for longest name to set namew
1535  int namew=GetSizeOfLongestParamName()+2, typew=12;
1536  int valuew=GetSizeOfLongestParamValueString()+2;
1537  if (WriteIndent_) {
1538  namew=(namew<20)?(20):namew;
1539  valuew=(valuew<7)?(7):valuew;
1540  }
1541  else {
1542  namew = 0;
1543  valuew = 0;
1544  }
1545  ofs.open(filename.c_str());
1546  if ( !ofs.is_open() )
1547  BIASERR( "File '" << filename << "' not opened!" << endl);
1548 
1549  ostringstream oss;
1550  vector<int> grps=UniqueSortedGroups();
1551  vector<int>::iterator git;
1552  for (git=grps.begin(); git!=grps.end(); git++){
1553  // dont write empty group headers into the parameter file:
1554  bool ThisGroupInUse = false;
1555  for ( CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1556  if (it->second->WriteToFile_ && it->second->Group_ == *git
1557  && (WriteEnhanced_ || (!(*it).second->Enhanced_)) &&
1558  (!(*it).second->Hidden_)) {
1559  ThisGroupInUse = true;
1560  break;
1561  }
1562  }
1563  if (!ThisGroupInUse) continue;
1564 
1565  // this group will have at least one entry, write headline
1566  ofs <<"\n############### Group ID "<<*git<<" : "<<GetGroupName(*git)
1567  <<" #######################\n";
1568 
1569  // now write the group members
1570  for ( CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1571  if (it->second->WriteToFile_ && it->second->Group_ == *git
1572  && (WriteEnhanced_ || (!(*it).second->Enhanced_)) &&
1573  (!(*it).second->Hidden_))
1574  {
1575  oss.str("");
1576  if (WriteComments_)
1577  // first, write name with comment
1578  ofs <<endl<<"# "<<it->second->Name_<<": "<<it->second->GetHint()
1579  <<endl<<"# "<<it->second->Help_<<endl;
1580  // second write name = value
1581  oss <<setw(namew)<<it->first<<" = "
1582  <<setw(valuew)<<left<<it->second->GetValueString()<<right
1583  <<" " ;
1584  while (oss.str().size() <40) oss<<" ";
1585  ofs <<oss.str();
1586  oss.str("");
1587  // third write type name
1588  oss << "PARAM_"<<it->second->GetTypeName();
1589  ofs << setw(typew) << oss.str()<< endl;
1590  }
1591  }
1592  }
1593  ofs.close();
1594  return 0;
1595 }
1596 
1597 #ifdef BIAS_HAVE_XML2
1598 
1599 int Param::WriteParameterXML(const string &filename)
1600 {
1601  // Tree for XML-file...
1602  XMLIO tree;
1603  // ...create base-node
1604  xmlNodePtr root = tree.create("XMLParamfile");
1605  tree.addAttribute(root, "Version", 0.1);
1606 
1607  stringstream tempString;
1608 
1609  vector<int> grps=UniqueSortedGroups();
1610  vector<int>::iterator git;
1611  for (git=grps.begin(); git!=grps.end(); git++){
1612  // dont write empty group headers into the parameter file:
1613  bool ThisGroupInUse = false;
1614  for ( CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1615  if (it->second->WriteToFile_ && it->second->Group_ == *git
1616  && (WriteEnhanced_ || (!(*it).second->Enhanced_)) &&
1617  (!(*it).second->Hidden_)) {
1618  ThisGroupInUse = true;
1619  break;
1620  }
1621  }
1622  if (!ThisGroupInUse) continue;
1623 
1624  // this group will have at least one entry, create group-node...
1625  // ... but first erase blanks in group-name and add ID
1626  {
1627  const char *groupName = (GetGroupName(*git)).c_str();
1628  int i=0;
1629  tempString << "Group_" << *git << "_";
1630  while (groupName[i] != 0) {
1631  if (groupName[i] == ' ') {
1632  tempString << '_';
1633  } else {
1634  tempString << groupName[i];
1635  }
1636  i++;
1637  }
1638  }
1639 
1640  xmlNodePtr groupNode = tree.addChildNode(root, tempString.str());
1641  if (groupNode == NULL) {
1642  BIASERR("Error creating group: " + tempString.str() +
1643  " / " + GetGroupName(*git));
1644  return -1;
1645  }
1646  tempString.str("");
1647  tree.addAttribute(groupNode, "GroupID", *git);
1648 
1649  // now create the group's member-nodes
1650  for ( CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++){
1651  if (it->second->WriteToFile_ && it->second->Group_ == *git
1652  && (WriteEnhanced_ || (!(*it).second->Enhanced_)) &&
1653  (!(*it).second->Hidden_))
1654  {
1655 
1656  xmlNodePtr lastNode = groupNode;
1657  std::string name = it->first;
1658  std::string::size_type lastFound = std::string::npos;
1659  std::string::size_type found = name.rfind('-');
1660  int depth = 1;
1661  while (found != string::npos){
1662  tempString << name.substr(found+1, lastFound-found);
1663  lastFound = found-1;
1664 
1665  xmlNodePtr temp = tree.getChild(lastNode, tempString.str());
1666  if (temp == NULL){
1667  lastNode = tree.addChildNode(lastNode, tempString.str());
1668  if (lastNode == NULL){
1669  BIASERR("Error creating SubGroup: " + tempString.str() +
1670  " / " + name);
1671  return -1;
1672  }
1673  tree.addAttribute(lastNode, "SubGroup", depth);
1674  } else {
1675  lastNode = temp;
1676  }
1677 
1678  tempString.str("");
1679  found = name.rfind('-',lastFound);
1680  depth++;
1681  }
1682  if (lastFound == std::string::npos) {
1683  tempString << name;
1684  } else {
1685  tempString << name.substr(0,lastFound+1);
1686  }
1687 
1688  lastNode = tree.addChildNode(lastNode, tempString.str());
1689  if (lastNode == NULL){
1690  BIASERR("Error creating param: " + tempString.str() +
1691  " / " + name);
1692  return -1;
1693  }
1694  tempString.str("");
1695 
1696  //first: set comments if desired
1697  if (WriteComments_) {
1698  tree.addComment(lastNode, it->second->Help_);
1699  }
1700 
1701  //second: set name and value(s)
1702  if (it->second->GetTypeName() == "BOOL") {
1703  tree.addAttribute(lastNode, "Value",
1704  ((ParamTypeBool*) it->second)->value_);
1705  tree.addAttribute(lastNode, "Default",
1706  ((ParamTypeBool*) it->second)->default_);
1707  tree.addAttribute(lastNode, "Name", it->second->Name_);
1708  } else if (it->second->GetTypeName() == "INT") {
1709  tree.addAttribute(lastNode, "Value",
1710  ((ParamTypeInt*) it->second)->value_);
1711  tree.addAttribute(lastNode, "Range", it->second->GetHint());
1712  tree.addAttribute(lastNode, "Default",
1713  ((ParamTypeInt*) it->second)->default_);
1714  tree.addAttribute(lastNode, "Name", it->second->Name_);
1715  } else if (it->second->GetTypeName() == "DOUBLE") {
1716  tree.addAttribute(lastNode, "Value",
1717  ((ParamTypeDouble*) it->second)->value_);
1718  tree.addAttribute(lastNode, "Range", it->second->GetHint());
1719  tree.addAttribute(lastNode, "Default",
1720  ((ParamTypeDouble*) it->second)->default_);
1721  tree.addAttribute(lastNode, "Name", it->second->Name_);
1722  } else if (it->second->GetTypeName() == "STRING") {
1723  tree.addAttribute(lastNode, "Value",
1724  ((ParamTypeString*) it->second)->value_);
1725  tree.addAttribute(lastNode, "Default",
1726  ((ParamTypeString*) it->second)->default_);
1727  tree.addAttribute(lastNode, "Name", it->second->Name_);
1728  } else if (it->second->GetTypeName() == "VECDBL") {
1729  tree.addAttribute(lastNode, "Value",
1730  ((ParamTypeVecDbl*) it->second)->value_.GetSTLVec());
1731  tree.addAttribute(lastNode, "Default",
1732  ((ParamTypeVecDbl*) it->second)->default_.GetSTLVec());
1733  tree.addAttribute(lastNode, "Name", it->second->Name_);
1734  } else if (it->second->GetTypeName() == "VECINT") {
1735  tree.addAttribute(lastNode, "Value",
1736  ((ParamTypeVecInt*) it->second)->value_.GetSTLVec());
1737  tree.addAttribute(lastNode, "Default",
1738  ((ParamTypeVecInt*) it->second)->default_.GetSTLVec());
1739  tree.addAttribute(lastNode, "Name", it->second->Name_);
1740  } else if (it->second->GetTypeName() == "ENUM") {
1741  tree.addAttribute(lastNode, "Value",
1742  ((ParamTypeEnum*) it->second)->GetValueString());
1743  tree.addAttribute(lastNode, "Range", it->second->GetHint());
1744  tree.addAttribute(lastNode, "Name", it->second->Name_);
1745  } else {
1746  BIASERR("!!! No matching ParamType for attribute:"
1747  + it->second->GetTypeName() + " !!!");
1748  return -1;
1749  }
1750 
1751  //third: set type
1752  tree.addAttribute(lastNode, "Type", it->second->GetTypeName());
1753  //fourth: set enhanced or not enh.
1754  tree.addAttribute(lastNode, "Enhanced", it->second->Enhanced_);
1755  }
1756  }
1757  }
1758 
1759  // if XML-file has been written...
1760  if (tree.write(filename) == 0){
1761  // ...clear tree and exit ...
1762  tree.clear();
1763  return 0;
1764  }
1765 
1766  // else exit with error -1
1767  BIASERR("\nCould not write parameterfile:\n " + filename + "\n");
1768  return -1;
1769 }
1770 
1771 #endif
1772 
1773 int Param::WriteRunMe(const std::string &filename)
1774 {
1775  ofstream ofs;
1776  time_t now_s;
1777  struct tm* now;
1778  char datestr[20];
1779  string fname;
1780 
1781  time(&now_s);
1782  now = localtime(&now_s);//, &now);
1783  sprintf(datestr,"%4d-%02d-%02d-%02d:%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday,
1784  now->tm_hour,now->tm_min);
1785 
1786  fname = filename + datestr;
1787  ofs.open(fname.c_str());
1788 
1789  if (!ofs){
1790  perror(fname.c_str());
1791  return -1;
1792  }
1793  ofs <<"#!/bin/sh"<<endl<<endl;
1794  for (unsigned int i=0;i<ArgV_.size(); i++)
1795  ofs <<ArgV_[i]<<" ";
1796  ofs<<endl<<endl;
1797  ofs.close();
1798 #ifndef WIN32
1799  chmod(filename.c_str(),0755);
1800 #endif //WIN32
1801  return 0;
1802 }
1803 
1804 
1805 
1807 {
1808  for (CI it=ParamMap_.begin(); it!=ParamMap_.end(); it++)
1809  it->second->SetDefault();
1810 }
1811 
1812 
1813 int Param::RegisterCallbackObject(const string &name,
1815 {
1816  CI it;
1817  if ( (it=ParamMap_.find(name)) != ParamMap_.end()) {
1818  it->second->CallbackObject_ = obj;
1819  return 0;
1820  }
1821  BIASERR("Unknown parameter \""<<name<<"\"in RegisterCallbackObject()");
1822  return -1;
1823 }
1824 
1825 int Param::SetRangeInt(const std::string &name,const int min, const int max)
1826 {
1827  CI it;
1828  if ( (it=ParamMap_.find(name)) != ParamMap_.end()) {
1829  ParamTypeInt *pInt = dynamic_cast<ParamTypeInt *>(it->second);
1830  if (pInt != NULL) {
1831  pInt->min_ = min;
1832  pInt->max_ = max;
1833  }
1834  return 0;
1835  }
1836  BIASERR("Unknown parameter \""<<name<<"\"in RegisterCallbackObject()");
1837  return -1;
1838 }
1839 
1840 
1841 int Param::SetShortCommand(const string &name, const char cmd)
1842 {
1843  CI it = ParamMap_.find(name);
1844  if ( it==ParamMap_.end() ){
1845  BIASERR("parameter "<<name<<" not found!");
1846  return -1;
1847  }
1848  else
1849  it->second->ShortCmd_ = cmd;
1850  return 0;
1851 }
1852 
1853 int Param::ParseListFile(const std::string& ListFileName,
1854  std::vector<std::string>& LinesInFile)
1855 {
1856  ifstream ifs(ListFileName.c_str());
1857  if(!ifs) {
1858  BIASERR("stream to list file "<<ListFileName<<" could not be established");
1859  ifs.close();
1860  return -1;
1861  }
1862 
1863  stringstream sstr;
1864  sstr.str("");
1865 
1866  do {
1867  ifs.get(*(sstr.rdbuf()));//stream symbols til EOL or EOF(excludes EOL/EOF)
1868  if(sstr.str().size()>0) {
1869  LinesInFile.push_back(sstr.str());
1870  } else {
1871 #ifdef BIAS_DEBUG
1872  // cout<<"empty string\n";
1873 #endif
1874  }
1875  sstr.clear();
1876  sstr.str("");
1877  } while(ifs.get()!=EOF);
1878 
1879  ifs.close();
1880  return 0;
1881 }
1882 
1883 // accessors because of protected-> private member to avoid DLL export JW
1884 std::map<const std::string,BIAS::ParamTypeBase*> &
1886 {
1887  return ParamMap_;
1888 }
1889 
1890 const std::map<const std::string,BIAS::ParamTypeBase*> &
1892 {
1893  return ParamMap_;
1894 }
1895 
1896 /**
1897  * \brief empties internal datastructures
1898  */
1900  ParamMap_.clear();
1901 }
1902 
1903 
int * SetParamInt(const std::string &name, const int &value)
Definition: Param.cpp:729
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
Definition: XMLIO.cpp:156
std::string getAttributeName(const xmlAttrPtr Attribute) const
Get the name of a given Attribute.
Definition: XMLIO.cpp:690
double * GetParamDouble(const std::string &name) const
Definition: Param.cpp:665
BIAS::Vector< int > * SetParamVecInt(const std::string &name, const BIAS::Vector< int > &value)
Definition: Param.cpp:860
virtual int SetRangeInt(const std::string &name, const int min, const int max)
Set [Min,Max] as new range, especially usefull in derived class PramGUI
Definition: Param.cpp:1825
xmlNodePtr getNextChild()
Get the next child of the parent specified in the last getFirstChild() call, the class remembers the ...
Definition: XMLIO.cpp:466
bool WriteToFile_
is only written to parameter file if true
Definition: ParamTypes.hh:75
int write(const std::string &Filename, bool AutoAddCompressionSuffix=true) const
Write the whole tree that was constructed in memory to disk.
Definition: XMLIO.cpp:379
int RegisterCallbackObject(const std::string &name, ParamCallbackInterface *obj)
Definition: Param.cpp:1813
int SetHiddenFlag(const std::string &name, bool hidden)
if a parametr is marked as hidden, it is obsolete and hidden for all users, use this for parameters o...
Definition: Param.cpp:970
int UpdateParameter(int &argc, char *argv[], const std::string &default_filename)
update all arguments from command line and parameter file
Definition: Param.cpp:985
xmlNodePtr read(const std::string &Filename)
Read and parse an XML file from disk, DtD validation is not yet implemented.
Definition: XMLIO.cpp:416
std::string * GetParamStringByIndex(const int i) const
Get a Param-value by Index.
Definition: Param.cpp:597
int SetParameterWriteToFile(const std::string &name, bool writeToFile)
Definition: Param.cpp:944
void addComment(const xmlNodePtr Node, const std::string &Comment)
Add comment to a node.
Definition: XMLIO.cpp:309
double * GetParamDoubleByIndex(const int i) const
Get a Param-value by Index.
Definition: Param.cpp:555
int GetSizeOfLongestParamName()
returns the size of the longest param name not marked as enhanced or hidden
Definition: Param.cpp:1502
std::vector< int > UniqueSortedGroups()
Returns a vector of all group IDs (unique) in ascending order.
Definition: Param.cpp:1483
BIAS::Vector< int > value_
Definition: ParamTypes.hh:301
xmlNodePtr getChild(const xmlNodePtr ParentNode, const std::string &ChildName)
Get a child of a Parent node by specifying the childs name, NULL is returned if the ParentNode has no...
Definition: XMLIO.cpp:489
Param(bool DisableDestructorWarning=false)
Definition: Param.cpp:74
void ClearAllParams()
empties internal datastructures
Definition: Param.cpp:1899
xmlNodePtr create(const std::string &RootNodeName)
Create the base of a new XML-Tree in memory, already with a one and only root node.
Definition: XMLIO.cpp:88
virtual void ParameterChanged(const std::string &paramname, const void *data)
Definition: Param.cpp:68
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
int ReadParameter(const std::string &filename)
read values for parameters from file
Definition: Param.cpp:1219
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
Definition: Param.cpp:468
std::map< std::string, int > Map_
Definition: ParamTypes.hh:349
bool getAttributeValueBool(const xmlAttrPtr Attribute) const
Get the value of a given Attribute, with type-cast overloads for different attribute types...
Definition: XMLIO.cpp:700
int * GetParamEnum(const std::string &name) const
Definition: Param.cpp:712
xmlAttrPtr getFirstAttribute(const xmlNodePtr Node)
Get the first attribute of a given parent, or NULL for no attributes.
Definition: XMLIO.cpp:624
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
double * SetParamDouble(const std::string &name, const double &value)
Definition: Param.cpp:802
bool * GetParamBool(const std::string &name) const
Definition: Param.cpp:633
std::vector< double > getAttributeValueVecDbl(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:747
BIAS::Vector< double > * SetParamVecDbl(const std::string &name, const BIAS::Vector< double > &value)
Definition: Param.cpp:830
std::string getAttributeValueString(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:716
int getAttributeValueInt(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:728
Vector< T > & newsize(Subscript N)
Definition: vec.h:220
std::string * SetParamString(const std::string &name, const std::string &value)
Definition: Param.cpp:779
int * SetParamEnum(const std::string &name, const int &value)
set the enum to the ID &#39;value&#39;
Definition: Param.cpp:917
bool IsUsedGroupID(const int group_id)
returns if the group id is used
Definition: Param.cpp:1496
This class provides an interface to be called if parameter changes occured.
Definition: Param.hh:74
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
Definition: Param.cpp:176
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
int GetGroupIDForGroupName(const std::string &name)
Definition: Param.cpp:1440
void SetDefaults()
sets all entries to their initially (AddParam) given default values
Definition: Param.cpp:1806
BIAS::Vector< int > * GetParamVecInt(const std::string &name) const
Definition: Param.cpp:696
std::string default_
Definition: ParamTypes.hh:229
std::string Name_
Definition: ParamTypes.hh:69
bool CheckParam(const std::string &name)
Check if parameter has already been added.
Definition: Param.cpp:527
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
Definition: XMLIO.cpp:131
std::string * GetParamString(const std::string &name) const
Definition: Param.cpp:649
BIAS::Vector< int > * AddParamVecInt(const std::string &name, const std::string &help, const BIAS::Vector< int > &deflt, char cmdshort=0, int Group=GRP_NOSHOW)
Add a parameter that expects a string on command line like &quot;&lt;value0&gt; &lt;value1&gt; &lt;value2&gt; ...
Definition: Param.cpp:423
std::string Help_
Definition: ParamTypes.hh:73
BIAS::Vector< double > * GetParamVecDbl(const std::string &name) const
Definition: Param.cpp:680
int SetShortCommand(const std::string &name, const char cmd)
Add a short commandline switch to an existing parameter.
Definition: Param.cpp:1841
int WriteParameter(const std::string &filename)
store complete set of parameter in file if write_comments is set, alo the help strings are written to...
Definition: Param.cpp:1531
BIAS::Vector< int > default_
Definition: ParamTypes.hh:302
const char * name
Definition: getopt_W32.h:68
int * GetParamInt(const std::string &name) const
Definition: Param.cpp:618
int GetFreeGroupID()
returns unused group id
Definition: Param.cpp:1421
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
Definition: XMLIO.cpp:452
static int ParseListFile(const std::string &ListFileName, std::vector< std::string > &LinesInFile)
Extracts lines from passed file.
Definition: Param.cpp:1853
bool * SetParamBool(const std::string &name, const bool &value)
Definition: Param.cpp:757
BIAS::Vector< double > * AddParamVecDbl(const std::string &name, const std::string &help, const BIAS::Vector< double > &deflt, char cmdshort=0, int Group=GRP_NOSHOW)
Add a parameter that expects a string on command line like &quot;&lt;value0&gt; &lt;value1&gt; &lt;value2&gt; ...
Definition: Param.cpp:378
BIAS::Vector< double > default_
Definition: ParamTypes.hh:255
xmlAttrPtr getNextAttribute()
Get the next attribute of the parent specified in the last getFirstAttribute() call, the class remembers the last returned attribute.
Definition: XMLIO.cpp:638
bool * GetParamBoolByIndex(const int i) const
Get a Param-value by Index.
Definition: Param.cpp:576
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
Definition: Param.cpp:1448
double getAttributeValueDouble(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:736
std::map< const std::string, BIAS::ParamTypeBase * > & GetParamMap()
Definition: Param.cpp:1885
void clear()
Definition: XMLIO.cpp:74
BIAS::Vector< double > value_
Definition: ParamTypes.hh:254
virtual ~ParamCallbackInterface()
Definition: Param.cpp:61
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
void ShowData(std::ostream &os=std::cout, int grp=GRP_ALL, bool showenhanced=true)
print all data in group grp including current values to os if grp = GRP_ALL, print all values if show...
Definition: Param.cpp:121
int * GetParamIntByIndex(const int i) const
Get a Param-value by Index.
Definition: Param.cpp:534
int ReadParameterXML(const std::string &filename)
read values for parameters from xml-file
Definition: Param.cpp:1320
int SetEnhancedFlag(const std::string &name, bool enhanced)
if a parametr is marked as enhanced, it is hidden from the naive user
Definition: Param.cpp:957
std::string GetGroupName(const int group_id)
gets the name of a group
Definition: Param.cpp:1465
int WriteParameterXML(const std::string &filename)
Definition: Param.cpp:1599
virtual ~Param()
Definition: Param.cpp:107
std::vector< int > getAttributeValueVecInt(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:761
int has_arg
Definition: getopt_W32.h:73
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
int GetGroupID(const std::string &name)
returns group id of parameter with name
Definition: Param.cpp:1430
int GetSizeOfLongestParamValueString()
returns the size of the longest param value string not marked as enhanced or hidden ...
Definition: Param.cpp:1516
int WriteRunMe(const std::string &filename)
writes complete command line including program name and unknown command line options, no defaults, no params read from file
Definition: Param.cpp:1773