AttributeSet.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef _Attribute_Set_h_
00042 #define _Attribute_Set_h_
00043
00044 #include <stdint.h>
00045 #include <string.h>
00046
00047 #include "boost/mpl/is_sequence.hpp"
00048 #include "boost/mpl/vector.hpp"
00049 #include "boost/mpl/find_if.hpp"
00050 #include "boost/mpl/void.hpp"
00051 #include "boost/mpl/placeholders.hpp"
00052 #include "boost/mpl/deref.hpp"
00053 #include "boost/mpl/eval_if.hpp"
00054
00055 #include "assert/staticerror.h"
00056
00057 #include "object/PlacementNew.h"
00058
00059 #include "mw/attributes/detail/AttributeSetImpl.h"
00060 #include "mw/attributes/detail/find.h"
00061 #include "mw/attributes/detail/AttributeSize.h"
00062 #include "mw/attributes/detail/Duplicates.h"
00063 #include "mw/attributes/detail/AttributeCompileErrors.h"
00064
00065 #include "mw/attributes/access/Attribute_RT.h"
00066 #include "mw/attributes/access/AttributeSet_RT.h"
00067 #include "mw/attributes/access/AttributeSetHeader_RT.h"
00068
00069 #include "mw/attributes/Null.h"
00070 #include "mw/attributes/type_traits/is_same_base_type.h"
00071
00072 namespace famouso {
00073 namespace mw {
00074 namespace attributes {
00075
00083 template <typename AttrSeq = boost::mpl::vector<> >
00084 struct AttributeSet : public famouso::mw::attributes::access::AttributeSet_RT {
00085 private:
00086
00087 FAMOUSO_STATIC_ASSERT_ERROR(
00088 (boost::mpl::is_sequence<AttrSeq>::value),
00089 no_forward_sequence_given,
00090 (AttrSeq));
00091
00092
00093 typedef detail::Duplicates<AttrSeq> duplicateTester;
00094
00095
00096
00097
00098 FAMOUSO_STATIC_ASSERT_ERROR(
00099 (!duplicateTester::result),
00100 duplicate_attribute_detected_in_sequence,
00101 (typename duplicateTester::duplicateAttribute, AttrSeq));
00102
00103
00104 typedef detail::AttributeSetImpl<AttrSeq> impl;
00105
00106
00107
00108 static const uint16_t contentSize = impl::size;
00109
00110 public:
00114 typedef AttributeSet type;
00115
00119 typedef AttrSeq sequence;
00120
00121 private:
00122
00123
00124 static const bool extension = (contentSize > 0x7F);
00125
00126
00127 typedef typename boost::mpl::eval_if_c<
00128 extension,
00129 detail::ExtendedSequenceBoundError<contentSize>,
00130 detail::UnextendedSequenceBoundError<contentSize>
00131 >::type assertDummy;
00132
00133
00134
00135 static const uint8_t headerSize = (extension ? 2 : 1);
00136
00137 public:
00144 static const uint16_t overallSize = headerSize + contentSize;
00145
00146 private:
00151 uint8_t data[overallSize];
00152
00153 public:
00158 AttributeSet() {
00159
00160
00161 writeSize(contentSize, extension);
00162
00163
00164
00165 impl::construct(&data[headerSize]);
00166 }
00167
00177 template <typename Attr>
00178 struct find_ct {
00179 private:
00180
00181 typedef famouso::mw::attributes::type_traits::is_same_base_type<
00182 boost::mpl::_1,
00183 Attr
00184 > pred;
00185
00186
00187 typedef typename boost::mpl::find_if<
00188 sequence,
00189 pred
00190 >::type found;
00191
00192
00193 template <typename Found, bool dummy>
00194 struct helper {
00195 typedef Found type;
00196 };
00197 template <bool dummy>
00198 struct helper<boost::mpl::void_, dummy> {
00199 typedef Null type;
00200 };
00201
00202 public:
00203 typedef typename helper<
00204 typename boost::mpl::deref<found>::type,
00205 true
00206 >::type type;
00207 };
00208
00209 };
00210
00211 }
00212 }
00213 }
00214
00215
00216 #endif // _Attribute_Set_