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

- File List
- File Members

# /home/coin/svn-release/Blis-0.93.2/Alps/src/AlpsParameterBase.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Abstract Library for Parallel Search (ALPS).     *
    00003  *                                                                           *
    00004  * ALPS is distributed under the Eclipse Public License as part of the       *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors:                                                                  *
    00008  *                                                                           *
    00009  *          Yan Xu, Lehigh University                                        *
    00010  *          Ted Ralphs, Lehigh University                                    *
    00011  *                                                                           *
    00012  * Conceptual Design:                                                        *
    00013  *                                                                           *
    00014  *          Yan Xu, Lehigh University                                        *
    00015  *          Ted Ralphs, Lehigh University                                    *
    00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00017  *          Matthew Saltzman, Clemson University                             *
    00018  *                                                                           *
    00019  *                                                                           *
    00020  * Copyright (C) 2001-2011, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00021  *===========================================================================*/
    00022
    00023 #ifndef AlpsParameters_h
    00024 #define AlpsParameters_h
    00025
    00026 //----------------------------------------------------------
    00027 // AlpsParameterBase.h is modified from BCP_parameters.hpp
    00028 //----------------------------------------------------------
    00029
    00030 #include <algorithm>
    00031 #include <cctype>
    00032 #include <cstdio>
    00033 #include <fstream>
    00034 #include <iostream>
    00035 #include <string>
    00036 #include <utility>          // for 'pair'
    00037 #include <vector>
    00038
    00039 #include "CoinError.hpp"
    00040
    00041 #if defined(__GNUC__) && (__GNUC__ >= 3)
    00042 #    include <sstream>
    00043 #    include <locale>
    00044 #    define ALPS_STRINGSTREAM std::istringstream
    00045 #else
    00046 #    include <strstream>
    00047 #    include <cctype>
    00048 #    define ALPS_STRINGSTREAM std::istrstream
    00049 #endif
    00050
    00051 class AlpsEncoded;
    00052
    00053 //##############################################################################
    00054
    00056 enum AlpsParameterT{
    00059     AlpsNoPar,
    00061     AlpsBoolPar,
    00063     AlpsIntPar,
    00065     AlpsDoublePar,
    00067     AlpsStringPar,
    00070     AlpsStringArrayPar
    00071 };
    00072
    00073 //##############################################################################
    00074
    00077 class AlpsParameter {
    00078
    00079  private:
    00083     AlpsParameterT type_;
    00085     int index_;
    00088  public:
    00089     // default copy constructor and assignment operator are fine
    00093     AlpsParameter() : type_(AlpsNoPar), index_(0) {}
    00095     AlpsParameter(const AlpsParameterT t, const int i) :
    00096         type_(t), index_(i) {}
    00098     ~AlpsParameter() {}
    00104     AlpsParameterT type() const { return type_; }
    00107     int index() const            { return index_; }
    00109 };
    00110
    00111 //##############################################################################
    00112
    00134 class AlpsParameterSet {
    00135  protected:
    00140     std::vector< std::pair<std::string, AlpsParameter> > keys_;
    00141
    00144     std::vector<std::string> obsoleteKeys_;
    00145
    00147     bool*                bpar_;
    00148
    00150     int*                 ipar_;
    00151
    00153     double*              dpar_;
    00154
    00156     std::string*          spar_;
    00157
    00159     int numSa_;
    00160     std::vector<std::string>* sapar_;
    00161
    00163   //---------------------------------------------------------------------------
    00164
    00165  public:
    00172     virtual void createKeywordList() = 0;
    00173
    00175     virtual void setDefaultEntries() = 0;
    00182     virtual void pack(AlpsEncoded& buf) {
    00183         throw CoinError("can't call pack()", "pack", " AlpsParameterSet");
    00184     }
    00185
    00187     virtual void unpack(AlpsEncoded& buf){
    00188         throw CoinError("can't call unpack()", "unpack", " AlpsParameterSet");
    00189     }
    00191
    00192     //---------------------------------------------------------------------------
    00193
    00194  public:
    00195
    00204     // This the one used in readFromStream()
    00205     void setEntry(const AlpsParameter key, const char * val) {
    00206         switch (key.type()){
    00207         case AlpsNoPar: break;
    00208         case AlpsBoolPar:        bpar_ [key.index()] = atoi(val) ? true : false;    break;
    00209         case AlpsIntPar:         ipar_ [key.index()] = atoi(val);    break;
    00210         case AlpsDoublePar:      dpar_ [key.index()] = atof(val);    break;
    00211         case AlpsStringPar:      spar_ [key.index()] = val;          break;
    00212         case AlpsStringArrayPar: sapar_[key.index()].push_back(val); break;
    00213         }
    00214     }
    00215
    00229     void readFromStream(std::istream& parstream);
    00230
    00232     void readFromFile(const char * paramfile);
    00233
    00235     void readFromArglist(const int argnum, const char * const * arglist);
    00236
    00240     void writeToStream(std::ostream& outstream) const;
    00241
    00243     AlpsParameterSet(int c, int i, int d, int s, int sa) :
    00244         keys_(),
    00245         bpar_(new bool[c]),
    00246         ipar_(new int[i]),
    00247         dpar_(new double[d]),
    00248         spar_(new std::string[s]),
    00249         sapar_(new std::vector<std::string>[sa])
    00250         {}
    00251
    00253     virtual ~AlpsParameterSet() {
    00254         keys_.clear();
    00255         obsoleteKeys_.clear();
    00256         delete[] bpar_; bpar_ = 0;
    00257         delete[] ipar_; ipar_ = 0;
    00258         delete[] dpar_; dpar_ = 0;
    00259         delete[] spar_; spar_ = 0;
    00260         delete[] sapar_; sapar_ = 0;
    00261     }
    00262 };
    00263
    00264 #endif