MINT2
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
MINT::NamedParameterBase Class Referenceabstract

#include <NamedParameterBase.h>

Inheritance diagram for MINT::NamedParameterBase:
MINT::INamedParameter MINT::FitParameter MINT::NamedParameter< T > MINT::NamedParameter< double > MINT::NamedParameter< int > MINT::NamedParameter< std::string >

Public Types

enum  VERBOSITY { VERBOSE =0, QUIET =1 }
 

Public Member Functions

bool setPPF (ParsedParameterFile *ppF_in=0)
 
bool read ()
 
bool read (std::istream &is)
 
bool read (const std::string &fname)
 
bool reloadFile (const std::string &id)
 
bool setFromInitString (const std::string &str)
 
bool setFromInitStringNoName (const std::string &str_in)
 
 NamedParameterBase (const std::string &name_in="", const char *fname=0, VERBOSITY=VERBOSE)
 
 NamedParameterBase (const NamedParameterBase &other)
 
virtual ~NamedParameterBase ()
 
virtual const std::string & name () const
 
void quiet (bool beSo=true)
 
bool gotInitialised () const
 
- Public Member Functions inherited from MINT::INamedParameter
virtual ~INamedParameter ()
 

Static Public Member Functions

static bool setDefaultInputFile (const std::string &fname)
 
static bool setDefaultInputStream (std::istream &str=std::cin)
 

Protected Member Functions

virtual bool setFromParsedLine (const ParsedParameterLine &line)=0
 
virtual bool setFromParsedFile ()
 
- Protected Member Functions inherited from MINT::INamedParameter
 INamedParameter ()
 

Static Protected Member Functions

static ParsedParameterFileListgetFlist ()
 

Protected Attributes

std::string _name
 
ParsedParameterFile_ppF
 
bool _gotInitialised
 
bool _quiet
 

Static Protected Attributes

static bool IveSaidItOnce =0
 
static std::string _defaultFile = ""
 
static std::istream * _defaultStreamPtr = &std::cin
 

Friends

std::stringstream & operator>> (std::stringstream &is, MINT::NamedParameterBase &npb)
 

Detailed Description

Definition at line 29 of file NamedParameterBase.h.

Member Enumeration Documentation

◆ VERBOSITY

Enumerator
VERBOSE 
QUIET 

Definition at line 46 of file NamedParameterBase.h.

Constructor & Destructor Documentation

◆ NamedParameterBase() [1/2]

NamedParameterBase::NamedParameterBase ( const std::string &  name_in = "",
const char *  fname = 0,
NamedParameterBase::VERBOSITY  vb = VERBOSE 
)

Definition at line 40 of file NamedParameterBase.cpp.

44  : INamedParameter()
45  , _name(name_in)
46  , _gotInitialised(false)
48 {
51  _name));
52  if(0 == fname){
53  if((! _quiet) && 0 == IveSaidItOnce){
54  IveSaidItOnce=true;
55  cout << "INFO in constructor of NamedParameterBase:"
56  << "\n > For parameter named: \"" << _name << "\""
57  << "\n > You did not provide a filename."
58  << "\n > I'll read from stdin. This is completely OK,"
59  << "\n > but if there is no input from stdin ending in EOF,"
60  << "\n > the program will stall after this message."
61  << "\n > If you find yourself in this situation, press Ctr-d."
62  << "\n > In future, run the program as ./program < inputFile.txt"
63  << "\n > even if inputFile.txt is just an empty dummy file."
64  << "\n > This message is only printed once."
65  << endl;
66  }
68  }else{
70  }
71 }
static std::string removeTrailingBlanks(const std::string &s)
static std::string removeLeadingBlanks(const std::string &s)

◆ NamedParameterBase() [2/2]

NamedParameterBase::NamedParameterBase ( const NamedParameterBase other)

Definition at line 72 of file NamedParameterBase.cpp.

◆ ~NamedParameterBase()

NamedParameterBase::~NamedParameterBase ( )
virtual

Definition at line 80 of file NamedParameterBase.cpp.

