Changeset 1270 for trunk/src/objects/RpVariable.cc
- Timestamp:
- Jan 11, 2009, 10:20:06 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/objects/RpVariable.cc
r1018 r1270 7 7 * ====================================================================== 8 8 * AUTHOR: Derrick Kearney, Purdue University 9 * Copyright (c) 200 4-2005Purdue Research Foundation9 * Copyright (c) 2005-2009 Purdue Research Foundation 10 10 * 11 11 * See the file "license.terms" for information on usage and … … 14 14 */ 15 15 16 #include "RpVariable.h" 16 #include <cstring> 17 #include <stdlib.h> 18 #include "RpVariable.h" 19 #include "RpHashHelper.h" 17 20 18 /**********************************************************************/ 19 // METHOD: setPath() 20 /// Set the path of this object 21 /** 22 */ 23 24 RpVariable& 25 RpVariable::setPath(std::string newPath) 21 RpVariable::RpVariable() 26 22 { 27 path = newPath; 28 return *this; 23 __init(); 29 24 } 30 25 31 /**********************************************************************/ 32 // METHOD: setDefaultValue() 33 /// Set the default value of this object 34 /** 35 */ 36 37 RpVariable& 38 RpVariable::setDefaultValue(void* newDefaultVal) 26 RpVariable::RpVariable(const RpVariable& o) 27 : 28 _path (o._path) 39 29 { 40 // who is responsible for freeing the pointer?41 defaultVal = newDefaultVal;42 return *this;30 if (o._h != NULL) { 31 Rp_HashCopy(_h,o._h,charCpyFxn); 32 } 43 33 } 44 34 45 /**********************************************************************/ 46 // METHOD: setCurrentValue() 47 /// Set the current value of this object 48 /** 49 */ 50 51 RpVariable& 52 RpVariable::setCurrentValue(void* newCurrentVal) 35 RpVariable::~RpVariable() 53 36 { 54 // who is responsible for freeing the pointer? 55 currentVal = newCurrentVal; 56 return *this; 37 __close(); 57 38 } 58 39 59 /**********************************************************************/ 60 // METHOD: setLabel() 61 /// Set the label of this object 62 /** 63 */ 64 65 RpVariable& 66 RpVariable::setLabel(std::string newLabel) 40 const char * 41 RpVariable::label( 42 const char *val) 67 43 { 68 about.setLabel(newLabel); 69 return *this; 44 return (const char *) property("label",val); 70 45 } 71 46 72 /**********************************************************************/ 73 // METHOD: setDesc() 74 /// Set the desc of this object 75 /** 76 */ 77 78 RpVariable& 79 RpVariable::setDesc(std::string newDesc) 47 const char * 48 RpVariable::desc( 49 const char *val) 80 50 { 81 about.setDesc(newDesc); 82 return *this; 51 return (const char *) property("desc",val); 83 52 } 84 53 85 /**********************************************************************/ 86 // METHOD: setHints() 87 /// Set the hints of this object 88 /** 89 */ 90 91 RpVariable& 92 RpVariable::setHints(std::string newHints) 54 const char * 55 RpVariable::hints( 56 const char *val) 93 57 { 94 about.setHints(newHints); 95 return *this; 58 return (const char *) property("hints",val); 96 59 } 97 60 98 /**********************************************************************/ 99 // METHOD: setColor() 100 /// Set the color of this object 101 /** 102 */ 103 104 RpVariable& 105 RpVariable::setColor(std::string newColor) 61 const char * 62 RpVariable::color( 63 const char *val) 106 64 { 107 about.setColor(newColor); 108 return *this; 65 return (const char *) property("color",val); 109 66 } 110 67 111 /**********************************************************************/ 112 // METHOD: setIcon() 113 /// Set the icon of this object 114 /** 115 */ 116 117 RpVariable& 118 RpVariable::setIcon(std::string newIcon) 68 const char * 69 RpVariable::icon( 70 const char *val) 119 71 { 120 about.setIcon(newIcon); 121 return *this; 72 return (const char *) property("icon",val); 122 73 } 123 74 124 125 /**********************************************************************/ 126 // METHOD: getPath() 127 /// Report the path of this object 128 /** 129 */ 130 131 std::string 132 RpVariable::getPath() const 75 const char * 76 RpVariable::path( 77 const char *val) 133 78 { 134 return path;79 return (const char *) property("path",val); 135 80 } 136 81 137 /**********************************************************************/ 138 // METHOD: getDefaultValue() 139 /// Report the default value of the object 140 /** 141 */ 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 } 142 94 143 void* 144 RpVariable::getDefaultValue() const 145 { 146 return defaultVal; 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; 147 106 } 148 107 149 /**********************************************************************/ 150 // METHOD: getCurrentValue() 151 /// Report the current value of the object 152 /** 153 */ 154 155 void* 156 RpVariable::getCurrentValue() const 108 void 109 RpVariable::__init() 157 110 { 158 return currentVal; 111 _path = NULL; 112 _h = NULL; 159 113 } 160 114 161 /**********************************************************************/ 162 // METHOD: getLabel() 163 /// Report the label of the object 164 /** 165 */ 115 void 116 RpVariable::__close() 117 { 118 if (_path != NULL) { 119 free((void *)_path); 120 } 166 121 167 std::string 168 RpVariable::getLabel() const 169 { 170 return about.getLabel(); 171 } 122 if (_h != NULL) { 123 Rp_DeleteHashTable(_h); 124 } 172 125 173 /**********************************************************************/ 174 // METHOD: getDesc() 175 /// Report the desc of the object 176 /** 177 */ 178 179 std::string 180 RpVariable::getDesc() const 181 { 182 return about.getDesc(); 183 } 184 185 /**********************************************************************/ 186 // METHOD: getHints() 187 /// Report the hints of this object 188 /** 189 */ 190 191 std::string 192 RpVariable::getHints() const 193 { 194 return about.getHints(); 195 } 196 197 /**********************************************************************/ 198 // METHOD: getColor() 199 /// Report the color of this object 200 /** 201 */ 202 203 std::string 204 RpVariable::getColor() const 205 { 206 return about.getColor(); 207 } 208 209 /**********************************************************************/ 210 // METHOD: getIcon() 211 /// Report the icon of this object 212 /** 213 */ 214 215 std::string 216 RpVariable::getIcon() const 217 { 218 return about.getIcon(); 126 __init(); 219 127 } 220 128
Note: See TracChangeset
for help on using the changeset viewer.