1 : |
agomez |
1 |
#ifndef addresskeeper_h
|
2 : |
|
|
#define addresskeeper_h
|
3 : |
|
|
|
4 : |
|
|
#include "gadget.h" |
5 : |
|
|
|
6 : |
|
|
/**
|
7 : |
|
|
* \class AddressKeeper
|
8 : |
|
|
* \brief This is the class used to store the name, and memory adddress, of the variables used in the model simulation
|
9 : |
|
|
*/
|
10 : |
|
|
class AddressKeeper {
|
11 : |
|
|
public:
|
12 : |
|
|
/**
|
13 : |
|
|
* \brief This is the default AddressKeeper constructor
|
14 : |
|
|
*/
|
15 : |
|
|
AddressKeeper() { addr = 0; name = 0; };
|
16 : |
|
|
/**
|
17 : |
|
|
* \brief This is the AddressKeeper constructor that creates a copy of an existing AddressKeeper
|
18 : |
|
|
* \param initial is the AddressKeeper to copy
|
19 : |
|
|
*/
|
20 : |
|
|
AddressKeeper(const AddressKeeper& initial)
|
21 : |
|
|
: addr(initial.addr), name(new char[strlen(initial.name) + 1])
|
22 : |
|
|
{ strcpy(name, initial.name); };
|
23 : |
|
|
/**
|
24 : |
|
|
* \brief This is the default AddressKeeper destructor
|
25 : |
|
|
*/
|
26 : |
|
|
~AddressKeeper() {
|
27 : |
|
|
if (name != 0)
|
28 : |
|
|
delete[] name;
|
29 : |
|
|
name = 0;
|
30 : |
|
|
};
|
31 : |
|
|
/**
|
32 : |
|
|
* \brief This operator will set the address of the AddressKeeper equal to an existing address
|
33 : |
|
|
* \param address is the address to copy
|
34 : |
|
|
*/
|
35 : |
|
|
void operator = (double* address) { addr = address; };
|
36 : |
|
|
/**
|
37 : |
|
|
* \brief This operator will set the address of the AddressKeeper equal to an existing vale
|
38 : |
|
|
* \param value is the value to copy
|
39 : |
|
|
*/
|
40 : |
|
|
void operator = (double& value) { addr = &value; };
|
41 : |
|
|
/**
|
42 : |
|
|
* \brief This operator will check to see if the address for the AddressKeeper is equal to an existing address
|
43 : |
|
|
* \param value is the address to check
|
44 : |
|
|
* \return 1 if the two addresses are equal, 0 otherwise
|
45 : |
|
|
*/
|
46 : |
|
|
int operator == (const double& value) { return (addr == &value); };
|
47 : |
|
|
/**
|
48 : |
|
|
* \brief This operator will check to see if the address for the AddressKeeper is equal to an existing address
|
49 : |
|
|
* \param address is the address to check
|
50 : |
|
|
* \return 1 if the two addresses are equal, 0 otherwise
|
51 : |
|
|
*/
|
52 : |
|
|
int operator == (const double* address) { return (addr == address); };
|
53 : |
|
|
/**
|
54 : |
|
|
* \brief This operator will set the name of the AddressKeeper equal to an existing string
|
55 : |
|
|
* \param str is the string to copy
|
56 : |
|
|
*/
|
57 : |
|
|
void operator = (const char* str) {
|
58 : |
|
|
if (name != 0)
|
59 : |
|
|
delete[] name;
|
60 : |
|
|
name = new char[strlen(str) + 1];
|
61 : |
|
|
strcpy(name, str);
|
62 : |
|
|
delete[] str;
|
63 : |
|
|
};
|
64 : |
|
|
/**
|
65 : |
|
|
* \brief This operator will set the AddressKeeper equal to an existing AddressKeeper
|
66 : |
|
|
* \param a is the AddressKeeper to copy
|
67 : |
|
|
*/
|
68 : |
|
|
void operator = (const AddressKeeper a) {
|
69 : |
|
|
if (name != 0)
|
70 : |
|
|
delete[] name;
|
71 : |
|
|
name = new char[strlen(a.name) + 1];
|
72 : |
|
|
strcpy(name, a.name);
|
73 : |
|
|
addr = a.addr;
|
74 : |
|
|
};
|
75 : |
|
|
/**
|
76 : |
|
|
* \brief This will return a null terminated text string containing the name of the stored variable
|
77 : |
|
|
* \return name
|
78 : |
|
|
*/
|
79 : |
|
|
const char* getName() const { return name; };
|
80 : |
|
|
/**
|
81 : |
|
|
* \brief This is the memory address where the value of the variable is stored
|
82 : |
|
|
*/
|
83 : |
|
|
double* addr; //JMB shouldnt this be private??
|
84 : |
|
|
private:
|
85 : |
|
|
/**
|
86 : |
|
|
* \brief This is the null terminated name of the stored variable
|
87 : |
|
|
*/
|
88 : |
|
|
char* name;
|
89 : |
|
|
};
|
90 : |
|
|
|
91 : |
|
|
#endif
|