3#include <Covellite/Api/Component.hpp>
4#include <boost/core/ignore_unused.hpp>
5#include <alicorn/std.memory.hpp>
33 for (
const auto & Param : _Params)
35 auto & Value = Params[GetHash(Param.first)];
36 Value.hType = Param.second.type().hash_code();
37 Value.Value = Param.second;
40 using Pool_t = ::alicorn::extension::std::pool<>;
42 return Pool_t::make_unique<Component>(Params, ConstructorTag{});
57 static const Hasher_t Hasher;
58 return Hasher(_Value);
76 Id((*this)[GetHashId()].Default(uT(
"Unknown"))),
77 Type((*this)[GetHashType()].Default(uT(
"Unknown"))),
78 Kind((*this)[GetHashKind()].Default(uT(
"Unknown")))
80 ::boost::ignore_unused(_Tag);
93inline bool Component::Param::IsType(
void)
const
95 static const auto hTType =
typeid(T).hash_code();
96 return (this->hType == hTType);
108inline Component::Param & Component::Param::Default(
const T & _Value)
110 if (!::covellite::has_value(this->Value)) Set(_Value);
114template<
typename S,
typename T>
117 template<
typename SS,
typename TT>
118 static auto test(
int) ->
decltype(
119 ::std::declval<SS &>() << ::std::declval<TT>(), ::std::true_type());
121 template<
typename,
typename>
122 static auto test(...) -> ::std::false_type;
125 static const bool value =
decltype(test<S, T>(0))::value;
129class Component::Convertor
133 static T To(
const String_t &)
143class Component::Convertor<true>
147 inline static T To(
const String_t & _Value)
149 return ::boost::lexical_cast<T>(_Value);
169Component::Param::operator T & (void)
173 return ::covellite::any_cast<T &>(this->Value);
175 catch (const ::std::exception &)
180 if (IsType<String_t>())
182 using TType_t = typename ::std::remove_const<T>::type;
184 constexpr auto IsConvertable =
185 !::std::is_pointer<T>::value &&
186 !::std::is_reference<T>::value &&
187 is_streamable<::std::iostream, TType_t>::value;
189 Set(Convertor<IsConvertable>::template To<TType_t>(
190 ::covellite::any_cast<const String_t &>(this->Value)));
193 return ::covellite::any_cast<T &>(this->Value);
197Component::Param::operator
const T & (void)
const
199 return ::covellite::any_cast<const T &>(this->Value);
215Component::Param & Component::Param::operator= (
const T & _Value)
220 TODO(
"Убрать оптимизацию присваивания по ссылке для std::any");
225 ::covellite::any_cast<T &>(this->Value) = _Value;
228 catch (const ::std::exception &)
238inline void Component::Param::Set(
const T & _Value)
240 static const auto hTType =
typeid(T).hash_code();
242 this->Value = _Value;
243 this->hType = hTType;
255 return (*
this)[
GetHash(_Name)];
267 return m_Params[_Hash];
282 return (*
this)[
GetHash(_Name)];
297 const auto itParam = m_Params.find(_Hash);
298 if (itParam == ::std::end(m_Params))
300 throw STD_EXCEPTION <<
"Unknown parameter: " << _Hash;
303 return itParam->second;
306inline size_t Component::GetHashId(
void)
308 static const size_t Hash =
GetHash(uT(
"id"));
312inline size_t Component::GetHashType(
void)
314 static const size_t Hash =
GetHash(uT(
"type"));
318inline size_t Component::GetHashKind(
void)
320 static const size_t Hash =
GetHash(uT(
"kind"));
Component(const Params_t &, ConstructorTag)
Конструктор класса.
Definition Component.inl:74
Param & operator[](const Name_t &)
Оператор получения временной переменной для доступа к параметру компонента.
Definition Component.inl:253
static ComponentPtr_t Make(const SourceParams_t &)
Функция создания объектов компонентов.
Definition Component.inl:29
static size_t GetHash(const Name_t &)
Функция получения хеша для имени параметра.
Definition Component.inl:55