SheafSystem  0.0.0.0
primitive_type.h
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 // Declarations relating to sheaf system primitive types.
19 
20 #ifndef PRIMITIVE_TYPE_H
21 #define PRIMITIVE_TYPE_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef STD_CLIMITS_H
28 #include "SheafSystem/std_climits.h"
29 #endif
30 
31 #ifndef POD_TYPES_H
32 #include "SheafSystem/pod_types.h"
33 #endif
34 
35 namespace sheaf
36 {
37 
38 // =============================================================================
39 // PRIMITIVE TYPES FACET
40 // =============================================================================
41 
46 {
47  // Ids for primitive types.
48 
49  // Start at 2 to keep enum and primitives poset member index in sync.
50 
51  PRIMITIVE_TYPE_BEGIN = 2,
52 
53  BOOL = 2, // Must be same as BEGIN.
54  CHAR, // 3
55 
56  SIGNED_CHAR, // 4
57  SHORT_INT, // 5
58  INT, // 6
59  INT_TYPE = 6, // typedef for int
60  POD_INDEX_TYPE = 6, // typdef for int
61  LONG_INT, // 7
62  LONG_LONG_INT, // 8
63 
64  UNSIGNED_CHAR, // 9
65  UNSIGNED_SHORT_INT, // 10
66  UNSIGNED_INT, // 11
67  UNSIGNED_LONG_INT, // 12
68  SIZE_TYPE = 12, // typedef for unsigned long
69  UNSIGNED_LONG_LONG_INT, // 13
70 
71  FLOAT, // 14
72  DOUBLE, // 15
73  LONG_DOUBLE, // 16
74 
75  VOID_STAR, // 17
76  C_STRING, // 18
77 
78  NAMESPACE_RELATIVE_MEMBER_INDEX, // 19
79  NAMESPACE_RELATIVE_SUBPOSET_INDEX, // 20
80  PRIMITIVE_TYPE_END, // Must follow last type id.
81 
82 
83  // Don't forget to update the functions below
84  // and primitive_buffer_type if you change this enum.
85 
86  NOT_A_PRIMITIVE_TYPE = INT_MAX
87 };
88 
93 
97 SHEAF_DLL_SPEC
99 
103 SHEAF_DLL_SPEC
104 std::ostream & operator << (std::ostream& os, const primitive_type& xpt);
105 
109 SHEAF_DLL_SPEC
110 std::istream & operator >> (std::istream& is, primitive_type& xpt);
111 
112 
113 // =============================================================================
114 // PRIMITIVE DESCRIPTORS FACET
115 // =============================================================================
116 
117 struct SHEAF_DLL_SPEC primitive_descriptor
118 {
119  size_t size;
120  size_t alignment;
121  pod_index_type index;
122 };
123 
127 SHEAF_DLL_SPEC
128 std::ostream & operator << (std::ostream& os, const primitive_descriptor& xpd);
129 
130 
134 inline size_t align(const size_t xoffset, const size_t xalignment)
135 {
136  // Note: the C++ standard, section 5.3.4 paragraph 10, states
137  // allocation routines are assumed to return memory properly aligned
138  // for any object type, and that in particular, the beginning
139  // address of a char array is so aligned, so that char arrays
140  // can be used to store any type of object.
141  // Since the base of the array is thus aligned, we can properly
142  // align any object within the array by properly aligning the
143  // offset from the base of the array. This approach avoids
144  // the need for implementation dependent conversion of pointers to
145  // integer types to do arithmetic on the pointer.
146  //
147  // Explanation of the expression used here:
148  // Let o = xoffset, a = xalignment.
149  // The expression being evaluated is: ((o+a-1)/a)*a
150  // Various cases:
151  // o = 0 => ((0+a-1)/a)*a = 0*a = 0
152  // o = 1 => ((1+a-1)/a)*a = 1*a = a
153  // 1 < o <= a => ((a+a-1)/a)*a = 1*a = a
154  // na < o <= (n+1)a => (((n+1)a + a - 1)/a)*a = (n+1)*a
155  return ((xoffset + xalignment - 1)/xalignment)*xalignment;
156 };
157 
158 // =============================================================================
159 // PRIMITIVE_BUFFER_TYPE FACET
160 // =============================================================================
161 
166 {
167  bool bool_primitive;
168  char char_primitive;
169 
170  signed char signed_char_primitive;
171  short int short_int_primitive;
172  int int_primitive;
173  long int long_int_primitive;
174  long long int long_long_int_primitive;
175 
176  unsigned char unsigned_char_primitive;
177  unsigned short int unsigned_short_int_primitive;
178  unsigned int unsigned_int_primitive;
179  unsigned long int unsigned_long_int_primitive;
180  unsigned long long int unsigned_long_long_int_primitive;
181 
182  float float_primitive;
183  double double_primitive;
184  long double long_double_primitive;
185 
186  void_star void_star_primitive;
187  c_string c_string_primitive;
188 
189  namespace_relative_member_index_pod_type namespace_relative_member_index_primitive;
190  namespace_relative_subposet_index_pod_type namespace_relative_subposet_index_primitive;
191 
192  int_type int_type_primitive;
193  pod_index_type pod_index_type_primitive;
194  size_type size_type_primitive;
195 };
196 
197 } // end namespace sheaf
198 
199 #endif // ifndef PRIMITIVE_TYPE_H
void * void_star
Synonym for void*.
Definition: sheaf.h:57
primitive_type
Type ids for sheaf primitives.
Type of buffer large enough to hold any primitive type.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
POD type associated with namespace_relative_subposet_index.
Definition: pod_types.h:111
POD type for namespace_relative_member_index.
Definition: pod_types.h:79
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.
size_t align(const size_t xoffset, const size_t xalignment)
Smallest offset greater than or equal to xoffset that has alignment xalignment.
Namespace for the sheaves component of the sheaf system.
SHEAF_DLL_SPEC namespace_member_index & operator++(namespace_member_index &x)
Prefix increment operator for namespace_member_index.
int int_type
The preferred integer type.
Definition: sheaf.h:41
char * c_string
Synonym for char*.
Definition: sheaf.h:62