diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/atom.h | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/atom.h | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/src/stable/atom.h b/src/stable/atom.h index 105c29a..9679ab6 100644 --- a/src/stable/atom.h +++ b/src/stable/atom.h | |||
@@ -15,133 +15,133 @@ | |||
15 | 15 | ||
16 | namespace Bu | 16 | namespace Bu |
17 | { | 17 | { |
18 | /** | 18 | /** |
19 | * | 19 | * |
20 | *@ingroup Containers | 20 | *@ingroup Containers |
21 | */ | 21 | */ |
22 | template <typename t, typename talloc=std::allocator<t> > | 22 | template <typename t, typename talloc=std::allocator<t> > |
23 | class Atom | 23 | class Atom |
24 | { | 24 | { |
25 | private: | 25 | private: |
26 | typedef struct Atom<t, talloc> MyType; | 26 | typedef struct Atom<t, talloc> MyType; |
27 | 27 | ||
28 | public: | 28 | public: |
29 | Atom() : | 29 | Atom() : |
30 | pData( NULL ) | 30 | pData( NULL ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Atom( const MyType &oth ) : | 34 | Atom( const MyType &oth ) : |
35 | pData( NULL ) | 35 | pData( NULL ) |
36 | { | 36 | { |
37 | if( oth.pData ) | 37 | if( oth.pData ) |
38 | set( *oth.pData ); | 38 | set( *oth.pData ); |
39 | } | 39 | } |
40 | 40 | ||
41 | Atom( const t &oth ) : | 41 | Atom( const t &oth ) : |
42 | pData( NULL ) | 42 | pData( NULL ) |
43 | { | 43 | { |
44 | set( oth ); | 44 | set( oth ); |
45 | } | 45 | } |
46 | 46 | ||
47 | virtual ~Atom() | 47 | virtual ~Atom() |
48 | { | 48 | { |
49 | clear(); | 49 | clear(); |
50 | } | 50 | } |
51 | 51 | ||
52 | bool has() const | 52 | bool has() const |
53 | { | 53 | { |
54 | return (pData != NULL); | 54 | return (pData != NULL); |
55 | } | 55 | } |
56 | 56 | ||
57 | void set( const t &val ) | 57 | void set( const t &val ) |
58 | { | 58 | { |
59 | clear(); | 59 | clear(); |
60 | pData = ta.allocate( 1 ); | 60 | pData = ta.allocate( 1 ); |
61 | ta.construct( pData, val ); | 61 | ta.construct( pData, val ); |
62 | } | 62 | } |
63 | 63 | ||
64 | t &get() | 64 | t &get() |
65 | { | 65 | { |
66 | if( !pData ) | 66 | if( !pData ) |
67 | throw Bu::ExceptionBase("Not set"); | 67 | throw Bu::ExceptionBase("Not set"); |
68 | return *pData; | 68 | return *pData; |
69 | } | 69 | } |
70 | 70 | ||
71 | const t &get() const | 71 | const t &get() const |
72 | { | 72 | { |
73 | if( !pData ) | 73 | if( !pData ) |
74 | throw Bu::ExceptionBase("Not set"); | 74 | throw Bu::ExceptionBase("Not set"); |
75 | return *pData; | 75 | return *pData; |
76 | } | 76 | } |
77 | 77 | ||
78 | void clear() | 78 | void clear() |
79 | { | 79 | { |
80 | if( pData ) | 80 | if( pData ) |
81 | { | 81 | { |
82 | ta.destroy( pData ); | 82 | ta.destroy( pData ); |
83 | ta.deallocate( pData, 1 ); | 83 | ta.deallocate( pData, 1 ); |
84 | pData = NULL; | 84 | pData = NULL; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | operator const t &() const | 88 | operator const t &() const |
89 | { | 89 | { |
90 | if( !pData ) | 90 | if( !pData ) |
91 | throw Bu::ExceptionBase("Not set"); | 91 | throw Bu::ExceptionBase("Not set"); |
92 | return *pData; | 92 | return *pData; |
93 | } | 93 | } |
94 | 94 | ||
95 | operator t &() | 95 | operator t &() |
96 | { | 96 | { |
97 | if( !pData ) | 97 | if( !pData ) |
98 | throw Bu::ExceptionBase("Not set"); | 98 | throw Bu::ExceptionBase("Not set"); |
99 | return *pData; | 99 | return *pData; |
100 | } | 100 | } |
101 | 101 | ||
102 | MyType &operator =( const t &oth ) | 102 | MyType &operator =( const t &oth ) |
103 | { | 103 | { |
104 | set( oth ); | 104 | set( oth ); |
105 | 105 | ||
106 | return *this; | 106 | return *this; |
107 | } | 107 | } |
108 | 108 | ||
109 | MyType &operator =( const MyType &oth ) | 109 | MyType &operator =( const MyType &oth ) |
110 | { | 110 | { |
111 | if( oth.pData ) | 111 | if( oth.pData ) |
112 | set( *oth.pData ); | 112 | set( *oth.pData ); |
113 | 113 | ||
114 | return *this; | 114 | return *this; |
115 | } | 115 | } |
116 | 116 | ||
117 | bool operator ==( const MyType &oth ) | 117 | bool operator ==( const MyType &oth ) |
118 | { | 118 | { |
119 | return (*pData) == (*oth.pData); | 119 | return (*pData) == (*oth.pData); |
120 | } | 120 | } |
121 | 121 | ||
122 | bool operator ==( const t &oth ) | 122 | bool operator ==( const t &oth ) |
123 | { | 123 | { |
124 | return (*pData) == oth; | 124 | return (*pData) == oth; |
125 | } | 125 | } |
126 | 126 | ||
127 | t *operator ->() | 127 | t *operator ->() |
128 | { | 128 | { |
129 | if( !pData ) | 129 | if( !pData ) |
130 | throw Bu::ExceptionBase("Not set"); | 130 | throw Bu::ExceptionBase("Not set"); |
131 | return pData; | 131 | return pData; |
132 | } | 132 | } |
133 | 133 | ||
134 | t &operator *() | 134 | t &operator *() |
135 | { | 135 | { |
136 | if( !pData ) | 136 | if( !pData ) |
137 | throw Bu::ExceptionBase("Not set"); | 137 | throw Bu::ExceptionBase("Not set"); |
138 | return *pData; | 138 | return *pData; |
139 | } | 139 | } |
140 | 140 | ||
141 | private: | 141 | private: |
142 | t *pData; | 142 | t *pData; |
143 | talloc ta; | 143 | talloc ta; |
144 | }; | 144 | }; |
145 | } | 145 | } |
146 | 146 | ||
147 | #endif | 147 | #endif |