80  {
81  if( (! _gotInitialised) && (! _quiet)){
82  cout << "WARNING in destructor of NamedParameterBase:"
83  << "\n > Hello. My name is \"" << _name << "\"."
84  << "\n > I'm being destroyed, and"
85  << "\n > I never even got initialised."
86  << "\n > Did you do that deliberatly?"
87  << endl;
88  }
89 }

Member Function Documentation

◆ getFlist()

ParsedParameterFileList * NamedParameterBase::getFlist ( )
staticprotected

Definition at line 91 of file NamedParameterBase.cpp.

91  {
93 }
static ParsedParameterFileList * getMe()

◆ gotInitialised()

bool MINT::NamedParameterBase::gotInitialised ( ) const
inline

Definition at line 72 of file NamedParameterBase.h.

◆ name()

virtual const std::string& MINT::NamedParameterBase::name ( ) const
inlinevirtual

Implements MINT::INamedParameter.

Reimplemented in MINT::FitParameter.

Definition at line 67 of file NamedParameterBase.h.

67  {
68  return _name;
69  }

◆ quiet()

void MINT::NamedParameterBase::quiet ( bool  beSo = true)
inline

Definition at line 71 of file NamedParameterBase.h.

◆ read() [1/3]

bool NamedParameterBase::read ( )

Definition at line 102 of file NamedParameterBase.cpp.

102  {
103  if(! ("" == _defaultFile)) return read(_defaultFile);
104  else return read(*_defaultStreamPtr);
105 }
static std::istream * _defaultStreamPtr
static std::string _defaultFile

◆ read() [2/3]

bool NamedParameterBase::read ( std::istream &  is)

Definition at line 106 of file NamedParameterBase.cpp.

106  {
107  _ppF = getFlist()->getParsedFile(is);
108  if(0 == _ppF){
109  cout << "SERIOUS ERROR IN NamedParameterBase::read(std::istream& is)"
110  << "\n > call to ParsedParameterFileList::getParsedFile"
111  << "\n > return 0 pointer. This is bad. Let's see how long"
112  << "\n > I'll last..." << endl;
113  return false;
114  }
115  return true;
116 }
ParsedParameterFile * _ppF
static ParsedParameterFileList * getFlist()
ParsedParameterFile * getParsedFile(const std::string &fname)

◆ read() [3/3]

bool NamedParameterBase::read ( const std::string &  fname)

Definition at line 118 of file NamedParameterBase.cpp.

118  {
119  _ppF = getFlist()->getParsedFile(fname);
120  if(0 == _ppF){
121  cout << "SERIOUS ERROR IN NamedParameterBase::read(const std::string&)"
122  << "\n > with string value = " << fname << "."
123  << "\n > Call to ParsedParameterFileList::getParsedFile"
124  << "\n > return 0 pointer. This is bad. Let's see how long"
125  << "\n > I'll last..." << endl;
126  return false;
127  }
128  return true;
129 }
ParsedParameterFile * _ppF
static ParsedParameterFileList * getFlist()
ParsedParameterFile * getParsedFile(const std::string &fname)

◆ reloadFile()

bool NamedParameterBase::reloadFile ( const std::string &  id)

Definition at line 32 of file NamedParameterBase.cpp.

32  {
33  bool success = true;
34  success |= (bool) getFlist()->reloadFile(id);
35  success |= read(id);
36  success |= setFromParsedFile();
37  return success;
38 }
static ParsedParameterFileList * getFlist()
ParsedParameterFile * reloadFile(const std::string &id)

◆ setDefaultInputFile()

bool NamedParameterBase::setDefaultInputFile ( const std::string &  fname)
static

Definition at line 19 of file NamedParameterBase.cpp.

19  {
20  _defaultFile = fname;
21  return true;
22 }
static std::string _defaultFile

◆ setDefaultInputStream()

bool NamedParameterBase::setDefaultInputStream ( std::istream &  str = std::cin)
static

Definition at line 24 of file NamedParameterBase.cpp.

24  {
25  _defaultFile="";
26  _defaultStreamPtr = &str;
27  return true;
28 }
static std::istream * _defaultStreamPtr
static std::string _defaultFile

