source: branches/blt4/src/objects/RpAccessor.h @ 2060

Last change on this file since 2060 was 1560, checked in by dkearney, 15 years ago

updates to the object system, fixed up tree and xml parser objects, added some basic tests for them and adopted number object to accept xml text and configure itself from the parsed xml. added fermi3.cc example program which contains suggested interface from apps meeting.

File size: 1.7 KB
Line 
1/*
2 * ======================================================================
3 *  AUTHOR:  Derrick S. Kearney, Purdue University
4 *  Copyright (c) 2005-2009  Purdue Research Foundation
5 *
6 *  See the file "license.terms" for information on usage and
7 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 * ======================================================================
9 */
10
11#ifndef RAPPTURE_ACCESSOR_H
12#define RAPPTURE_ACCESSOR_H
13
14#include <cstring>
15
16namespace Rappture {
17
18template <class T>
19class Accessor
20{
21public:
22    Accessor ();
23    Accessor (const T &o);
24    ~Accessor();
25
26    // get routine
27    T operator() (void) const;
28
29    // set routine
30    void operator() (T val);
31
32private:
33
34    T _val;
35};
36
37template <class T>
38Accessor<T>::Accessor()
39{
40}
41
42template <class T>
43T
44Accessor<T>::operator() (void) const
45{
46    return _val;
47}
48
49template <class T>
50void
51Accessor<T>::operator() (T val)
52{
53    _val = val;
54}
55
56template <class T>
57Accessor<T>::~Accessor()
58{
59}
60
61// handle const char *'s gracefully?
62
63template <> inline
64Accessor<const char *>::Accessor()
65{
66    _val = NULL;
67}
68
69template <> inline
70void
71Accessor<const char *>::operator() (const char *val)
72{
73    if (val == NULL) {
74        return;
75    }
76
77    size_t len = strlen(val);
78    char *tmp = new char[len+1];
79    if (tmp == NULL) {
80        // raise error and exit
81    }
82    strncpy(tmp,val,len+1);
83
84    if (_val) {
85        delete[] _val;
86    }
87
88    _val = tmp;
89}
90
91template <> inline
92Accessor<const char *>::~Accessor()
93{
94    if (_val) {
95        delete[] _val;
96    }
97}
98
99} // namespace Rappture
100
101/*--------------------------------------------------------------------------*/
102/*--------------------------------------------------------------------------*/
103
104#endif // RAPPTURE_ACCESSOR_H
Note: See TracBrowser for help on using the repository browser.