File: variables.hpp

package info (click to toggle)
sip-tester 1%3A3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,152 kB
  • ctags: 1,681
  • sloc: cpp: 15,621; ansic: 2,131; sh: 412; makefile: 147
file content (131 lines) | stat: -rw-r--r-- 3,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Authors : Benjamin GAUTHIER - 24 Mar 2004
 *            Joseph BANINO
 *            Olivier JACQUES
 *            Richard GAYRAUD
 *            From Hewlett Packard Company.
 *           
 */

#ifndef _CVARIABLE
#define _CVARIABLE

#include <sys/types.h>
#include <regex.h>

typedef std::map<std::string, int> str_int_map;
typedef std::map<int, char *> int_str_map;
typedef std::map<int, int> int_int_map;

#define BUFFER_SIZE 512
#define MAX_MATCHING_EXPR 50
#define REGEXP_PARAMS REG_EXTENDED

enum T_VarType
{
  E_VT_REGEXP = 0,
  E_VT_DOUBLE,
  E_VT_BOOL,
  E_VT_STRING,
  E_VT_UNDEFINED
};

class CCallVariable
{
public:
  bool isSet();
  bool isDouble();
  bool isBool();
  bool isRegExp();
  bool isString();

  // WARNING : setMatchingValue does't allocate the memory for the matching value
  // but the destructor free the memory
  void setMatchingValue(char* P_matchingValue);
  char* getMatchingValue();

  /* When the variable is used for a string, these functions should be called. */
  // WARNING : setString does't allocate the memory for the matching value
  // but the destructor free the memory
  void setString(char *s);
  char *getString();

  /* When the variable is used for a double, these functions should be called. */
  void setDouble(double val);
  double getDouble();

  /* When the variable is used for a bool, these functions should be called. */
  void setBool(bool val);
  bool getBool();

  /* Cast this to a double variable, return the result in newValue. */
  bool toDouble(double *newValue);

  // constructor and destructor
  CCallVariable();
  ~CCallVariable();

private:
  T_VarType	M_type;
  char*		M_matchingValue;
  int		M_nbOfMatchingValue;
  double	M_double;
  char*		M_stringValue;
  bool		M_bool;
};

class AllocVariableTable;

class VariableTable
{
public:
	VariableTable(VariableTable *parent, int size);
	VariableTable(AllocVariableTable *src);
	VariableTable *getTable();
	void putTable();
	int size;

	CCallVariable *getVar(int i);
protected:
	virtual ~VariableTable();
	void expand(int size);
	int count;
	int level;
	CCallVariable **variableTable;
	VariableTable *parent;
};

class AllocVariableTable : public VariableTable
{
public:
  AllocVariableTable(AllocVariableTable *av_parent);
  ~AllocVariableTable();
  int find(const char *name, bool allocate);
  char *getName(int i);
  void validate();
private:
  AllocVariableTable *av_parent;
  str_int_map  variableMap;
  int_str_map  variableRevMap;
  int_int_map  variableReferences;
};

void clear_int_str(int_str_map m);
void clear_str_int(str_int_map m);
void clear_int_int(int_int_map m);

#endif