◆ setFromInitString()

bool NamedParameterBase::setFromInitString ( const std::string &  str)

Definition at line 154 of file NamedParameterBase.cpp.

154  {
155  ParsedParameterLine ppl(str);
156  return this->setFromParsedLine(ppl);
157 }
virtual bool setFromParsedLine(const ParsedParameterLine &line)=0

◆ setFromInitStringNoName()

bool NamedParameterBase::setFromInitStringNoName ( const std::string &  str_in)

Definition at line 158 of file NamedParameterBase.cpp.

158  {
159  std::string str = name() + "\t" + str_in;
160  ParsedParameterLine ppl(str);
161  return this->setFromParsedLine(ppl);
162 }
virtual const std::string & name() const
virtual bool setFromParsedLine(const ParsedParameterLine &line)=0

◆ setFromParsedFile()

bool NamedParameterBase::setFromParsedFile ( )
protectedvirtual

Definition at line 131 of file NamedParameterBase.cpp.

131  {
132  bool success=false;
133  if(0 == _ppF){
134  if((! _gotInitialised) && (! _quiet)){
135  cout << "WARNING in NamedParameterBase::setFromParsedFile():"
136  << "\n No ParsedParameterFile attached!." << endl;
137  }
138  return false;
139  }
140  const ParsedParameterLine& ppL =_ppF->find(name());
141  if(! ppL.isValid()){
142  /*if(! _quiet){
143  cout << "WARNING in NamedParameterBase::setFromParsedFile():"
144  << "\n > Can't find variable with name \"" << name() << "\""
145  << "\n > in attached ParsedParameterFile." << endl;
146  }*/
147  }else{
148  success = setFromParsedLine(ppL);
149  }
150  if(success) _gotInitialised = true;
151  return success;
152 }
virtual const std::string & name() const
ParsedParameterFile * _ppF
virtual bool setFromParsedLine(const ParsedParameterLine &line)=0
const ParsedParameterLine & find(const std::string &name) const

◆ setFromParsedLine()

virtual bool MINT::NamedParameterBase::setFromParsedLine ( const ParsedParameterLine line)
protectedpure virtual

◆ setPPF()

bool NamedParameterBase::setPPF ( ParsedParameterFile ppF_in = 0)

Definition at line 95 of file NamedParameterBase.cpp.

95  {
96  // if(0 != _ppF) delete _ppF;
97  // above now managed by ParsedParameterFileList
98  _ppF = ppF_in;
99  return true;
100 }
ParsedParameterFile * _ppF

Friends And Related Function Documentation

◆ operator>>

std::stringstream& operator>> ( std::stringstream &  is,
MINT::NamedParameterBase npb 
)
friend

Definition at line 164 of file NamedParameterBase.cpp.

165  {
166  std::string str;
167  is >> str;
168  npb.setFromInitStringNoName(str);
169  return is;
170 }
bool setFromInitStringNoName(const std::string &str_in)

Member Data Documentation

◆ _defaultFile

std::string NamedParameterBase::_defaultFile = ""
staticprotected

Definition at line 36 of file NamedParameterBase.h.

◆ _defaultStreamPtr

std::istream * NamedParameterBase::_defaultStreamPtr = &std::cin
staticprotected

Definition at line 37 of file NamedParameterBase.h.

◆ _gotInitialised

bool MINT::NamedParameterBase::_gotInitialised
protected

Definition at line 41 of file NamedParameterBase.h.

◆ _name

std::string MINT::NamedParameterBase::_name
protected

Definition at line 32 of file NamedParameterBase.h.

◆ _ppF

ParsedParameterFile* MINT::NamedParameterBase::_ppF
protected

Definition at line 34 of file NamedParameterBase.h.

◆ _quiet

bool MINT::NamedParameterBase::_quiet
protected

Definition at line 43 of file NamedParameterBase.h.

◆ IveSaidItOnce

bool NamedParameterBase::IveSaidItOnce =0
staticprotected

Definition at line 31 of file NamedParameterBase.h.


The documentation for this class was generated from the following files: