Alps 1.5.7
Loading...
Searching...
No Matches
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-2019, 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
51class AlpsEncoded;
52
53//##############################################################################
54
71};
72
73//##############################################################################
74
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) {}
104 AlpsParameterT type() const { return type_; }
107 int index() const { return index_; }
109};
110
111//##############################################################################
112
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
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
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
AlpsParameterT
This enumerative constant describes the possible parameter types.
@ AlpsStringArrayPar
The parameter is an array of strings.
@ AlpsDoublePar
Double parameter.
@ AlpsNoPar
The type is not yet specified.
@ AlpsStringPar
String parameter (E.g., data file name.).
@ AlpsBoolPar
Bool parameter.
@ AlpsIntPar
Integer parameter.
This data structure is to contain the packed form of an encodable knowledge.
Definition AlpsEncoded.h:25
This is the class serves as a holder for a set of parameters.
std::vector< std::pair< std::string, AlpsParameter > > keys_
The keyword, parameter pairs.
virtual void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer.
std::vector< std::string > * sapar_
void readFromStream(std::istream &parstream)
Read the parameters from the stream specified in the argument.
virtual void createKeywordList()=0
Method for creating the list of keyword looked for in the parameter file.
void setEntry(const AlpsParameter key, const char *val)
First, there is the assignment operator that sets the whole parameter set at once.
int * ipar_
The integer parameters.
std::vector< std::string > obsoleteKeys_
list of obsolete keywords.
virtual ~AlpsParameterSet()
The destructor deletes all data members.
int numSa_
The "vector of string" parameters.
void writeToStream(std::ostream &outstream) const
Write keyword-value pairs to the stream specified in the argument.
AlpsParameterSet(int c, int i, int d, int s, int sa)
The constructor allocate memory for parameters.
virtual void setDefaultEntries()=0
Method for setting the default values for the parameters.
bool * bpar_
The bool parameters.
virtual void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
double * dpar_
The double parameters.
void readFromFile(const char *paramfile)
Read parameters from a file.
void readFromArglist(const int argnum, const char *const *arglist)
Read parameters from the command line.
std::string * spar_
The string (actually, std::string) parameters.
This parameter indeintifies a single parameter entry.
int index() const
Return the index of the parameter within all parameters of the same type.
AlpsParameterT type() const
Return the type of the parameter.
AlpsParameter()
The default constructor creates a phony parameter.
~AlpsParameter()
The destructor.
AlpsParameter(const AlpsParameterT t, const int i)
Constructor where members are specified.