C++ main module for gpm Package  1.0
GPM_Variable.h
Go to the documentation of this file.
1 #ifndef GPM_Variable_H
2 #define GPM_Variable_H
3 
4 #include "GPM_Object.h"
5 
6 
7 
8 
16 class GPM_Variable : public GPM_Object{
17  SP_OBJECT(GPM_Variable);
18  // ATTRIBUTES
19 
20 public:
21 
22  static const tFlag UNDEFINED;
23  static const tFlag REAL;
24  static const tFlag BOOLEAN;
25  static const tFlag INTEGER;
26  static const tFlag STRING;
27  static const tFlag SINGLE;
28  static const tFlag MULTIPLE;
29 private:
30 
31  tFlag mType;
32  double *mValues;
33  int mCardinality;
34  tBoolean mIsGlobal;
35 
36 
37 protected:
38  // METHODS
39 
40  // CONSTRUCTORS
41 
43  GPM_Variable(void);
44 
45 
46 
47  // DESTRUCTORS
48 
49 
52  virtual ~GPM_Variable(void);
53 
54 
55 public:
56 
57  // NEW methods
58 
59  inline static SP::GPM_Variable New() {
60  SP::GPM_Variable p(new GPM_Variable(),GPM_Variable::Delete());
61  p->setThis(p);
62  return p;
63  }
64 
65  //operator
66  const double& operator[](const int& i) const {
67  ASSERT_IN(i<mCardinality);
68  return mValues[i];
69  }
70  double& operator[](const int& i) {
71  ASSERT_IN(i<mCardinality);
72  return mValues[i];
73  }
74 
75  // SET & GET methods
76 
79  virtual void copy(const GPM_Variable& var);
82  virtual void copy(SPC::GPM_Variable var) {
83  if (var.get()!=null) copy(*var.get());
84  else {
85  resize(0);
86  }
87  }
88 
91  inline void setCardinality(const int& n) {
92  resize(n);
93  }
96  inline void setType(const tFlag& t) {
97  mType=t;
98  }
101  inline void setIsGlobal(const tBoolean& t) {
102  mIsGlobal=t;
103  }
106  void setValue(const int& cardinality,const double* values,const tFlag& type);
107 
110  void setValue(const tString& value) {
111  int l=value.size();
112  resize(l);
113  for (int i=0;i<l;i++) mValues[i]=(double) value[i];
114  mType=STRING;
115  }
118  void setValue(const int& n,const double* value) {
119  setValue(n,value,REAL);
120  }
123  void setValue(const double& value) {
124  setValue(1,&value,REAL);
125  }
126 
127 
128 
129  // GET
130 
133  inline int getCardinality() const {
134  return mCardinality;
135  }
138  inline tFlag getType() const {
139  return mType;
140  }
143  inline tBoolean isGlobal() const {
144  return mIsGlobal;
145  }
146 
147 
150  inline void getValue(tString& values) const {
151  values.resize(mCardinality);
152  for (int i=0;i<mCardinality;i++) values[i]=(char) mValues[i];
153  }
156  inline void getValue(int& n,double* values) const {
157  n=(n<mCardinality)?n:mCardinality;
158  for (int i=0;i<n;i++) values[i]=mValues[i];
159  }
162  inline double getValue() const {
163  if (mCardinality==0) return 0;
164  return mValues[0];
165  }
166 
167 
168  // = TEST
171  inline tBoolean isEqual(const GPM_Variable& var) const {
172  return isEqual(var,1.e-12);
173  }
176  tBoolean isEqual(const GPM_Variable& var,const double& eps) const;
177 
180  tBoolean isEqual(const GPM_Variable* var) const {
181  if (var==null) return false;
182  return isEqual(*var);
183  }
186  tBoolean isEqual(const SPC::GPM_Variable var) const {
187  if (var.get()==null) return false;
188  return isEqual(*var.get());
189  }
190 
191  // PARSING methods
192 
195  void parse(const tString& value);
198  virtual tString toString() const;
199 
200 private:
201  void resize(const int& n);
202  void desallocate();
203 };
204 
205 #endif
static const tFlag SINGLE
Definition: GPM_Variable.h:27
virtual ~GPM_Variable(void)
destroy an object.
Definition: GPM_Variable.cpp:22
tBoolean isEqual(const GPM_Variable *var) const
return tre if the 2 variables are equal
Definition: GPM_Variable.h:180
void setType(const tFlag &t)
set the type of the variable
Definition: GPM_Variable.h:96
void setValue(const double &value)
set the variable
Definition: GPM_Variable.h:123
DEFINE_SVPTR(GPM_Variable)
double getValue() const
get the variable value
Definition: GPM_Variable.h:162
tBoolean isGlobal() const
return true if the vraibale is global
Definition: GPM_Variable.h:143
tBoolean isEqual(const GPM_Variable &var) const
return true if the 2 variables are equal
Definition: GPM_Variable.h:171
virtual void copy(SPC::GPM_Variable var)
copy the vraiable
Definition: GPM_Variable.h:82
static SP::GPM_Variable New()
Definition: GPM_Variable.h:59
#define tBoolean
Definition: types.h:35
int getCardinality() const
get the cardinality
Definition: GPM_Variable.h:133
#define null
Definition: types.h:13
double & operator[](const int &i)
Definition: GPM_Variable.h:70
static const tFlag MULTIPLE
Definition: GPM_Variable.h:28
void getValue(tString &values) const
get the variable value
Definition: GPM_Variable.h:150
tFlag getType() const
Definition: GPM_Variable.h:138
void setValue(const int &cardinality, const double *values, const tFlag &type)
set the variable
Definition: GPM_Variable.cpp:74
void parse(const tString &value)
parse the string : reverse method of toString
Definition: GPM_Variable.cpp:85
void setCardinality(const int &n)
set the cardinalty of the variable
Definition: GPM_Variable.h:91
static const tFlag STRING
Definition: GPM_Variable.h:26
static const tFlag REAL
Definition: GPM_Variable.h:23
This class describes a node.
Definition: GPM_Variable.h:16
void setValue(const int &n, const double *value)
set the variable
Definition: GPM_Variable.h:118
tBoolean isEqual(const SPC::GPM_Variable var) const
return tre if the 2 variables are equal
Definition: GPM_Variable.h:186
void setValue(const tString &value)
set the variable
Definition: GPM_Variable.h:110
virtual tString toString() const
to string
Definition: GPM_Variable.cpp:181
void getValue(int &n, double *values) const
get the variable value
Definition: GPM_Variable.h:156
static const tFlag BOOLEAN
Definition: GPM_Variable.h:24
#define tString
Definition: types.h:36
const double & operator[](const int &i) const
Definition: GPM_Variable.h:66
DEFINE_SPTR(GPM_Variable)
GPM_Variable(void)
create an object
Definition: GPM_Variable.cpp:13
This class is the base class of all graph classes.
Definition: GPM_Object.h:17
static const tFlag UNDEFINED
Definition: GPM_Variable.h:22
virtual void copy(const GPM_Variable &var)
copy the vraiable
Definition: GPM_Variable.cpp:53
#define ASSERT_IN(a)
Definition: types.h:82
static const tFlag INTEGER
Definition: GPM_Variable.h:25
void setIsGlobal(const tBoolean &t)
set if the variable is global
Definition: GPM_Variable.h:101
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14