BaseRegmas.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2008 by Antonello Lobianco                         *
00003  *   http://regmas.org                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 3 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef BASEREGMASBASEREGMAS_H
00021 #define BASEREGMASBASEREGMAS_H
00022 
00023 #include <iostream>
00024 #include <string>
00025 #include <sstream>
00026 #include <vector>
00027 
00028 // regmas headers...
00029 
00030 class ThreadManager;
00031 
00032 using namespace std;
00033 
00034 enum {
00035 
00036     // DON'T USE NEGATIVE NUMBERS, as often different meaning !
00037     PLOTS_ALL             = 0,
00038     PLOTS_OWNED           = 1,
00039     PLOTS_RENTED          = 2,
00040 
00041     STAGE_INIT            = 0,
00042     STAGE_NORMAL          = 1,
00043 
00044     MSG_NO_MSG            = 0,
00045     MSG_DEBUG             = 1,
00046     MSG_INFO              = 2,
00047     MSG_WARNING           = 3,
00048     MSG_ERROR             = 4,
00049     MSG_CRITICAL_ERROR    = 5,
00050 
00051     RESSOURCE_ZERO         =0,
00052     RESSOURCE_FIXED        =1,
00053     RESSOURCE_CALCULATED   =2,
00054     RESSOURCE_OBJECTS      =3,
00055     RESSOURCE_PIXEL        =4,
00056 
00057     RESTYPE_GENERIC        =0,
00058     RESTYPE_FINANCIAL      =1,
00059     RESTYPE_POLICYPREMIUM  =2,
00060     RESTYPE_LABOUR         =3,
00061     RESTYPE_STABLES        =4,
00062     RESTYPE_MACHINARY      =5,
00063     RESTYPE_FEED           =6,
00064 
00065     TYPE_INT               =0,
00066     TYPE_DOUBLE            =1,
00067     TYPE_STRING            =2,
00068     TYPE_BOOL              =3,
00069 
00070     DATA_INDIVIDUAL        =0,
00071     DATA_VECTOR            =1,
00072     DATA_NOW               =-1, // asking for data (settings) at current time
00073 
00074     OUTVL_NONE             =0, //output verbosity level
00075     OUTVL_MAPS             =3,
00076     OUTVL_AGGREGATED       =3,
00077     OUTVL_DETAILED         =5,
00078     OUTVL_BINMAPS          =6,
00079     OUTVL_ALL              =7,
00080 
00081     AGEXIT_FALSE           =0, //reason why agents leave the model
00082     AGEXIT_NOCAPITAL       =1,
00083     AGEXIT_DEBS            =2,
00084     AGEXIT_SHPRICES        =3
00085 
00086 };
00087 
00088 // mathematical defines (not correctly implemented in some compilers, namely MS VisualStudio..)
00089 
00090 #ifndef M_PI
00091 #define M_PI 3.1415926535897932384626433832795
00092 #endif
00093  
00094 #ifndef M_LN2
00095 #define M_LN2 0.69314718055994530941723212145818
00096 #endif
00097  
00098 #ifndef M_LN10
00099 #define M_LN10 2.3025850929940456840179914546844
00100 #endif
00101 
00103 
00109 class BaseRegmas{
00110 
00111 public:
00112                         BaseRegmas();
00113                        ~BaseRegmas();
00114 
00115     void                msgOut(int msgCode_h, string msg_h, bool refreshGUI_h=true) const; 
00116     void                msgOut(int msgCode_h, int msg_h, bool refreshGUI_h=true) const;    
00117     void                msgOut(int msgCode_h, double msg_h, bool refreshGUI_h=true) const; 
00118 
00119     int                 s2i ( string string_h)         const; 
00120     double              s2d (string string_h)          const; 
00121     bool                s2b (string string_h)          const; 
00122     string              i2s (int int_h)                const; 
00123     string              d2s (double double_h)          const; 
00124     string              b2s (bool bool_h)              const; 
00125     vector<int>         s2i ( vector<string> string_h) const; 
00126     vector<double>      s2d (vector<string> string_h)  const; 
00127     vector<bool>        s2b (vector<string> string_h)  const; 
00128     vector<string>      i2s (vector<int> int_h)        const; 
00129     vector<string>      d2s (vector<double> double_h)  const; 
00130     vector<string>      b2s (vector<bool> bool_h)      const; 
00131 
00136     int                 getType(string &type_h);
00137 
00138     void                refreshGUI() const;  
00139     
00140     //string intToString(int x);
00141     template<typename T> string toString(const T& x);      // string s = toString(x);
00142     template<typename T> T stringTo(const std::string& s); // e.g. int x = stringTo<int>("123");
00143 
00144     int                 iVSum (const vector<int> &intVector_h);       
00145     double              dVSum (const vector<double> &doubleVector_h); 
00146 
00148     void                tokenize(const string& str, vector<string>& tokens, const string& delimiter = " ");
00149 
00150 protected:
00151 
00156     ThreadManager*                       MTHREAD;                       
00157 
00158 private:
00159     void msgOut2(int msgCode_h, string msg_h, bool refreshGUI_h) const; 
00160 
00161 };
00162 
00163 #endif