SheafSystem  0.0.0.0
rc_any.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/rc_any.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 
25 using namespace std;
26 
27 // ===========================================================
28 // RC_ANY FACET
29 // ===========================================================
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  _ref_ct=0;
41 
42  // Postconditions:
43 
44  // Exit:
45 
46  return;
47 }
48 
50 rc_any(const rc_any & xother)
51 {
52  // Preconditions:
53 
54  // Body:
55 
56  _ref_ct=0;
57 
58  // Postconditions:
59 
60  // Exit:
61 
62  return;
63 }
64 
67 operator=(const rc_any& xother)
68 {
69  // Preconditions:
70 
71  // Body:
72 
73  // Postconditions:
74 
75  // Exit:
76 
77  return *this;
78 }
79 
82 {
83  // Preconditions:
84 
85  require(ref_ct()==0);
86 
87  // Body:
88 
89  // Postconditions:
90 
91  // Exit:
92 
93  return;
94 }
95 
96 void
99 {
100 
101  // Preconditions:
102 
103  // Body:
104 
105  ++_ref_ct;
106 
107  // Postconditions:
108 
109  ensure(ref_ct() > 0);
110 
111  // Exit:
112 
113  return;
114 }
115 
116 void
119 {
120  // Preconditions:
121 
122  // Body:
123 
124  if(--_ref_ct == 0)
125  delete this;
126 
127  // Postconditions:
128 
129  // Exit:
130 
131  return;
132 }
133 
134 bool
136 is_shared() const
137 {
138  // Preconditions:
139 
140  // Body:
141 
142  bool result = _ref_ct > 1;
143 
144  // Postconditions:
145 
146  // Exit:
147 
148  return result;
149 }
150 
153 ref_ct() const
154 {
155  // Preconditions:
156 
157  // Body:
158 
159  // Postconditions:
160 
161  // Exit:
162 
163  return _ref_ct;
164 }
165 
166 // PROTECTED MEMBER FUNCTIONS
167 
168 // PRIVATE MEMBER FUNCTIONS
169 
170 
171 // ===========================================================
172 // NON-MEMBER FUNCTIONS
173 // ===========================================================
174 
175 std::ostream&
176 sheaf::operator << (std::ostream& xos, const rc_any& xrc)
177 {
178  // Preconditions:
179 
180  // Body:
181 
182  xos << "rc_any: " << endl;
183  xos << " ref_ct = " << xrc.ref_ct() << endl;
184  xos << " shared = " << xrc.is_shared() << endl;
185  xos << endl;
186 
187  // Postconditions:
188 
189  // Exit:
190 
191  return xos;
192 }
STL namespace.
size_type ref_ct() const
Return the reference count.
Definition: rc_any.cc:153
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void add_reference()
Increment the reference count.
Definition: rc_any.cc:98
rc_any()
Default constructor.
Definition: rc_any.cc:34
Base class for reference counting.
Definition: rc_any.h:42
bool is_shared() const
True if the reference count is greater than one.
Definition: rc_any.cc:136
rc_any & operator=(const rc_any &xother)
Assignment operator.
Definition: rc_any.cc:67
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
void remove_reference()
Decrement the reference count. Delete this object if the reference count is zero. ...
Definition: rc_any.cc:118
~rc_any()
Destructor.
Definition: rc_any.cc:81