6#include <bond/core/config.h>
11#include <bond/core/bond_types.h>
21template <
typename SignedT>
23typename boost::enable_if<is_signed_int_or_enum<SignedT>,
bool>::type
26 BOOST_ASSERT(!variant.nothing);
27 return value ==
static_cast<SignedT
>(variant.int_value);
33template <
typename Un
signedT>
35typename boost::enable_if<std::is_unsigned<UnsignedT>,
bool>::type
38 BOOST_ASSERT(!variant.nothing);
39 return value ==
static_cast<UnsignedT
>(variant.uint_value);
48 BOOST_ASSERT(!variant.nothing);
49 BOOST_STATIC_ASSERT((std::is_unsigned<bool>::value));
51 return value == !!variant.uint_value;
60 BOOST_ASSERT(!variant.nothing);
61 return value == variant.double_value;
70 BOOST_ASSERT(!variant.nothing);
71 return value == variant.string_value;
78operator==(
const Variant& variant,
const std::string& value)
80 BOOST_ASSERT(!variant.nothing);
81 return value == variant.string_value;
90 BOOST_ASSERT(!variant.nothing);
91 return value == variant.wstring_value;
98operator==(
const Variant& variant,
const std::wstring& value)
100 BOOST_ASSERT(!variant.nothing);
101 return value == variant.wstring_value;
112typename boost::enable_if<std::is_unsigned<T> >::type
113VariantSet(bond::Variant& variant,
const T& value)
115 variant.uint_value = value;
121typename boost::enable_if<is_signed_int_or_enum<T> >::type
122VariantSet(bond::Variant& variant,
const T& value)
124 variant.int_value =
static_cast<int64_t
>(value);
129VariantSet(bond::Variant& variant,
const char* value)
131 variant.string_value = value;
136VariantSet(bond::Variant& variant,
const wchar_t* value)
138 variant.wstring_value = value;
142VariantSet(bond::Variant& variant,
const double& value)
144 variant.double_value = value;
151VariantGet(
const bond::Variant& variant,
bool& var)
153 BOOST_ASSERT(!variant.nothing);
154 var = !!variant.uint_value;
160typename boost::enable_if<std::is_unsigned<T> >::type
161VariantGet(
const bond::Variant& variant, T& var)
163 BOOST_ASSERT(!variant.nothing);
164 var =
static_cast<T
>(variant.uint_value);
170typename boost::enable_if<is_signed_int_or_enum<T> >::type
171VariantGet(
const bond::Variant& variant, T& var)
173 BOOST_ASSERT(!variant.nothing);
174 var =
static_cast<T
>(variant.int_value);
180typename boost::enable_if<std::is_floating_point<T> >::type
181VariantGet(
const bond::Variant& variant, T& var)
183 BOOST_ASSERT(!variant.nothing);
184 var =
static_cast<T
>(variant.double_value);
190typename boost::enable_if<is_string<T> >::type
191VariantGet(
const bond::Variant& variant, T& var)
193 BOOST_ASSERT(!variant.nothing);
195 const size_t size = variant.string_value.size();
196 resize_string(var,
static_cast<uint32_t
>(size));
199 variant.string_value.begin(),
200 variant.string_value.end(),
201 detail::make_checked_array_iterator(string_data(var), size));
207typename boost::enable_if<is_wstring<T> >::type
208VariantGet(
const bond::Variant& variant, T& var)
210 BOOST_ASSERT(!variant.nothing);
212 const size_t size = variant.wstring_value.size();
213 resize_string(var,
static_cast<uint32_t
>(size));
216 variant.wstring_value.begin(),
217 variant.wstring_value.end(),
218 detail::make_checked_array_iterator(string_data(var), size));
225typename boost::disable_if<std::is_enum<T>,
const char*>::type
226GetTypeName(T,
const qualified_name_tag&)
228 switch (get_type_id<T>::value)
230 case BT_BOOL:
return "bool";
231 case BT_UINT8:
return "uint8";
232 case BT_UINT16:
return "uint16";
233 case BT_UINT32:
return "uint32";
234 case BT_UINT64:
return "uint64";
235 case BT_FLOAT:
return "float";
236 case BT_DOUBLE:
return "double";
237 case BT_INT8:
return "int8";
238 case BT_INT16:
return "int16";
239 case BT_INT32:
return "int32";
240 case BT_INT64:
return "int64";
241 default: BOOST_ASSERT(
false);
242 return "unknown_type";
249typename boost::enable_if<std::is_enum<T>,
const char*>::type
250GetTypeName(T e,
const qualified_name_tag&)
254 return GetTypeName(e);
259template <
typename T,
typename Enable =
void>
262 static std::string name()
264 return GetTypeName(T(), qualified_name);
270struct type<T, typename boost::enable_if<std::is_class<typename T::Schema::methods> >::type>
272 static std::string name()
274 return T::Schema().metadata.qualified_name;
280struct type<T, typename boost::enable_if<is_string<T> >::type>
282 static std::string name()
291struct type<T, typename boost::enable_if<is_wstring<T> >::type>
293 static std::string name()
302struct type<blob, void>
304 static std::string name()
313struct type<T, typename boost::enable_if<is_list_container<T> >::type>
315 static std::string name()
317 return "list<" + type<typename element_type<T>::type>::name() +
">";
324struct type<T, typename boost::enable_if<is_set_container<T> >::type>
326 static std::string name()
328 return "set<" + type<typename element_type<T>::type>::name() +
">";
335struct type<T, typename boost::enable_if<is_map_container<T> >::type>
337 static std::string name()
339 return "map<" + type<typename element_type<T>::type::first_type>::name() +
", "
340 + type<typename element_type<T>::type::second_type>::name() +
">";
347struct type<bonded<T> >
349 static std::string name()
351 return "bonded<" + type<T>::name() +
">";
358struct type<maybe<T> >
360 static std::string name()
362 return type<T>::name();
369struct type<T, typename boost::enable_if<has_schema<T> >::type>
371 static std::string name()
375 return schema<T>::type::GetMetadata().qualified_name;
384 TypeListBuilder(std::string& name)
388 template <
typename T>
389 void operator()(
const T*)
394 _name += type<T>::name();
398 TypeListBuilder& operator=(
const TypeListBuilder&);
namespace bond
Definition: apply.h:17
boost::enable_if< is_signed_int_or_enum< SignedT >, bool >::type operator==(const Variant &variant, SignedT value)
Compares variant for equality against the provided signed integer or enum value.
Definition: metadata.h:24