File: Variable.hh

package info (click to toggle)
gri 2.4.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,540 kB
  • ctags: 1,966
  • sloc: cpp: 32,542; lisp: 3,243; perl: 806; makefile: 548; sh: 253
file content (55 lines) | stat: -rw-r--r-- 1,487 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
// Store variable name/value
#if !defined(_grivariable_h_)
#define  _grivariable_h_
#include "GCounter.hh"
class GriVariable : public GriCounter
{
public:
    GriVariable() {
	name = new char [1];
	if (!name) OUT_OF_MEMORY;
	name[0] = '\0';
	value = 0.0;
    }
    GriVariable(const char *the_name, double the_value) {
	name = new char [1 + strlen(the_name)];
	if (!name) OUT_OF_MEMORY;
	strcpy(name, the_name);
	value = the_value;
    };
    GriVariable(const GriVariable& c) {
	name = new char [1 + strlen(c.getName())];
	if (!name) OUT_OF_MEMORY;
	strcpy(name, c.getName());
	value = c.get_value_quietly();
    };
    ~GriVariable() {delete [] name;};
    void setNameValue(const char *the_name, double the_value) {
	if (strlen(the_name) > strlen(name)) {
	    delete [] name;
	    name = new char [1 + strlen(the_name)];
	    if (!name) OUT_OF_MEMORY;
	}
	strcpy(name, the_name);
	value = the_value;
    };
    void   setValue(double the_value) {value = the_value;};
    char  *getName(void) const        {return name;};
    double getValue(void)            {incrementCount(); return value;};
    double get_value_quietly(void) const {return value;};
    GriVariable& operator=(const GriVariable& n) {
	char *cp = n.getName();
	if (strlen(cp) > strlen(name)) {
	    delete [] name;
	    name = new char [1 + strlen(cp)];
	    if (!name) OUT_OF_MEMORY;
	}
	strcpy(name, cp);
	value = n.get_value_quietly();
	return *this;
    }
private:
    char   *name;
    double  value;
};
#endif