1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * RpVariable.cc |
---|
4 | * |
---|
5 | * Rappture 2.0 Variable member functions |
---|
6 | * |
---|
7 | * ====================================================================== |
---|
8 | * AUTHOR: Derrick Kearney, Purdue University |
---|
9 | * Copyright (c) 2005-2009 Purdue Research Foundation |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | |
---|
16 | #include <cstring> |
---|
17 | #include <stdlib.h> |
---|
18 | #include "RpVariable.h" |
---|
19 | #include "RpHashHelper.h" |
---|
20 | |
---|
21 | RpVariable::RpVariable() |
---|
22 | { |
---|
23 | __init(); |
---|
24 | } |
---|
25 | |
---|
26 | RpVariable::RpVariable(const RpVariable& o) |
---|
27 | : |
---|
28 | _path (o._path) |
---|
29 | { |
---|
30 | if (o._h != NULL) { |
---|
31 | Rp_HashCopy(_h,o._h,charCpyFxn); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | RpVariable::~RpVariable() |
---|
36 | { |
---|
37 | __close(); |
---|
38 | } |
---|
39 | |
---|
40 | const char * |
---|
41 | RpVariable::label( |
---|
42 | const char *val) |
---|
43 | { |
---|
44 | return (const char *) property("label",val); |
---|
45 | } |
---|
46 | |
---|
47 | const char * |
---|
48 | RpVariable::desc( |
---|
49 | const char *val) |
---|
50 | { |
---|
51 | return (const char *) property("desc",val); |
---|
52 | } |
---|
53 | |
---|
54 | const char * |
---|
55 | RpVariable::hints( |
---|
56 | const char *val) |
---|
57 | { |
---|
58 | return (const char *) property("hints",val); |
---|
59 | } |
---|
60 | |
---|
61 | const char * |
---|
62 | RpVariable::color( |
---|
63 | const char *val) |
---|
64 | { |
---|
65 | return (const char *) property("color",val); |
---|
66 | } |
---|
67 | |
---|
68 | const char * |
---|
69 | RpVariable::icon( |
---|
70 | const char *val) |
---|
71 | { |
---|
72 | return (const char *) property("icon",val); |
---|
73 | } |
---|
74 | |
---|
75 | const char * |
---|
76 | RpVariable::path( |
---|
77 | const char *val) |
---|
78 | { |
---|
79 | return (const char *) property("path",val); |
---|
80 | } |
---|
81 | |
---|
82 | const void * |
---|
83 | RpVariable::property( |
---|
84 | const char *key, |
---|
85 | const void *val) |
---|
86 | { |
---|
87 | const void *r = NULL; |
---|
88 | if (_h == NULL) { |
---|
89 | // hash table does not exist, create it |
---|
90 | _h = (Rp_HashTable*) malloc(sizeof(Rp_HashTable)); |
---|
91 | Rp_InitHashTable(_h,RP_STRING_KEYS); |
---|
92 | return NULL; |
---|
93 | } |
---|
94 | |
---|
95 | if (val == NULL) { |
---|
96 | // get the value |
---|
97 | r = Rp_HashSearchNode(_h,key); |
---|
98 | } else { |
---|
99 | //set the value |
---|
100 | Rp_HashRemoveNode(_h,key); |
---|
101 | Rp_HashAddNode(_h,key,val); |
---|
102 | r = val; |
---|
103 | } |
---|
104 | |
---|
105 | return r; |
---|
106 | } |
---|
107 | |
---|
108 | void |
---|
109 | RpVariable::__init() |
---|
110 | { |
---|
111 | _path = NULL; |
---|
112 | _h = NULL; |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | RpVariable::__close() |
---|
117 | { |
---|
118 | if (_path != NULL) { |
---|
119 | free((void *)_path); |
---|
120 | } |
---|
121 | |
---|
122 | if (_h != NULL) { |
---|
123 | Rp_DeleteHashTable(_h); |
---|
124 | } |
---|
125 | |
---|
126 | __init(); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | // -------------------------------------------------------------------- // |
---|
131 | |
---|