- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

AlpsParameterBase.h
Go to the documentation of this file.
1 /*===========================================================================*
2 * This file is part of the Abstract Library for Parallel Search (ALPS). *
3 * *
4 * ALPS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: *
8 * *
9 * Yan Xu, Lehigh University *
10 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * *
20 * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21 *===========================================================================*/
22
23 #ifndef AlpsParameters_h
24 #define AlpsParameters_h
25
26 //----------------------------------------------------------
27 // AlpsParameterBase.h is modified from BCP_parameters.hpp
28 //----------------------------------------------------------
29
30 #include <algorithm>
31 #include <cctype>
32 #include <cstdio>
33 #include <fstream>
34 #include <iostream>
35 #include <string>
36 #include <utility> // for 'pair'
37 #include <vector>
38
39 #include "CoinError.hpp"
40
41 #if defined(__GNUC__) && (__GNUC__ >= 3)
42 # include <sstream>
43 # include <locale>
44 # define ALPS_STRINGSTREAM std::istringstream
45 #else
46 # include <strstream>
47 # include <cctype>
48 # define ALPS_STRINGSTREAM std::istrstream
49 #endif
50
51 class AlpsEncoded;
52
53 //##############################################################################
54
56 enum AlpsParameterT{
59 AlpsNoPar,
61 AlpsBoolPar,
63 AlpsIntPar,
65 AlpsDoublePar,
67 AlpsStringPar,
70 AlpsStringArrayPar
71 };
72
73 //##############################################################################
74
77 class AlpsParameter {
78
79 private:
83 AlpsParameterT type_;
85 int index_;
88 public:
89 // default copy constructor and assignment operator are fine
93 AlpsParameter() : type_(AlpsNoPar), index_(0) {}
95 AlpsParameter(const AlpsParameterT t, const int i) :
96 type_(t), index_(i) {}
98 ~AlpsParameter() {}
104 AlpsParameterT type() const { return type_; }
107 int index() const { return index_; }
109 };
110
111 //##############################################################################
112
134 class AlpsParameterSet {
135 protected:
140 std::vector< std::pair<std::string, AlpsParameter> > keys_;
141
144 std::vector<std::string> obsoleteKeys_;
145
147 bool* bpar_;
148
150 int* ipar_;
151
153 double* dpar_;
154
156 std::string* spar_;
157
159 int numSa_;
160 std::vector<std::string>* sapar_;
161
163 //---------------------------------------------------------------------------
164
165 public:
172 virtual void createKeywordList() = 0;
173
175 virtual void setDefaultEntries() = 0;
182 virtual void pack(AlpsEncoded& buf) {
183 throw CoinError("can't call pack()", "pack", " AlpsParameterSet");
184 }
185
187 virtual void unpack(AlpsEncoded& buf){
188 throw CoinError("can't call unpack()", "unpack", " AlpsParameterSet");
189 }
191
192 //---------------------------------------------------------------------------
193
194 public:
195
204 // This the one used in readFromStream()
205 void setEntry(const AlpsParameter key, const char * val) {
206 switch (key.type()){
207 case AlpsNoPar: break;
208 case AlpsBoolPar: bpar_ [key.index()] = atoi(val) ? true : false; break;
209 case AlpsIntPar: ipar_ [key.index()] = atoi(val); break;
210 case AlpsDoublePar: dpar_ [key.index()] = atof(val); break;
211 case AlpsStringPar: spar_ [key.index()] = val; break;
212 case AlpsStringArrayPar: sapar_[key.index()].push_back(val); break;
213 }
214 }
215
229 void readFromStream(std::istream& parstream);
230
232 void readFromFile(const char * paramfile);
233
235 void readFromArglist(const int argnum, const char * const * arglist);
236
240 void writeToStream(std::ostream& outstream) const;
241
243 AlpsParameterSet(int c, int i, int d, int s, int sa) :
244 keys_(),
245 bpar_(new bool[c]),
246 ipar_(new int[i]),
247 dpar_(new double[d]),
248 spar_(new std::string[s]),
249 sapar_(new std::vector<std::string>[sa])
250 {}
251
253 virtual ~AlpsParameterSet() {
254 keys_.clear();
255 obsoleteKeys_.clear();
256 delete[] bpar_; bpar_ = 0;
257 delete[] ipar_; ipar_ = 0;
258 delete[] dpar_; dpar_ = 0;
259 delete[] spar_; spar_ = 0;
260 delete[] sapar_; sapar_ = 0;
261 }
262 };
263
264 #endif
AlpsParameterSet::unpack
virtual void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
Definition: AlpsParameterBase.h:187
AlpsParameter::AlpsParameter
AlpsParameter()
The default constructor creates a phony parameter.
Definition: AlpsParameterBase.h:93
AlpsParameterSet
This is the class serves as a holder for a set of parameters.
Definition: AlpsParameterBase.h:134
AlpsParameter::type_
AlpsParameterT type_
The type of the parameter (e.g., AlpsIntPar).
Definition: AlpsParameterBase.h:83
AlpsParameterSet::writeToStream
void writeToStream(std::ostream &outstream) const
Write keyword-value pairs to the stream specified in the argument.
CoinError.hpp
AlpsParameter::type
AlpsParameterT type() const
Return the type of the parameter.
Definition: AlpsParameterBase.h:104
AlpsParameterSet::ipar_
int * ipar_
The integer parameters.
Definition: AlpsParameterBase.h:150
AlpsParameterSet::readFromFile
void readFromFile(const char *paramfile)
Read parameters from a file.
AlpsParameterSet::numSa_
int numSa_
The &quot;vector of string&quot; parameters.
Definition: AlpsParameterBase.h:159
AlpsParameter
This parameter indeintifies a single parameter entry.
Definition: AlpsParameterBase.h:77
AlpsParameterSet::createKeywordList
virtual void createKeywordList()=0
Method for creating the list of keyword looked for in the parameter file.
AlpsParameter::index_
int index_
The index of this parameter within all parameters of the same type.
Definition: AlpsParameterBase.h:85
AlpsEncoded
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
AlpsStringPar
String parameter (E.g., data file name.).
Definition: AlpsParameterBase.h:67
AlpsParameterSet::readFromStream
void readFromStream(std::istream &parstream)
Read the parameters from the stream specified in the argument.
AlpsBoolPar
Bool parameter.
Definition: AlpsParameterBase.h:61
AlpsParameterT
AlpsParameterT
This enumerative constant describes the possible parameter types.
Definition: AlpsParameterBase.h:56
AlpsParameterSet::spar_
std::string * spar_
The string (actually, std::string) parameters.
Definition: AlpsParameterBase.h:156
AlpsParameterSet::setDefaultEntries
virtual void setDefaultEntries()=0
Method for setting the default values for the parameters.
AlpsDoublePar
Double parameter.
Definition: AlpsParameterBase.h:65
AlpsParameterSet::keys_
std::vector< std::pair< std::string, AlpsParameter > > keys_
The keyword, parameter pairs.
Definition: AlpsParameterBase.h:140
AlpsParameterSet::readFromArglist
void readFromArglist(const int argnum, const char *const *arglist)
Read parameters from the command line.
AlpsParameterSet::sapar_
std::vector< std::string > * sapar_
The keyword, parameter pairs.
Definition: AlpsParameterBase.h:160
AlpsParameterSet::~AlpsParameterSet
virtual ~AlpsParameterSet()
The destructor deletes all data members.
Definition: AlpsParameterBase.h:253
AlpsParameterSet::setEntry
void setEntry(const AlpsParameter key, const char *val)
First, there is the assignment operator that sets the whole parameter set at once.
Definition: AlpsParameterBase.h:205
AlpsParameterSet::bpar_
bool * bpar_
The bool parameters.
Definition: AlpsParameterBase.h:147
AlpsParameterSet::AlpsParameterSet
AlpsParameterSet(int c, int i, int d, int s, int sa)
The constructor allocate memory for parameters.
Definition: AlpsParameterBase.h:243
AlpsParameterSet::obsoleteKeys_
std::vector< std::string > obsoleteKeys_
list of obsolete keywords.
Definition: AlpsParameterBase.h:144
AlpsParameter::AlpsParameter
AlpsParameter(const AlpsParameterT t, const int i)
Constructor where members are specified.
Definition: AlpsParameterBase.h:95
CoinError
Error Class thrown by an exception.
Definition: CoinError.hpp:42
AlpsIntPar
Integer parameter.
Definition: AlpsParameterBase.h:63
AlpsStringArrayPar
The parameter is an array of strings.
Definition: AlpsParameterBase.h:70
AlpsParameter::~AlpsParameter
~AlpsParameter()
The destructor.
Definition: AlpsParameterBase.h:98
AlpsParameterSet::dpar_
double * dpar_
The double parameters.
Definition: AlpsParameterBase.h:153
AlpsParameterSet::pack
virtual void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer.
Definition: AlpsParameterBase.h:182
AlpsParameter::index
int index() const
Return the index of the parameter within all parameters of the same type.
Definition: AlpsParameterBase.h:107
AlpsNoPar
The type is not yet specified.
Definition: AlpsParameterBase.h:59