[115] | 1 | /* |
---|
[121] | 2 | * ---------------------------------------------------------------------- |
---|
| 3 | * RpVariable.cc |
---|
| 4 | * |
---|
| 5 | * Rappture 2.0 Variable member functions |
---|
| 6 | * |
---|
[115] | 7 | * ====================================================================== |
---|
[121] | 8 | * AUTHOR: Derrick Kearney, Purdue University |
---|
[1270] | 9 | * Copyright (c) 2005-2009 Purdue Research Foundation |
---|
[115] | 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 | */ |
---|
[37] | 15 | |
---|
[1270] | 16 | #include <cstring> |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | #include "RpVariable.h" |
---|
| 19 | #include "RpHashHelper.h" |
---|
[37] | 20 | |
---|
[1270] | 21 | RpVariable::RpVariable() |
---|
[37] | 22 | { |
---|
[1270] | 23 | __init(); |
---|
[37] | 24 | } |
---|
| 25 | |
---|
[1270] | 26 | RpVariable::RpVariable(const RpVariable& o) |
---|
| 27 | : |
---|
| 28 | _path (o._path) |
---|
[37] | 29 | { |
---|
[1270] | 30 | if (o._h != NULL) { |
---|
| 31 | Rp_HashCopy(_h,o._h,charCpyFxn); |
---|
| 32 | } |
---|
[37] | 33 | } |
---|
| 34 | |
---|
[1270] | 35 | RpVariable::~RpVariable() |
---|
[37] | 36 | { |
---|
[1270] | 37 | __close(); |
---|
[37] | 38 | } |
---|
| 39 | |
---|
[1270] | 40 | const char * |
---|
| 41 | RpVariable::label( |
---|
| 42 | const char *val) |
---|
[37] | 43 | { |
---|
[1270] | 44 | return (const char *) property("label",val); |
---|
[37] | 45 | } |
---|
| 46 | |
---|
[1270] | 47 | const char * |
---|
| 48 | RpVariable::desc( |
---|
| 49 | const char *val) |
---|
[37] | 50 | { |
---|
[1270] | 51 | return (const char *) property("desc",val); |
---|
[37] | 52 | } |
---|
| 53 | |
---|
[1270] | 54 | const char * |
---|
| 55 | RpVariable::hints( |
---|
| 56 | const char *val) |
---|
[37] | 57 | { |
---|
[1270] | 58 | return (const char *) property("hints",val); |
---|
[37] | 59 | } |
---|
| 60 | |
---|
[1270] | 61 | const char * |
---|
| 62 | RpVariable::color( |
---|
| 63 | const char *val) |
---|
[37] | 64 | { |
---|
[1270] | 65 | return (const char *) property("color",val); |
---|
[37] | 66 | } |
---|
| 67 | |
---|
[1270] | 68 | const char * |
---|
| 69 | RpVariable::icon( |
---|
| 70 | const char *val) |
---|
[37] | 71 | { |
---|
[1270] | 72 | return (const char *) property("icon",val); |
---|
[37] | 73 | } |
---|
| 74 | |
---|
[1270] | 75 | const char * |
---|
| 76 | RpVariable::path( |
---|
| 77 | const char *val) |
---|
[37] | 78 | { |
---|
[1270] | 79 | return (const char *) property("path",val); |
---|
[37] | 80 | } |
---|
| 81 | |
---|
[1270] | 82 | const void * |
---|
| 83 | RpVariable::property( |
---|
| 84 | const char *key, |
---|
| 85 | const void *val) |
---|
[37] | 86 | { |
---|
[1270] | 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 | } |
---|
[37] | 94 | |
---|
[1270] | 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 | } |
---|
[121] | 104 | |
---|
[1270] | 105 | return r; |
---|
[37] | 106 | } |
---|
| 107 | |
---|
[1270] | 108 | void |
---|
| 109 | RpVariable::__init() |
---|
[37] | 110 | { |
---|
[1270] | 111 | _path = NULL; |
---|
| 112 | _h = NULL; |
---|
[37] | 113 | } |
---|
| 114 | |
---|
[1270] | 115 | void |
---|
| 116 | RpVariable::__close() |
---|
[37] | 117 | { |
---|
[1270] | 118 | if (_path != NULL) { |
---|
| 119 | free((void *)_path); |
---|
| 120 | } |
---|
[37] | 121 | |
---|
[1270] | 122 | if (_h != NULL) { |
---|
| 123 | Rp_DeleteHashTable(_h); |
---|
| 124 | } |
---|
[121] | 125 | |
---|
[1270] | 126 | __init(); |
---|
[37] | 127 | } |
---|
| 128 | |
---|
[121] | 129 | |
---|
[37] | 130 | // -------------------------------------------------------------------- // |
---|
| 131 | |
---|