21 #include "SheafSystem/primitive_value.h" 23 #include "SheafSystem/assert_contract.h" 24 #include "SheafSystem/block.impl.h" 25 #include "SheafSystem/poset_path.h" 26 #include "SheafSystem/primitive_traits.h" 27 #include "SheafSystem/std_cstring.h" 28 #include "SheafSystem/std_sstream.h" 30 using namespace sheaf;
43 lstr << reinterpret_cast<const T&>(x);
66 if(xid == sheaf::NOT_A_PRIMITIVE_TYPE)
68 xid = sheaf::PRIMITIVE_TYPE_END;
71 static const to_string_type lfcn_ptrs[] =
78 to_string<signed char>,
82 to_string<long long int>,
84 to_string<unsigned char>,
85 to_string<unsigned short int>,
86 to_string<unsigned int>,
87 to_string<unsigned long int>,
88 to_string<unsigned long long int>,
92 to_string<long double>,
97 to_string<sheaf::namespace_relative_member_index_pod_type>,
98 to_string<sheaf::namespace_relative_subposet_index_pod_type>,
102 return lfcn_ptrs[xid];
109 template <
typename T>
112 stringstream lstr(x);
113 lstr >>
reinterpret_cast<T&
>(b);
124 b.c_string_primitive = strdup(x.c_str());
134 for(
int i=0; i<
sizeof(b); ++i)
136 reinterpret_cast<char*
>(&b)[i] = 0;
152 if(xid == sheaf::NOT_A_PRIMITIVE_TYPE)
154 xid = sheaf::PRIMITIVE_TYPE_END;
157 static const from_string_type lfcn_ptrs[] =
164 from_string<signed char>,
165 from_string<short int>,
167 from_string<long int>,
168 from_string<long long int>,
170 from_string<unsigned char>,
171 from_string<unsigned short int>,
172 from_string<unsigned int>,
173 from_string<unsigned long int>,
174 from_string<unsigned long long int>,
178 from_string<long double>,
183 from_string<sheaf::namespace_relative_member_index_pod_type>,
184 from_string<sheaf::namespace_relative_subposet_index_pod_type>,
188 return lfcn_ptrs[xid];
216 ensure(static_cast<pod_index_type>(result.
id()) ==
218 ensure(unexecutable(
"result.value == default value for type associated with id"));
262 (*this) = prototype(xid);
275 ensure(unexecutable(
"value() == primitive_attributes::default_value(xid)"));
289 require(xvalue_ptr != 0);
293 (*this) = prototype(xid);
303 ensure(unexecutable(
"value() == *reinterpret_cast<primitive_buffer_type*>(xvalue_ptr)"));
771 _value.void_star_primitive =
const_cast<void*
>(x);
781 _value.void_star_primitive =
const_cast<void*
>(x);
791 _value.c_string_primitive = strdup(x);
801 _value.c_string_primitive = strdup(x);
806 template <
typename T>
812 *
reinterpret_cast<T*
>(&_value) = x;
841 _value.c_string_primitive = strdup(s.c_str());
890 _value.c_string_primitive = strdup(x.
path().c_str());
894 #ifndef DOXYGEN_SKIP_PRIMITIVE_INSTANTIATIONS 958 #endif // DOXYGEN_SKIP_PRIMITIVE_INSTANTIATIONS 976 sheaf::primitive_value::
977 operator bool()
const 979 return _value.bool_primitive;
982 sheaf::primitive_value::
983 operator char()
const 985 return _value.char_primitive;
988 sheaf::primitive_value::
989 operator
signed char()
const 991 return _value.signed_char_primitive;
994 sheaf::primitive_value::
995 operator
short int()
const 997 return _value.short_int_primitive;
1000 sheaf::primitive_value::
1001 operator int()
const 1003 return _value.int_primitive;
1006 sheaf::primitive_value::
1007 operator
long int()
const 1009 return _value.long_int_primitive;
1012 sheaf::primitive_value::
1013 operator
long long int()
const 1015 return _value.long_long_int_primitive;
1018 sheaf::primitive_value::
1019 operator
unsigned char()
const 1021 return _value.unsigned_char_primitive;
1024 sheaf::primitive_value::
1025 operator
unsigned short int()
const 1027 return _value.unsigned_short_int_primitive;
1030 sheaf::primitive_value::
1031 operator
unsigned int()
const 1033 return _value.unsigned_int_primitive;
1036 sheaf::primitive_value::
1037 operator
unsigned long int()
const 1039 return _value.unsigned_long_int_primitive;
1042 sheaf::primitive_value::
1043 operator
unsigned long long int()
const 1045 return _value.unsigned_long_long_int_primitive;
1048 sheaf::primitive_value::
1049 operator float()
const 1051 return _value.float_primitive;
1054 sheaf::primitive_value::
1055 operator double()
const 1057 return _value.double_primitive;
1060 sheaf::primitive_value::
1061 operator
long double()
const 1063 return _value.long_double_primitive;
1066 sheaf::primitive_value::
1067 operator
void*()
const 1069 return _value.void_star_primitive;
1072 sheaf::primitive_value::
1073 operator
char*()
const 1075 return _value.c_string_primitive;
1078 sheaf::primitive_value::
1081 return _value.namespace_relative_member_index_primitive;
1084 sheaf::primitive_value::
1087 return _value.namespace_relative_subposet_index_primitive;
1110 return (*to_string_function(_id))(_value);
1113 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1120 return (*from_string_function(_id))(x, _value);
1123 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS 1133 sheaf::primitive_value::
1141 if(result.
ct() == 0)
1167 result[NAMESPACE_RELATIVE_MEMBER_INDEX] =
1170 result[NAMESPACE_RELATIVE_SUBPOSET_INDEX] =
1175 result.
set_ct(PRIMITIVE_TYPE_END+1);
1195 result = (xpv1._id == xpv2._id);
1202 result = result && xpv1._value.bool_primitive == xpv2._value.bool_primitive;
1205 result = result && xpv1._value.char_primitive == xpv2._value.char_primitive;
1208 result = result && xpv1._value.signed_char_primitive == xpv2._value.signed_char_primitive;
1211 result = result && xpv1._value.short_int_primitive == xpv2._value.short_int_primitive;
1214 result = result && xpv1._value.int_primitive == xpv2._value.int_primitive;
1217 result = result && xpv1._value.long_int_primitive == xpv2._value.long_int_primitive;
1220 result = result && xpv1._value.long_long_int_primitive == xpv2._value.long_long_int_primitive;
1223 result = result && xpv1._value.unsigned_char_primitive == xpv2._value.unsigned_char_primitive;
1225 case UNSIGNED_SHORT_INT:
1226 result = result && xpv1._value.unsigned_short_int_primitive == xpv2._value.unsigned_short_int_primitive;
1229 result = result && xpv1._value.unsigned_int_primitive == xpv2._value.unsigned_int_primitive;
1231 case UNSIGNED_LONG_INT:
1232 result = result && xpv1._value.unsigned_long_int_primitive == xpv2._value.unsigned_long_int_primitive;
1234 case UNSIGNED_LONG_LONG_INT:
1235 result = result && xpv1._value.unsigned_long_long_int_primitive == xpv2._value.unsigned_long_long_int_primitive;
1238 result = result && xpv1._value.float_primitive == xpv2._value.float_primitive;
1241 result = result && xpv1._value.double_primitive == xpv2._value.double_primitive;
1244 result = result && xpv1._value.long_double_primitive == xpv2._value.long_double_primitive;
1247 result = result && xpv1._value.void_star_primitive == xpv2._value.void_star_primitive;
1250 result = result && xpv1._value.c_string_primitive == xpv2._value.c_string_primitive;
1252 case NAMESPACE_RELATIVE_MEMBER_INDEX:
1253 result = result && xpv1._value.namespace_relative_member_index_primitive == xpv2._value.namespace_relative_member_index_primitive;
1255 case NAMESPACE_RELATIVE_SUBPOSET_INDEX:
1256 result = result && xpv1._value.namespace_relative_subposet_index_primitive == xpv2._value.namespace_relative_subposet_index_primitive;
1272 return (
void*)(xpv) == xval;
1279 return xval == (
void*)(xpv);
1286 return strcmp(xpv.
value().c_string_primitive, xval) == 0;
1293 return strcmp(xval, xpv.
value().c_string_primitive) == 0;
1300 return xpv.
value().c_string_primitive == xval;
1307 return xval == xpv.
value().c_string_primitive;
1356 return (
bool)(xpv) == xval;
1363 return xval == (bool)(xpv);
1370 return (
char)(xpv) == xval;
1377 return xval == (char)(xpv);
1384 return (
signed char)(xpv) == xval;
1391 return xval == (
signed char)(xpv);
1398 return (
short int)(xpv) == xval;
1405 return xval == (
short int)(xpv);
1412 return (
int)(xpv) == xval;
1419 return xval == (int)(xpv);
1426 return (
long int)(xpv) == xval;
1433 return xval == (
long int)(xpv);
1440 return (
long long int)(xpv) == xval;
1447 return xval == (
long long int)(xpv);
1454 return (
unsigned char)(xpv) == xval;
1461 return xval == (
unsigned char)(xpv);
1468 return (
unsigned short int)(xpv) == xval;
1475 return xval == (
unsigned short int)(xpv);
1482 return (
unsigned int)(xpv) == xval;
1489 return xval == (
unsigned int)(xpv);
1496 return (
unsigned long int)(xpv) == xval;
1503 return xval == (
unsigned long int)(xpv);
1510 return (
unsigned long long)(xpv) == xval;
1517 return xval == (
unsigned long long)(xpv);
1524 return (
float)(xpv) == xval;
1531 return xval == (float)(xpv);
1538 return (
double)(xpv) == xval;
1545 return xval == (double)(xpv);
1552 return (
long double)(xpv) == xval;
1559 return xval == (
long double)(xpv);
1617 ensure(result == 0);
Index for identifying a poset member relative to a given name space.
size_type ct() const
The number of items currently in use.
pod_type pod() const
The "plain old data" storage of this.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
~primitive_value()
Destructor.
A path defined by a poset name and a member name separated by a forward slash ('/'). For example: "cell_definitions/triangle".
primitive_value()
Default constructor.
std::string to_string() const
Converts this to a string (for stream insertion).
pod_type pod() const
The "plain old data" storage of this.
primitive_type
Type ids for sheaf primitives.
Type of buffer large enough to hold any primitive type.
void set_ct(size_type xct)
Sets ct() == xct.
An index within the external ("client") scope of a given id space.
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.
POD type associated with namespace_relative_subposet_index.
POD type for namespace_relative_member_index.
SHEAF_DLL_SPEC bool is_primitive_index(pod_index_type xindex)
True if xindex is a valid primitive index.
Traits for primitive type T.
Index for identifying a subposet relative to a given name space.
static primitive_type id()
The primitive type id for T.
static T default_value()
The default value for instances of type T.
bool from_string(const std::string &x)
Converts this from a string (from stream extraction); returns true if operation successful, false otherwise.
primitive_buffer_type & value()
The value of this.
bool operator==(const singly_linked_list< T, Alloc > &lhs, const singly_linked_list< T, Alloc > &rhs)
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
primitive_type & id()
Type id of the primitive type.
primitive_value & operator=(const primitive_value &x)
Copy assignment.
int_type pod_index_type
The plain old data index type.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
Namespace for the sheaves component of the sheaf system.
Abstract object wrapper for an instance of a primitive type.
static const primitive_value & prototype(pod_index_type xid)
The prototype for the primitive value of the type associated with xid.
std::string path() const
The full path as a string.
An auto_block with a no-initialization initialization policy.