SheafSystem  0.0.0.0
primitive_value.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 //
19 // Implementation for class primitive_value
20 
21 #include "SheafSystem/primitive_value.h"
22 
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"
29 
30 using namespace sheaf;
31 using namespace std;
32 
33 namespace
34 {
35 
39 template <typename T>
40 std::string to_string(const sheaf::primitive_buffer_type& x)
41 {
42  stringstream lstr;
43  lstr << reinterpret_cast<const T&>(x);
44  return lstr.str();
45 };
46 
47 // Specialization for void.
48 
49 template <>
50 std::string to_string<void>(const sheaf::primitive_buffer_type& x)
51 {
52  return "<undefined>";
53 };
54 
58 typedef std::string (*to_string_type)(const sheaf::primitive_buffer_type& x);
59 
60 to_string_type to_string_function(sheaf::primitive_type xid)
61 {
62  // Preconditions:
63 
64  // require(is_primitive_index(xid));
65 
66  if(xid == sheaf::NOT_A_PRIMITIVE_TYPE)
67  {
68  xid = sheaf::PRIMITIVE_TYPE_END;
69  }
70 
71  static const to_string_type lfcn_ptrs[] =
72  {
73  0,
74  0,
75  to_string<bool>,
76  to_string<char>,
77 
78  to_string<signed char>,
79  to_string<short int>,
80  to_string<int>,
81  to_string<long int>,
82  to_string<long long int>,
83 
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>,
89 
90  to_string<float>,
91  to_string<double>,
92  to_string<long double>,
93 
94  to_string<void*>,
95  to_string<char*>,
96 
97  to_string<sheaf::namespace_relative_member_index_pod_type>,
98  to_string<sheaf::namespace_relative_subposet_index_pod_type>,
99  to_string<void>
100  };
101 
102  return lfcn_ptrs[xid];
103 };
104 
105 
109 template <typename T>
110 bool from_string(const std::string& x, sheaf::primitive_buffer_type& b)
111 {
112  stringstream lstr(x);
113  lstr >> reinterpret_cast<T&>(b);
114  return !lstr.fail();
115 };
116 
117 // Specialization for C_STRING
118 
119 template <>
120 bool from_string<char*>(const std::string& x, sheaf::primitive_buffer_type& b)
121 {
122  // For c_string values, assume the entire string x is the value.
123 
124  b.c_string_primitive = strdup(x.c_str());
125 
126  return true;
127 };
128 
129 // Specialization for void
130 
131 template <>
132 bool from_string<void>(const std::string& x, sheaf::primitive_buffer_type& b)
133 {
134  for(int i=0; i<sizeof(b); ++i)
135  {
136  reinterpret_cast<char*>(&b)[i] = 0;
137  }
138  return true;
139 };
140 
144 typedef bool (*from_string_type)(const std::string& x, sheaf::primitive_buffer_type& b);
145 
146 from_string_type from_string_function(sheaf::primitive_type xid)
147 {
148  // Preconditions:
149 
150  // require(is_primitive_index(xid));
151 
152  if(xid == sheaf::NOT_A_PRIMITIVE_TYPE)
153  {
154  xid = sheaf::PRIMITIVE_TYPE_END;
155  }
156 
157  static const from_string_type lfcn_ptrs[] =
158  {
159  0,
160  0,
161  from_string<bool>,
162  from_string<char>,
163 
164  from_string<signed char>,
165  from_string<short int>,
166  from_string<int>,
167  from_string<long int>,
168  from_string<long long int>,
169 
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>,
175 
176  from_string<float>,
177  from_string<double>,
178  from_string<long double>,
179 
180  from_string<void*>,
181  from_string<char*>,
182 
183  from_string<sheaf::namespace_relative_member_index_pod_type>,
184  from_string<sheaf::namespace_relative_subposet_index_pod_type>,
185  from_string<void>
186  };
187 
188  return lfcn_ptrs[xid];
189 };
190 
191 }
192 
193 // ===========================================================
194 // STATIC FUNCTIONS
195 // ===========================================================
196 
201 {
202  // Preconditions:
203 
204  // require(is_primitive_index(xid));
205 
206  // Body:
207 
208  xid = is_primitive_index(xid) ? xid : PRIMITIVE_TYPE_END;
209 
210  static const block<primitive_value>& lprototypes = make_prototypes();
211  primitive_value& result = lprototypes[xid];
212 
213  // Postconditions:
214 
215  // ensure(result.id() == xid);
216  ensure(static_cast<pod_index_type>(result.id()) ==
217  (is_primitive_index(xid) ? xid : static_cast<pod_index_type>(NOT_A_PRIMITIVE_TYPE)));
218  ensure(unexecutable("result.value == default value for type associated with id"));
219 
220  // Exit:
221 
222  return result;
223 }
224 
225 // ===========================================================
226 // CONSTRUCTORS
227 // ===========================================================
228 
229 // ///
230 // primitive_value::
231 // primitive_value()
232 // {
233 // _id = INT;
234 // _value.int_primitive = primitive_traits<int>::default_value();
235 // }
236 
240 {
243 }
244 
248 {
249  (*this) = x;
250 }
251 
255 {
256  // Preconditions:
257 
258  require(is_primitive_index(xid));
259 
260  // Body:
261 
262  (*this) = prototype(xid);
263 
264  // Postconditions:
265 
266  ensure(id() == xid);
267 
268  // Next postcondition is unexecutable because primitve_buffer_type::operator==
269  // doesn't exist and it isn't immediately clear how to define it.
270  // What we mean here is that the member of value() associated with id() is
271  // equal to the corresponding member in default_value(), but we can't define
272  // this in the context of primitive_buffer type alone. The only thing we can do
273  // is compare all the bytes, but for most members, some of the bytes will be undefined.
274 
275  ensure(unexecutable("value() == primitive_attributes::default_value(xid)"));
276 
277  // Exit:
278 
279  return;
280 }
281 
284 primitive_value(pod_index_type xid, void* xvalue_ptr)
285 {
286  // Preconditions:
287 
288  require(is_primitive_index(xid));
289  require(xvalue_ptr != 0);
290 
291  // Body:
292 
293  (*this) = prototype(xid);
294  _value = *reinterpret_cast<primitive_buffer_type*>(xvalue_ptr);
295 
296  // Postconditions:
297 
298  ensure(id() == xid);
299 
300  // Next postcondition is unexecutable because primitve_buffer_type::operator==
301  // doesn't exist and it isn't immediately clear how to define it.
302 
303  ensure(unexecutable("value() == *reinterpret_cast<primitive_buffer_type*>(xvalue_ptr)"));
304 
305  // Exit:
306 
307  return;
308 }
309 
312 primitive_value(const void* x)
313 {
314 
315  // Id:
316 
317  (*this) = x;
318 
319  // Postconditions:
320 
321  ensure(id() == primitive_traits<void*>::id());
322  //ensure((*this) == x);
323 
324  // Exit:
325 
326  return;
327 }
328 
331 primitive_value(const char* x)
332 {
333 
334  // Id:
335 
336  (*this) = x;
337 
338  // Postconditions:
339 
340  ensure(id() == primitive_traits<char*>::id());
341  //ensure((*this) == x);
342 
343  // Exit:
344 
345  return;
346 }
347 
348 // Template specializations
349 
352 primitive_value(const std::string& x)
353 {
354 
355  // Id:
356 
357  (*this) = x.c_str();
358 
359  // Postconditions:
360 
361  ensure(id() == primitive_traits<char *>::id());
362  //ensure((*this) == x);
363 
364  // Exit:
365 
366  return;
367 }
368 
372 {
373 
374  // Id:
375 
376  (*this) = x.pod();
377 
378  // Postconditions:
379 
380  ensure(id() == primitive_traits<pod_index_type>::id());
381  //ensure((*this) == x);
382 
383  // Exit:
384 
385  return;
386 }
387 
391 {
392 
393  // Id:
394 
395  (*this) = x.pod();
396 
397  // Postconditions:
398 
400  //ensure((*this) == x);
401 
402  // Exit:
403 
404  return;
405 }
406 
410 {
411 
412  // Id:
413 
414  (*this) = x.pod();
415 
416  // Postconditions:
417 
419  //ensure((*this) == x);
420 
421  // Exit:
422 
423  return;
424 }
425 
428 primitive_value(const bool& x)
429 {
430 
431  // Id:
432 
433  (*this) = x;
434 
435  // Postconditions:
436 
437  ensure(id() == primitive_traits<bool>::id());
438  //ensure((*this) == x);
439 
440  // Exit:
441 
442  return;
443 }
444 
447 primitive_value(const char& x)
448 {
449 
450  // Id:
451 
452  (*this) = x;
453 
454  // Postconditions:
455 
456  ensure(id() == primitive_traits<char>::id());
457  //ensure((*this) == x);
458 
459  // Exit:
460 
461  return;
462 }
463 
466 primitive_value(const signed char& x)
467 {
468 
469  // Id:
470 
471  (*this) = x;
472 
473  // Postconditions:
474 
475  ensure(id() == primitive_traits<signed char>::id());
476  //ensure((*this) == x);
477 
478  // Exit:
479 
480  return;
481 }
482 
485 primitive_value(const short int& x)
486 {
487 
488  // Id:
489 
490  (*this) = x;
491 
492  // Postconditions:
493 
494  ensure(id() == primitive_traits<short int>::id());
495  //ensure((*this) == x);
496 
497  // Exit:
498 
499  return;
500 }
501 
504 primitive_value(const int& x)
505 {
506 
507  // Id:
508 
509  (*this) = x;
510 
511  // Postconditions:
512 
513  ensure(id() == primitive_traits<int>::id());
514  //ensure((*this) == x);
515 
516  // Exit:
517 
518  return;
519 }
520 
523 primitive_value(const long int& x)
524 {
525 
526  // Id:
527 
528  (*this) = x;
529 
530  // Postconditions:
531 
532  ensure(id() == primitive_traits<long int>::id());
533  //ensure((*this) == x);
534 
535  // Exit:
536 
537  return;
538 }
539 
542 primitive_value(const long long int& x)
543 {
544 
545  // Id:
546 
547  (*this) = x;
548 
549  // Postconditions:
550 
551  ensure(id() == primitive_traits<long long int>::id());
552  //ensure((*this) == x);
553 
554  // Exit:
555 
556  return;
557 }
558 
561 primitive_value(const unsigned char& x)
562 {
563 
564  // Id:
565 
566  (*this) = x;
567 
568  // Postconditions:
569 
570  ensure(id() == primitive_traits<unsigned char>::id());
571  //ensure((*this) == x);
572 
573  // Exit:
574 
575  return;
576 }
577 
580 primitive_value(const unsigned short int& x)
581 {
582 
583  // Id:
584 
585  (*this) = x;
586 
587  // Postconditions:
588 
590  //ensure((*this) == x);
591 
592  // Exit:
593 
594  return;
595 }
596 
599 primitive_value(const unsigned int& x)
600 {
601 
602  // Id:
603 
604  (*this) = x;
605 
606  // Postconditions:
607 
608  ensure(id() == primitive_traits<unsigned int>::id());
609  //ensure((*this) == x);
610 
611  // Exit:
612 
613  return;
614 }
615 
618 primitive_value(const unsigned long int& x)
619 {
620 
621  // Id:
622 
623  (*this) = x;
624 
625  // Postconditions:
626 
627  ensure(id() == primitive_traits<unsigned long int>::id());
628  //ensure((*this) == x);
629 
630  // Exit:
631 
632  return;
633 }
634 
637 primitive_value(const unsigned long long int& x)
638 {
639 
640  // Id:
641 
642  (*this) = x;
643 
644  // Postconditions:
645 
647  //ensure((*this) == x);
648 
649  // Exit:
650 
651  return;
652 }
653 
656 primitive_value(const float& x)
657 {
658 
659  // Id:
660 
661  (*this) = x;
662 
663  // Postconditions:
664 
665  ensure(id() == primitive_traits<float>::id());
666  //ensure((*this) == x);
667 
668  // Exit:
669 
670  return;
671 }
672 
675 primitive_value(const double& x)
676 {
677 
678  // Id:
679 
680  (*this) = x;
681 
682  // Postconditions:
683 
684  ensure(id() == primitive_traits<double>::id());
685  //ensure((*this) == x);
686 
687  // Exit:
688 
689  return;
690 }
691 
694 primitive_value(const long double& x)
695 {
696 
697  // Id:
698 
699  (*this) = x;
700 
701  // Postconditions:
702 
703  ensure(id() == primitive_traits<long double>::id());
704  //ensure((*this) == x);
705 
706  // Exit:
707 
708  return;
709 }
710 
714 {
715 
716  // Id:
717 
718  (*this) = x;
719 
720  // Postconditions:
721 
723  //ensure((*this) == x);
724 
725  // Exit:
726 
727  return;
728 }
729 
733 {
734 
735  // Id:
736 
737  (*this) = x;
738 
739  // Postconditions:
740 
742  //ensure((*this) == x);
743 
744  // Exit:
745 
746  return;
747 }
748 
749 // ===========================================================
750 // ASSIGNMENT OPERATORS
751 // ===========================================================
752 
757 {
758  _id = x._id;
759  _value = x._value;
760 
761  return *this;
762 }
763 
764 
768 operator=(void* x)
769 {
771  _value.void_star_primitive = const_cast<void*>(x);
772  return *this;
773 }
774 
778 operator=(const void* x)
779 {
781  _value.void_star_primitive = const_cast<void*>(x);
782  return *this;
783 }
784 
788 operator=(char* x)
789 {
791  _value.c_string_primitive = strdup(x);
792  return *this;
793 }
794 
798 operator=(const char* x)
799 {
801  _value.c_string_primitive = strdup(x);
802  return *this;
803 }
804 
805 
806 template <typename T>
809 operator=(const T& x)
810 {
811  _id = primitive_traits<T>::id();
812  *reinterpret_cast<T*>(&_value) = x;
813  return *this;
814 };
815 
816 // Specialization for string.
817 
818 namespace sheaf
819 {
820 
821 
822 // template <>
823 // SHEAF_DLL_SPEC
824 // sheaf::primitive_value&
825 // sheaf::primitive_value::
826 // operator=(const char* x)
827 // {
828 // _id = primitive_traits<char*>::id();
829 // _value.c_string_primitive = strdup(x);
830 // return *this;
831 // }
832 
833 template <>
834 SHEAF_DLL_SPEC
837 operator=(const std::string& x)
838 {
840  string s(x);
841  _value.c_string_primitive = strdup(s.c_str());
842  return *this;
843 }
844 
845 // Specialization for scoped_index.
846 
847 template <>
848 SHEAF_DLL_SPEC
851 operator=(const scoped_index& x)
852 {
853  (*this) = x.pod();
854  return *this;
855 }
856 
857 // Specialization for namespace_relative_member_index.
858 
859 template <>
860 SHEAF_DLL_SPEC
864 {
865  (*this) = x.pod();
866  return *this;
867 }
868 
869 // Specialization for namespace_relative_subposet_index.
870 
871 template <>
872 SHEAF_DLL_SPEC
876 {
877  (*this) = x.pod();
878  return *this;
879 }
880 
881 // Specialization for poset_path.
882 
883 template <>
884 SHEAF_DLL_SPEC
887 operator=(const poset_path& x)
888 {
890  _value.c_string_primitive = strdup(x.path().c_str());
891  return *this;
892 }
893 
894 #ifndef DOXYGEN_SKIP_PRIMITIVE_INSTANTIATIONS
895 
896 // Explict instantiations for assignment from primitive.
897 
898 template
899 SHEAF_DLL_SPEC
901 
902 template
903 SHEAF_DLL_SPEC
905 
906 template
907 SHEAF_DLL_SPEC
909 
910 template
911 SHEAF_DLL_SPEC
913 
914 template
915 SHEAF_DLL_SPEC
917 
918 template
919 SHEAF_DLL_SPEC
921 
922 template
923 SHEAF_DLL_SPEC
925 
926 template
927 SHEAF_DLL_SPEC
929 
930 template
931 SHEAF_DLL_SPEC
932 sheaf::primitive_value& sheaf::primitive_value::operator=(const unsigned short int& x);
933 
934 template
935 SHEAF_DLL_SPEC
937 
938 template
939 SHEAF_DLL_SPEC
940 sheaf::primitive_value& sheaf::primitive_value::operator=(const unsigned long int& x);
941 
942 template
943 SHEAF_DLL_SPEC
944 sheaf::primitive_value& sheaf::primitive_value::operator=(const unsigned long long int& x);
945 
946 template
947 SHEAF_DLL_SPEC
949 
950 template
951 SHEAF_DLL_SPEC
953 
954 template
955 SHEAF_DLL_SPEC
957 
958 #endif // DOXYGEN_SKIP_PRIMITIVE_INSTANTIATIONS
959 
960 template
961 SHEAF_DLL_SPEC
964 
965 template
966 SHEAF_DLL_SPEC
969 
970 } // namespace sheaf
971 
972 // ===========================================================
973 // CONVERSION TO PRIMITIVE
974 // ===========================================================
975 
976 sheaf::primitive_value::
977 operator bool() const
978 {
979  return _value.bool_primitive;
980 }
981 
982 sheaf::primitive_value::
983 operator char() const
984 {
985  return _value.char_primitive;
986 }
987 
988 sheaf::primitive_value::
989 operator signed char() const
990 {
991  return _value.signed_char_primitive;
992 }
993 
994 sheaf::primitive_value::
995 operator short int() const
996 {
997  return _value.short_int_primitive;
998 }
999 
1000 sheaf::primitive_value::
1001 operator int() const
1002 {
1003  return _value.int_primitive;
1004 }
1005 
1006 sheaf::primitive_value::
1007 operator long int() const
1008 {
1009  return _value.long_int_primitive;
1010 }
1011 
1012 sheaf::primitive_value::
1013 operator long long int() const
1014 {
1015  return _value.long_long_int_primitive;
1016 }
1017 
1018 sheaf::primitive_value::
1019 operator unsigned char() const
1020 {
1021  return _value.unsigned_char_primitive;
1022 }
1023 
1024 sheaf::primitive_value::
1025 operator unsigned short int() const
1026 {
1027  return _value.unsigned_short_int_primitive;
1028 }
1029 
1030 sheaf::primitive_value::
1031 operator unsigned int() const
1032 {
1033  return _value.unsigned_int_primitive;
1034 }
1035 
1036 sheaf::primitive_value::
1037 operator unsigned long int() const
1038 {
1039  return _value.unsigned_long_int_primitive;
1040 }
1041 
1042 sheaf::primitive_value::
1043 operator unsigned long long int() const
1044 {
1045  return _value.unsigned_long_long_int_primitive;
1046 }
1047 
1048 sheaf::primitive_value::
1049 operator float() const
1050 {
1051  return _value.float_primitive;
1052 }
1053 
1054 sheaf::primitive_value::
1055 operator double() const
1056 {
1057  return _value.double_primitive;
1058 }
1059 
1060 sheaf::primitive_value::
1061 operator long double() const
1062 {
1063  return _value.long_double_primitive;
1064 }
1065 
1066 sheaf::primitive_value::
1067 operator void*() const
1068 {
1069  return _value.void_star_primitive;
1070 }
1071 
1072 sheaf::primitive_value::
1073 operator char*() const
1074 {
1075  return _value.c_string_primitive;
1076 }
1077 
1078 sheaf::primitive_value::
1080 {
1081  return _value.namespace_relative_member_index_primitive;
1082 }
1083 
1084 sheaf::primitive_value::
1086 {
1087  return _value.namespace_relative_subposet_index_primitive;
1088 }
1089 
1090 // ===========================================================
1091 // DESTRUCTOR FACET
1092 // ===========================================================
1093 
1096 {
1097  // Nothing to do.
1098  return;
1099 }
1100 
1101 // ===========================================================
1102 // SUPPORT FOR STREAMS FACET
1103 // ===========================================================
1104 
1106 std::string
1108 to_string() const
1109 {
1110  return (*to_string_function(_id))(_value);
1111 }
1112 
1113 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1114 
1116 bool
1118 from_string(const std::string& x)
1119 {
1120  return (*from_string_function(_id))(x, _value);
1121 }
1122 
1123 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
1124 
1125 
1126 
1127 // ===========================================================
1128 // PRIVATE MEMBER FUNCTIONS
1129 // ===========================================================
1130 
1133 sheaf::primitive_value::
1134 make_prototypes()
1135 {
1136 
1137  static block<primitive_value> result(PRIMITIVE_TYPE_END+1);
1138 
1139  // Preconditions:
1140 
1141  if(result.ct() == 0)
1142  {
1143  result[0] = primitive_value();
1144  result[1] = primitive_value();
1145  result[BOOL] = primitive_traits<bool>::default_value();
1146  result[CHAR] = primitive_traits<char>::default_value();
1147 
1148  result[SIGNED_CHAR] = primitive_traits<signed char>::default_value();
1149  result[SHORT_INT] = primitive_traits<short int>::default_value();
1150  result[INT] = primitive_traits<int>::default_value();
1151  result[LONG_INT] = primitive_traits<long int>::default_value();
1152  result[LONG_LONG_INT] = primitive_traits<long long int>::default_value();
1153 
1154  result[UNSIGNED_CHAR] = primitive_traits<unsigned char>::default_value();
1155  result[UNSIGNED_SHORT_INT] = primitive_traits<unsigned short int>::default_value();
1156  result[UNSIGNED_INT] = primitive_traits<unsigned int>::default_value();
1157  result[UNSIGNED_LONG_INT] = primitive_traits<unsigned long int>::default_value();
1158  result[UNSIGNED_LONG_LONG_INT] = primitive_traits<unsigned long long int>::default_value();
1159 
1160  result[FLOAT] = primitive_traits<float>::default_value();
1161  result[DOUBLE] = primitive_traits<double>::default_value();
1162  result[LONG_DOUBLE] = primitive_traits<long double>::default_value();
1163 
1164  result[VOID_STAR] = primitive_traits<void_star>::default_value();
1165  result[C_STRING] = primitive_traits<c_string>::default_value();
1166 
1167  result[NAMESPACE_RELATIVE_MEMBER_INDEX] =
1169 
1170  result[NAMESPACE_RELATIVE_SUBPOSET_INDEX] =
1172 
1173  result[PRIMITIVE_TYPE_END] = primitive_value();
1174 
1175  result.set_ct(PRIMITIVE_TYPE_END+1);
1176  }
1177 
1178  return result;
1179 }
1180 
1181 // ===========================================================
1182 // NON-MEMBER FUNCTIONS
1183 // ===========================================================
1184 
1185 bool
1186 sheaf::
1187 operator==(const primitive_value& xpv1, const primitive_value& xpv2)
1188 {
1189  bool result;
1190 
1191  // Preconditions:
1192 
1193  // Body:
1194 
1195  result = (xpv1._id == xpv2._id);
1196 
1197  if(result)
1198  {
1199  switch(xpv1._id)
1200  {
1201  case BOOL:
1202  result = result && xpv1._value.bool_primitive == xpv2._value.bool_primitive;
1203  break;
1204  case CHAR:
1205  result = result && xpv1._value.char_primitive == xpv2._value.char_primitive;
1206  break;
1207  case SIGNED_CHAR:
1208  result = result && xpv1._value.signed_char_primitive == xpv2._value.signed_char_primitive;
1209  break;
1210  case SHORT_INT:
1211  result = result && xpv1._value.short_int_primitive == xpv2._value.short_int_primitive;
1212  break;
1213  case INT:
1214  result = result && xpv1._value.int_primitive == xpv2._value.int_primitive;
1215  break;
1216  case LONG_INT:
1217  result = result && xpv1._value.long_int_primitive == xpv2._value.long_int_primitive;
1218  break;
1219  case LONG_LONG_INT:
1220  result = result && xpv1._value.long_long_int_primitive == xpv2._value.long_long_int_primitive;
1221  break;
1222  case UNSIGNED_CHAR:
1223  result = result && xpv1._value.unsigned_char_primitive == xpv2._value.unsigned_char_primitive;
1224  break;
1225  case UNSIGNED_SHORT_INT:
1226  result = result && xpv1._value.unsigned_short_int_primitive == xpv2._value.unsigned_short_int_primitive;
1227  break;
1228  case UNSIGNED_INT:
1229  result = result && xpv1._value.unsigned_int_primitive == xpv2._value.unsigned_int_primitive;
1230  break;
1231  case UNSIGNED_LONG_INT:
1232  result = result && xpv1._value.unsigned_long_int_primitive == xpv2._value.unsigned_long_int_primitive;
1233  break;
1234  case UNSIGNED_LONG_LONG_INT:
1235  result = result && xpv1._value.unsigned_long_long_int_primitive == xpv2._value.unsigned_long_long_int_primitive;
1236  break;
1237  case FLOAT:
1238  result = result && xpv1._value.float_primitive == xpv2._value.float_primitive;
1239  break;
1240  case DOUBLE:
1241  result = result && xpv1._value.double_primitive == xpv2._value.double_primitive;
1242  break;
1243  case LONG_DOUBLE:
1244  result = result && xpv1._value.long_double_primitive == xpv2._value.long_double_primitive;
1245  break;
1246  case VOID_STAR:
1247  result = result && xpv1._value.void_star_primitive == xpv2._value.void_star_primitive;
1248  break;
1249  case C_STRING:
1250  result = result && xpv1._value.c_string_primitive == xpv2._value.c_string_primitive;
1251  break;
1252  case NAMESPACE_RELATIVE_MEMBER_INDEX:
1253  result = result && xpv1._value.namespace_relative_member_index_primitive == xpv2._value.namespace_relative_member_index_primitive;
1254  break;
1255  case NAMESPACE_RELATIVE_SUBPOSET_INDEX:
1256  result = result && xpv1._value.namespace_relative_subposet_index_primitive == xpv2._value.namespace_relative_subposet_index_primitive;
1257  break;
1258  }
1259  }
1260 
1261  // Postconditions:
1262 
1263  // Exit:
1264 
1265  return result;
1266 }
1267 
1268 bool
1269 sheaf::
1270 operator==(const primitive_value& xpv, const void* xval)
1271 {
1272  return (void*)(xpv) == xval;
1273 }
1274 
1275 bool
1276 sheaf::
1277 operator==(const void* xval, const primitive_value& xpv)
1278 {
1279  return xval == (void*)(xpv);
1280 }
1281 
1282 bool
1283 sheaf::
1284 operator==(const primitive_value& xpv, const char* xval)
1285 {
1286  return strcmp(xpv.value().c_string_primitive, xval) == 0;
1287 }
1288 
1289 bool
1290 sheaf::
1291 operator==(const char* xval, const primitive_value& xpv)
1292 {
1293  return strcmp(xval, xpv.value().c_string_primitive) == 0;
1294 }
1295 
1296 bool
1297 sheaf::
1298 operator==(const primitive_value& xpv, const std::string& xval)
1299 {
1300  return xpv.value().c_string_primitive == xval;
1301 }
1302 
1303 bool
1304 sheaf::
1305 operator==(const std::string& xval, const primitive_value& xpv)
1306 {
1307  return xval == xpv.value().c_string_primitive;
1308 }
1309 
1310 bool
1311 sheaf::
1312 operator==(const primitive_value& xpv, const scoped_index& xval)
1313 {
1314  return (scoped_index&)(xpv) == xval;
1315 }
1316 
1317 bool
1318 sheaf::
1319 operator==(const scoped_index& xval, const primitive_value& xpv)
1320 {
1321  return xval == (scoped_index&)(xpv);
1322 }
1323 
1324 bool
1325 sheaf::
1327 {
1328  return (namespace_relative_member_index&)(xpv) == xval;
1329 }
1330 
1331 bool
1332 sheaf::
1334 {
1335  return xval == (namespace_relative_member_index&)(xpv);
1336 }
1337 
1338 bool
1339 sheaf::
1341 {
1342  return (namespace_relative_subposet_index&)(xpv) == xval;
1343 }
1344 
1345 bool
1346 sheaf::
1348 {
1349  return xval == (namespace_relative_subposet_index&)(xpv);
1350 }
1351 
1352 bool
1353 sheaf::
1354 operator==(const primitive_value& xpv, const bool& xval)
1355 {
1356  return (bool)(xpv) == xval;
1357 }
1358 
1359 bool
1360 sheaf::
1361 operator==(const bool& xval, const primitive_value& xpv)
1362 {
1363  return xval == (bool)(xpv);
1364 }
1365 
1366 bool
1367 sheaf::
1368 operator==(const primitive_value& xpv, const char& xval)
1369 {
1370  return (char)(xpv) == xval;
1371 }
1372 
1373 bool
1374 sheaf::
1375 operator==(const char& xval, const primitive_value& xpv)
1376 {
1377  return xval == (char)(xpv);
1378 }
1379 
1380 bool
1381 sheaf::
1382 operator==(const primitive_value& xpv, const signed char& xval)
1383 {
1384  return (signed char)(xpv) == xval;
1385 }
1386 
1387 bool
1388 sheaf::
1389 operator==(const signed char& xval, const primitive_value& xpv)
1390 {
1391  return xval == (signed char)(xpv);
1392 }
1393 
1394 bool
1395 sheaf::
1396 operator==(const primitive_value& xpv, const short int& xval)
1397 {
1398  return (short int)(xpv) == xval;
1399 }
1400 
1401 bool
1402 sheaf::
1403 operator==(const short int& xval, const primitive_value& xpv)
1404 {
1405  return xval == (short int)(xpv);
1406 }
1407 
1408 bool
1409 sheaf::
1410 operator==(const primitive_value& xpv, const int& xval)
1411 {
1412  return (int)(xpv) == xval;
1413 }
1414 
1415 bool
1416 sheaf::
1417 operator==(const int& xval, const primitive_value& xpv)
1418 {
1419  return xval == (int)(xpv);
1420 }
1421 
1422 bool
1423 sheaf::
1424 operator==(const primitive_value& xpv, const long int& xval)
1425 {
1426  return (long int)(xpv) == xval;
1427 }
1428 
1429 bool
1430 sheaf::
1431 operator==(const long int& xval, const primitive_value& xpv)
1432 {
1433  return xval == (long int)(xpv);
1434 }
1435 
1436 bool
1437 sheaf::
1438 operator==(const primitive_value& xpv, const long long int& xval)
1439 {
1440  return (long long int)(xpv) == xval;
1441 }
1442 
1443 bool
1444 sheaf::
1445 operator==(const long long int& xval, const primitive_value& xpv)
1446 {
1447  return xval == (long long int)(xpv);
1448 }
1449 
1450 bool
1451 sheaf::
1452 operator==(const primitive_value& xpv, const unsigned char& xval)
1453 {
1454  return (unsigned char)(xpv) == xval;
1455 }
1456 
1457 bool
1458 sheaf::
1459 operator==(const unsigned char& xval, const primitive_value& xpv)
1460 {
1461  return xval == (unsigned char)(xpv);
1462 }
1463 
1464 bool
1465 sheaf::
1466 operator==(const primitive_value& xpv, const unsigned short int& xval)
1467 {
1468  return (unsigned short int)(xpv) == xval;
1469 }
1470 
1471 bool
1472 sheaf::
1473 operator==(const unsigned short int& xval, const primitive_value& xpv)
1474 {
1475  return xval == (unsigned short int)(xpv);
1476 }
1477 
1478 bool
1479 sheaf::
1480 operator==(const primitive_value& xpv, const unsigned int& xval)
1481 {
1482  return (unsigned int)(xpv) == xval;
1483 }
1484 
1485 bool
1486 sheaf::
1487 operator==(const unsigned int& xval, const primitive_value& xpv)
1488 {
1489  return xval == (unsigned int)(xpv);
1490 }
1491 
1492 bool
1493 sheaf::
1494 operator==(const primitive_value& xpv, const unsigned long int& xval)
1495 {
1496  return (unsigned long int)(xpv) == xval;
1497 }
1498 
1499 bool
1500 sheaf::
1501 operator==(const unsigned long int& xval, const primitive_value& xpv)
1502 {
1503  return xval == (unsigned long int)(xpv);
1504 }
1505 
1506 bool
1507 sheaf::
1508 operator==(const primitive_value& xpv, const unsigned long long& xval)
1509 {
1510  return (unsigned long long)(xpv) == xval;
1511 }
1512 
1513 bool
1514 sheaf::
1515 operator==(const unsigned long long& xval, const primitive_value& xpv)
1516 {
1517  return xval == (unsigned long long)(xpv);
1518 }
1519 
1520 bool
1521 sheaf::
1522 operator==(const primitive_value& xpv, const float& xval)
1523 {
1524  return (float)(xpv) == xval;
1525 }
1526 
1527 bool
1528 sheaf::
1529 operator==(const float& xval, const primitive_value& xpv)
1530 {
1531  return xval == (float)(xpv);
1532 }
1533 
1534 bool
1535 sheaf::
1536 operator==(const primitive_value& xpv, const double& xval)
1537 {
1538  return (double)(xpv) == xval;
1539 }
1540 
1541 bool
1542 sheaf::
1543 operator==(const double& xval, const primitive_value& xpv)
1544 {
1545  return xval == (double)(xpv);
1546 }
1547 
1548 bool
1549 sheaf::
1550 operator==(const primitive_value& xpv, const long double& xval)
1551 {
1552  return (long double)(xpv) == xval;
1553 }
1554 
1555 bool
1556 sheaf::
1557 operator==(const long double& xval, const primitive_value& xpv)
1558 {
1559  return xval == (long double)(xpv);
1560 }
1561 
1562 bool
1563 sheaf::
1565 {
1566  return (namespace_relative_member_index_pod_type)(xpv) == xval;
1567 }
1568 
1569 bool
1570 sheaf::
1572 {
1573  return xval == (namespace_relative_member_index_pod_type)(xpv);
1574 }
1575 
1576 bool
1577 sheaf::
1579 {
1580  return (namespace_relative_subposet_index_pod_type)(xpv) == xval;
1581 }
1582 
1583 bool
1584 sheaf::
1586 {
1587  return xval == (namespace_relative_subposet_index_pod_type)(xpv);
1588 }
1589 
1590 
1591 std::ostream&
1592 sheaf::
1593 operator << (std::ostream& xos, const primitive_value& xpv)
1594 {
1595  xos << xpv.to_string();
1596  return xos;
1597 }
1598 
1599 
1600 size_t
1601 sheaf::
1602 deep_size(const primitive_value& xpv, bool xinclude_shallow)
1603 {
1604  size_t result;
1605 
1606  // Preconditions:
1607 
1608  // Body:
1609 
1612 
1613  result = 0;
1614 
1615  // Postconditions:
1616 
1617  ensure(result == 0);
1618  //ensure(result >= 0);
1619 
1620  // Exit
1621 
1622  return result;
1623 }
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.
Definition: scoped_index.h:672
~primitive_value()
Destructor.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
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.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
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.
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.
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.
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.
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.
Definition: poset_path.cc:450
An auto_block with a no-initialization initialization policy.