SheafSystem  0.0.0.0
primitive_type.cc
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 
18 // Definitions relating to sheaf system primitive types.
19 
20 #include "SheafSystem/primitive_type.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/error_message.h"
24 #include "SheafSystem/primitive_attributes.h"
25 #include "SheafSystem/std_iomanip.h"
26 
27 using namespace std;
28 
29 namespace
30 {
31 const int PRIMITIVE_TYPE_CT = sheaf::PRIMITIVE_TYPE_END - sheaf::PRIMITIVE_TYPE_BEGIN;
32 
33 template <typename T>
34 class alignment
35 {
36 public:
37  char pad;
38  T prim;
39 };
40 }
41 
42 // =============================================================================
43 // PRIMITIVE TYPES FACET
44 // =============================================================================
45 
48 sheaf::
50 {
51  x = (x == PRIMITIVE_TYPE_END) ? PRIMITIVE_TYPE_BEGIN : primitive_type(x+1);
52  return x;
53 };
54 
56 bool
57 sheaf::
59 {
60  bool result;
61 
62  // Preconditions:
63 
64  // Body:
65 
66  result = (PRIMITIVE_TYPE_BEGIN <= xindex) && (xindex < PRIMITIVE_TYPE_END);
67 
68  // Postconditions:
69 
70  // Exit
71 
72  return result;
73 }
74 
76 std::ostream&
77 sheaf::
78 operator<<(std::ostream& os, const primitive_type& xpt)
79 {
80  // Preconditions:
81 
82 
83  // Body:
84 
85  os << primitive_attributes::name(xpt);
86 
87  // Postconditions:
88 
89 
90  // Exit:
91 
92  return os;
93 }
94 
96 std::istream&
97 sheaf::
98 operator>>(std::istream& is, primitive_type& xpt)
99 {
100  // Preconditions:
101 
102 
103  // Body:
104 
105  string ltmp;
106  is >> ltmp;
107  xpt = primitive_attributes::id(ltmp);
108 
109  // Postconditions:
110 
111 
112  // Exit:
113 
114  return is;
115 }
116 
117 
118 // =============================================================================
119 // PRIMITIVE DESCRIPTORS FACET
120 // =============================================================================
121 
123 std::ostream&
124 sheaf::
125 operator<<(std::ostream& os, const primitive_descriptor& xpd)
126 {
127  // Preconditions:
128 
129 
130  // Body:
131 
132  os << setw(4) << xpd.size
133  << setw(4) << xpd.alignment
134  << setw(4) << xpd.index
135  << " " << primitive_attributes::name(xpd.index);
136 
137 
138  // Postconditions:
139 
140 
141  // Exit:
142 
143  return os;
144 }
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
STL namespace.
primitive_type
Type ids for sheaf primitives.
SHEAF_DLL_SPEC bool is_primitive_index(pod_index_type xindex)
True if xindex is a valid primitive index.
SHEAF_DLL_SPEC std::istream & operator>>(std::istream &is, dof_tuple_type &xdt)
Extract dof_tuple_type xdt from istream& is.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
SHEAF_DLL_SPEC namespace_member_index & operator++(namespace_member_index &x)
Prefix increment operator for namespace_member_index.