-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProperty.h
45 lines (37 loc) · 880 Bytes
/
Property.h
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
#pragma once
enum TMPTYPE {
TMPT_INT,
TMPT_FLOAT,
TMPT_STRING,
};
struct Property {
const TMPTYPE type;
union {
int i;
float f;
char * c;
};
Property(int src) : type(TMPT_INT), i(src) {}
Property(float src) : type(TMPT_FLOAT), f(src) {}
Property(char * src) : type(TMPT_STRING)
{
unsigned length = strlen(src) + 1;
c = new char[length];
memcpy(c, src, length);
}
Property(const Property & src)
: type(src.type), i(src.i) // Will work for float as well, irrelevant for string
{
// Duplicate string
if (type == TMPT_STRING) {
unsigned length = strlen(src.c) + 1;
c = new char[length];
memcpy(c, src.c, length);
}
}
~Property()
{
if (type == TMPT_STRING)
delete[] c;
}
};