source: trunk/src/objects/RpVariable.cc @ 1270

Last change on this file since 1270 was 1270, checked in by dkearney, 16 years ago

rappture object updates, stuff i'm playing around with. the code is not functional but it compiles, and i dont want to loose this state as i continue to play. the configure scripts and makefiles should still be working properly.

File size: 2.3 KB
Line 
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
21RpVariable::RpVariable()
22{
23    __init();
24}
25
26RpVariable::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
35RpVariable::~RpVariable()
36{
37    __close();
38}
39
40const char *
41RpVariable::label(
42    const char *val)
43{
44    return (const char *) property("label",val);
45}
46
47const char *
48RpVariable::desc(
49    const char *val)
50{
51    return (const char *) property("desc",val);
52}
53
54const char *
55RpVariable::hints(
56    const char *val)
57{
58    return (const char *) property("hints",val);
59}
60
61const char *
62RpVariable::color(
63    const char *val)
64{
65    return (const char *) property("color",val);
66}
67
68const char *
69RpVariable::icon(
70    const char *val)
71{
72    return (const char *) property("icon",val);
73}
74
75const char *
76RpVariable::path(
77    const char *val)
78{
79    return (const char *) property("path",val);
80}
81
82const void *
83RpVariable::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
108void
109RpVariable::__init()
110{
111    _path = NULL;
112    _h = NULL;
113}
114
115void
116RpVariable::__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
Note: See TracBrowser for help on using the repository browser.