Last change
on this file since 4356 was
3177,
checked in by mmc, 12 years ago
|
Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.
|
File size:
1.7 KB
|
Line | |
---|
1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * AUTHOR: Derrick S. Kearney, Purdue University |
---|
4 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
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.