Last change
on this file since 2936 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 | |
---|
16 | namespace Rappture { |
---|
17 | |
---|
18 | template <class T> |
---|
19 | class Accessor |
---|
20 | { |
---|
21 | public: |
---|
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 | |
---|
32 | private: |
---|
33 | |
---|
34 | T _val; |
---|
35 | }; |
---|
36 | |
---|
37 | template <class T> |
---|
38 | Accessor<T>::Accessor() |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | template <class T> |
---|
43 | T |
---|
44 | Accessor<T>::operator() (void) const |
---|
45 | { |
---|
46 | return _val; |
---|
47 | } |
---|
48 | |
---|
49 | template <class T> |
---|
50 | void |
---|
51 | Accessor<T>::operator() (T val) |
---|
52 | { |
---|
53 | _val = val; |
---|
54 | } |
---|
55 | |
---|
56 | template <class T> |
---|
57 | Accessor<T>::~Accessor() |
---|
58 | { |
---|
59 | } |
---|
60 | |
---|
61 | // handle const char *'s gracefully? |
---|
62 | |
---|
63 | template <> inline |
---|
64 | Accessor<const char *>::Accessor() |
---|
65 | { |
---|
66 | _val = NULL; |
---|
67 | } |
---|
68 | |
---|
69 | template <> inline |
---|
70 | void |
---|
71 | Accessor<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 | |
---|
91 | template <> inline |
---|
92 | Accessor<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.