SheafSystem  0.0.0.0
dof_descriptor_array.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/dof_descriptor_array.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/primitive_attributes.h"
25 #include "SheafSystem/std_string.h"
26 
27 // ===========================================================
28 // DOF_DESCRIPTOR_ARRAY FACET
29 // ===========================================================
30 
31 sheaf::dof_descriptor_array::
32 dof_descriptor_array(size_type xdof_ct)
33 {
34  // Preconditions:
35 
36  require(xdof_ct >= 0);
37 
38  // Body:
39 
40  _ub = xdof_ct+1;
41  _descriptors = new dof_descriptor[_ub];
42  _ref_ct = 0;
43 
44  // Postconditions:
45 
46  ensure(ub() == xdof_ct + 1);
47 
48  // Exit:
49 
50  return;
51 }
52 
55 {
56  // Preconditions:
57 
58  // Body:
59 
60  delete [] _descriptors;
61 
62  // Postconditions:
63 
64  // Exit:
65 
66  return;
67 }
68 
71 operator[](int xid) const
72 {
73  // Preconditions:
74 
75  require( (0 <= xid) && (xid < ub()) );
76 
77  return _descriptors[xid];
78 }
79 
80 void
83 {
84  _ref_ct++;
85 }
86 
87 void
90 {
91  if(--_ref_ct == 0)
92  delete this;
93 }
94 
97 ub() const
98 {
99  size_type result = _ub;
100 
101  // Postconditions:
102 
103  ensure(result >= 1);
104 
105  return result;
106 }
107 
110 dof_ct() const
111 {
112  size_type result = _ub - 1;
113 
114  // Postconditions:
115 
116  ensure(result >= 0);
117 
118  return result;
119 }
120 
123 size() const
124 {
125  return _descriptors[_ub - 1].offset;
126 }
127 
128 // ===========================================================
129 // NON-MEMBER FUNCTIONS
130 // ===========================================================
131 
132 std::ostream&
133 sheaf::
134 operator << (std::ostream &os, const dof_descriptor_array& p)
135 {
136  os << "p.ub() = " << p.ub() << std::endl;
137 
138  for(int i=0; i<p.ub(); ++i)
139  {
140  os << " " << p[i];
141  }
142 
143  return os;
144 }
145 
146 std::ostream&
147 sheaf::
149 {
150  os << "{" << primitive_attributes::name(p.type)
151  << ", " << p.size
152  << ", " << p.alignment
153  << ", " << p.offset
154  << "}";
155 
156  return os;
157 }
158 
159 size_t
160 sheaf::
161 deep_size(const dof_descriptor_array& xp, bool xinclude_shallow)
162 {
163  size_t result;
164 
165  // Preconditions:
166 
167  // Body:
168 
169  result = xinclude_shallow ? sizeof(xp) : 0;
170 
171  // Add the memory allocated for _descriptors.
172 
173  dof_descriptor_array& lxp = const_cast<dof_descriptor_array&>(xp);
174  result += lxp.ub()*sizeof(dof_descriptor_array::dof_descriptor);
175 
176  // Postconditions:
177 
178  ensure(result >= 0);
179 
180  // Exit
181 
182  return result;
183 }
size_type size() const
The number of bytes in the dof tuple described by this.
size_type dof_ct() const
The number of dofs described in this.
size_type ub() const
The upper bound on the array index; the number of descriptors. Note that this is not the number of do...
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
An array for storing structs which describe the size, alignment, and offset of dofs within a dof tupl...
void remove_reference()
Remove a reference from this.
void add_reference()
Add a reference to this.
virtual dof_descriptor & operator[](int xid) const
Value of xid-th element.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
const std::string & name() const
The name of the primitive type associated with this.