COPASI API  4.16.103
COptions.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/commandline/COptions.h,v $
3  $Revision: 1.13 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2011/03/07 19:26:18 $
7  End CVS Header */
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 /**
24  * COptions class.
25  * The class retrieves the options from the commandline and various files.
26  * The options as well as their type can be retreived by name.
27  *
28  * Created for Copasi by Stefan Hoops 2002
29  */
30 
31 #ifndef COPASI_COptions
32 #define COPASI_COptions
33 
34 #include <string>
35 #include <map>
36 #include <vector>
37 
39 
40 class COptions
41 {
43  {
44  public:
45  typedef void valueType;
46 
47  // Attributes
48  protected:
50 
51  //Operations
52  protected:
54  mpValue(NULL)
56 
57  public:
59 
60  template< class CType > void setValue(const CType & value)
61  {*(CType *) mpValue = value;}
62 
63  template< class CType > void getValue(CType & value) const
64  {
65  if (this && mpValue) value = *(CType *) mpValue;
66  else value = CType();
67  }
68 
69  template< class CType > bool compareValue(CType & value) const
70  {
71  if (this && mpValue) return (value == *(CType *) mpValue);
72  else return false;
73  }
74  };
75 
76  template< class CType > class COptionValueTemplate : public COptionValue
77  {
78  public:
79  typedef CType valueType;
80 
81  //Operations
82  private:
84  COptionValue()
85  {
87  mpValue = new valueType;
88  }
89 
90  public:
92  COptionValue()
93  {
95  mpValue = new valueType;
96  *(valueType *) mpValue = value;
97  }
98 
100  {
101  if (mpValue) {delete(valueType *) mpValue; mpValue = NULL;}
102 
104  }
105  };
106 
107 public:
108  typedef std::map< std::string, COptionValue * > optionType;
109  typedef std::vector< std::string > nonOptionType;
110  typedef std::map< std::string, std::string > defaultType;
111 
112  //Attributes
113 private:
116 
117  //Operations
118 private:
119  COptions();
120 
121 public:
122  ~COptions();
123 
124  template< class CType > static void getValue(const std::string & name,
125  CType & value)
126  {mOptions[name]->getValue(value);}
127 
128  template< class CType > static bool compareValue(const std::string & name,
129  const CType & value)
130  {return mOptions[name]->compareValue(value);}
131 
132  static void init(C_INT argc = 0, char *argv[] = NULL);
133 
134  static void cleanup();
135 
136  static const nonOptionType & getNonOptions();
137 
138  static std::string getEnvironmentVariable(const std::string & name);
139 
140  static std::string getPWD(void);
141 
142 private:
143  template< class CType > static void setValue(const std::string & name,
144  const CType & value)
145  {
146  if (mOptions[name])
147  mOptions[name]->setValue(value);
148  else
149  mOptions[name] = new COptionValueTemplate< CType >(value);
150 
151  return;
152  }
153 
154  static std::string getCopasiDir(void);
155 
156  static std::string getHome(void);
157  static std::string getTemp(void);
158 
159  static std::string getConfigDir(void);
160  static std::string getConfigFile(void);
161 };
162 
163 #endif // COPASI_COptions
static void setValue(const std::string &name, const CType &value)
Definition: COptions.h:143
COptionValueTemplate(const valueType &value)
Definition: COptions.h:91
#define C_INT
Definition: copasi.h:115
void getValue(CType &value) const
Definition: COptions.h:63
COptions()
Definition: COptions.cpp:50
static std::string getCopasiDir(void)
Definition: COptions.cpp:260
static std::string getPWD(void)
Definition: COptions.cpp:338
static std::string getConfigFile(void)
Definition: COptions.cpp:448
bool compareValue(CType &value) const
Definition: COptions.h:69
static void cleanup()
Definition: COptions.cpp:243
static const nonOptionType & getNonOptions()
Definition: COptions.cpp:251
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
static std::string getEnvironmentVariable(const std::string &name)
Definition: COptions.cpp:253
static bool compareValue(const std::string &name, const CType &value)
Definition: COptions.h:128
static optionType mOptions
Definition: COptions.h:114
std::map< std::string, std::string > defaultType
Definition: COptions.h:110
virtual ~COptionValue()
Definition: COptions.h:58
std::map< std::string, COptionValue * > optionType
Definition: COptions.h:108
static std::string getConfigDir(void)
Definition: COptions.cpp:436
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
static nonOptionType mNonOptions
Definition: COptions.h:115
static std::string getHome(void)
Definition: COptions.cpp:365
std::vector< std::string > nonOptionType
Definition: COptions.h:109
~COptions()
Definition: COptions.cpp:53
valueType * mpValue
Definition: COptions.h:49
static std::string getTemp(void)
Definition: COptions.cpp:393
static void init(C_INT argc=0, char *argv[]=NULL)
Definition: COptions.cpp:56
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
void setValue(const CType &value)
Definition: COptions.h:60