File: Synonym.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 (75 lines) | stat: -rw-r--r-- 2,169 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
// Store synonym name/value
#if !defined(_grisynonym_h_)
#define  _grisynonym_h_
#include "GCounter.hh"
class GriSynonym : public GriCounter
{
public:
    GriSynonym() {
	name = new char [1];	if (!name)  OUT_OF_MEMORY;
	name[0] = '\0';
	value = new char [1];	if (!value) OUT_OF_MEMORY;
	value[0] = '\0';
    }
    GriSynonym(const char *the_name, const char *the_value) {
	name = new char [1 + strlen(the_name)];	  if (!name)  OUT_OF_MEMORY;
	strcpy(name, the_name);
	value = new char [1 + strlen(the_value)]; if (!value) OUT_OF_MEMORY;
	strcpy(value, the_value);
    }
    GriSynonym(const GriSynonym& c) {
	name = new char [1 + strlen(c.getName())];
	if (!name) OUT_OF_MEMORY;
	strcpy(name, c.getName());
	value = new char [1 + strlen(c.get_value_quietly())];
	if (!value) OUT_OF_MEMORY;
	strcpy(value, c.get_value_quietly());
    }
    ~GriSynonym() {delete [] name; delete [] value;}
    void setNameValue(const char *the_name, const char *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);
	if (strlen(the_value) > strlen(value)) {
	    delete [] value;
	    value = new char [1 + strlen(the_value)];
	    if (!value) OUT_OF_MEMORY;
	}
	strcpy(value, the_value);
    }
    void setValue(const char *the_value) {
	if (strlen(the_value) > strlen(value)) {
	    delete [] value;
	    value = new char[1 + strlen(the_value)];
	    if (!value) OUT_OF_MEMORY;
	}
	strcpy(value, the_value);
    }
    char *getName(void) const		{return name;};
    char *getValue(void)  	      {incrementCount(); return value;};
    char *get_value_quietly(void) const {return value;};
    GriSynonym& operator=(const GriSynonym& 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);
	cp = n.get_value_quietly();
	if (strlen(cp) > strlen(value)) {
	    delete [] value;
	    value = new char [1 + strlen(cp)];
	    if (!value) OUT_OF_MEMORY;
	}
	strcpy(value, cp);
	return *this;
    }
private:
    char *name;
    char *value;
};
#endif