25 #ifndef __I6ENGINE_API_CONFIGS_ATTRIBUTEMAP_H__
26 #define __I6ENGINE_API_CONFIGS_ATTRIBUTEMAP_H__
30 #include <type_traits>
34 #include "boost/lexical_cast.hpp"
36 #include "boost/archive/text_iarchive.hpp"
37 #include "boost/archive/text_oarchive.hpp"
48 template<
typename U,
void(U::*)(const std::
string &, attributeMap &)const>
55 static const bool value =
sizeof(Test<T>(0)) ==
sizeof(char);
58 template<
class type,
class...Args>
76 typename std::enable_if<std::is_enum<T>::value && !std::is_fundamental<T>::value,
void>::type
parseAttribute(attributeMap::const_iterator it, T & value) {
77 value = T(std::stoul(it->second));
85 value = T(it->second);
92 typename std::enable_if<!std::is_enum<T>::value && !std::is_fundamental<T>::value && !detail::constructible_from<T, const std::string &>::value,
void>::type
parseAttribute(attributeMap::const_iterator it, T & value) {
93 std::stringstream ss(it->second);
94 boost::archive::text_iarchive arch(ss, boost::archive::no_header | boost::archive::no_codecvt | boost::archive::no_xml_tag_checking | boost::archive::archive_flags::no_tracking);
102 typename std::enable_if<!std::is_enum<T>::value && std::is_fundamental<T>::value,
void>::type
parseAttribute(attributeMap::const_iterator it, T & value) {
103 value = boost::lexical_cast<T>(it->second);
110 typename std::enable_if<std::is_enum<T>::value && !std::is_fundamental<T>::value,
void>::type
writeAttribute(attributeMap & params,
const std::string & entry,
const T & value) {
111 params.insert(std::make_pair(entry, std::to_string(
int(value))));
117 template<
bool Required,
typename T>
118 typename std::enable_if<Required, void>::type
parseAttribute(
const attributeMap & params,
const std::string & entry, T & value) {
119 auto it = params.find(entry);
120 if (it == params.end()) {
130 template<
bool Required,
typename T>
131 typename std::enable_if<!Required, void>::type
parseAttribute(
const attributeMap & params,
const std::string & entry, T & value) {
132 auto it = params.find(entry);
133 if (it != params.end()) {
142 typename std::enable_if<!std::is_enum<T>::value && !std::is_fundamental<T>::value && !std::is_same<T, std::string>::value &&
detail::hasInsertInMap<T>::value,
void>::type
writeAttribute(attributeMap & params,
const std::string & entry, T value) {
143 value.insertInMap(entry, params);
150 typename std::enable_if<!std::is_enum<T>::value && !std::is_fundamental<T>::value && (std::is_same<T, std::string>::value || std::is_same<const char, typename std::remove_pointer<T>::type>::value),
void>::type
writeAttribute(attributeMap & params,
const std::string & entry, T value) {
151 params.insert(std::make_pair(entry, value));
158 typename std::enable_if<!std::is_enum<T>::value && std::is_fundamental<T>::value,
void>::type
writeAttribute(attributeMap & params,
const std::string & entry, T value) {
166 typename std::enable_if<!std::is_enum<T>::value && !std::is_fundamental<T>::value && !std::is_same<T, std::string>::value && !std::is_same<const char, typename std::remove_pointer<T>::type>::value && !detail::hasInsertInMap<T>::value,
void>::type
writeAttribute(attributeMap & params,
const std::string & entry, T value) {
167 std::stringstream ss;
168 boost::archive::text_oarchive arch(ss, boost::archive::no_header | boost::archive::no_codecvt | boost::archive::no_xml_tag_checking | boost::archive::archive_flags::no_tracking);
static char Test(SFINAE< U,&U::insertInMap > *)
#define ISIXE_THROW_API(module, message)
std::map< std::string, std::string > attributeMap
std::enable_if< std::is_enum< T >::value &&!std::is_fundamental< T >::value, void >::type parseAttribute(attributeMap::const_iterator it, T &value)
converts a string to enum value
std::enable_if< std::is_enum< T >::value &&!std::is_fundamental< T >::value, void >::type writeAttribute(attributeMap ¶ms, const std::string &entry, const T &value)
writes into an attributeMap
static char constructible_test(U *, decltype(U(arg< Args >()...))*=0)