12#ifndef DOXYGEN_SHOULD_SKIP_THIS
14 template<
typename T,
typename... Rest>
15 struct is_all : std::false_type {
18 template<
typename T,
typename First>
19 struct is_all<T, First> : std::is_same<T, First> {
22 template<
typename T,
typename First,
typename... Rest>
23 struct is_all<T, First, Rest...>
24 : std::integral_constant<bool, std::is_same<T, First>::value && is_all<T, Rest...>::value> {
27 template<
typename T,
typename... Rest>
28 struct is_any : std::false_type {
31 template<
typename T,
typename First>
32 struct is_any<T, First> : std::is_same<T, First> {
35 template<
typename T,
typename First,
typename... Rest>
36 struct is_any<T, First, Rest...>
37 : std::integral_constant<bool, std::is_same<T, First>::value || is_any<T, Rest...>::value> {
41 typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
42 almost_equal(T x, T y,
int ulp) {
45 return std::fabs(x - y) <= std::numeric_limits<T>::epsilon() * std::fabs(x + y) * ulp
47 || std::fabs(x - y) < std::numeric_limits<T>::min();
52 template <
typename T>
class Iter;
72 template <
typename T,
typename PTR = std::shared_ptr<T>>
73 class Dict :
public std::list<std::pair<std::string, PTR>>
83 typename std::enable_if < std::is_integral<I>::value && !std::is_pointer<I>::value,
const PairType &>::type
89 typename std::enable_if < std::is_same<N, std::string>::value || std::is_pointer<N>::value,
const PairType &>::type
95 ListType::push_back(p);
111 return std::pair<std::string, Type>(
name, value);
122 typename ListType::iterator
find(
const std::string_view
name) {
123 auto iter = ListType::begin();
124 while (iter != ListType::end()) {
125 if (iter->first.compare(
name.begin()) == 0) {
130 return ListType::end();
139 if (iter != ListType::end()) {
145 virtual const std::string &
name(
const int64_t
index)
const {
149 virtual int64_t
index(
const std::string_view field_name) {
150 typename ListType::iterator found =
find(field_name.begin());
151 if (found == ListType::end()) {
154 return std::distance(ListType::begin(), found);
161 virtual int64_t
resize(int64_t new_size,
const Type fill,
const std::string &
name =
"") {
164 ListType::resize(new_size, std::pair<std::string, Type>(
name, fill));
167 new_size = -new_size;
168 if (
static_cast<int64_t
> (ListType::size()) > new_size) {
170 ListType::erase(ListType::begin(),
at_index(ListType::size() - new_size));
172 }
else if (
static_cast<int64_t
> (ListType::size()) < new_size) {
173 ListType::insert(ListType::begin(), (ListType::size() - new_size), std::pair<std::string, Type>(
name, fill));
178 return ListType::size();
183 if (-
index <=
static_cast<int64_t
> (ListType::size())) {
184 int64_t pos =
index + 1;
185 typename ListType::iterator iter = ListType::end();
186 while (iter != ListType::begin()) {
196 typename ListType::iterator iter = ListType::begin();
197 while (iter != ListType::end()) {
210 if (-
index <
static_cast<int64_t
> (ListType::size())) {
211 int64_t pos =
index + 1;
212 typename ListType::const_iterator iter = ListType::end();
213 while (iter != ListType::begin()) {
223 typename ListType::const_iterator iter = ListType::begin();
224 while (iter != ListType::end()) {
239 virtual void erase(
const size_t index_from,
const size_t index_to) {
240 if (index_from <= index_to) {
241 if (index_from == index_to) {
242 if (index_from < ListType::size()) {
243 ListType::erase(
at_index(index_from));
246 ListType::erase(
at_index(index_from), (index_to < ListType::size() ?
at_index(index_to) : ListType::end()));
249 ASSERT(index_to < index_from);
250 ListType::erase(
at_index(index_to), ListType::end());
251 ListType::erase(ListType::begin(), (index_from < ListType::size() ?
at_index(index_from) : ListType::end()));
266 push_front(arg.second, arg.first);
270 push_front(arg.second, arg.first);
std::pair< std::string, Type > PairType
ListType::iterator find(const std::string_view name)
virtual int64_t index(const std::string_view field_name)
virtual PairType & at(const std::string name)
PairType & push_back(const Type value, const std::string &name="")
virtual int64_t resize(int64_t new_size, const Type fill, const std::string &name="")
PairType & push_back(const PairType &p)
Dict(PairType arg, A... rest)
virtual const std::string & name(const int64_t index) const
std::enable_if< std::is_integral< I >::value &&!std::is_pointer< I >::value, constPairType & >::type operator[](I index)
ListType::const_iterator at_index_const(const int64_t index) const
ListType::iterator at_index(const int64_t index)
static PairType pair(const Type value, const std::string name="")
virtual PairType & at(const int64_t index)
std::list< PairType > ListType
virtual const PairType & at(const int64_t index) const
virtual void erase(const int64_t index)
virtual void erase(const size_t index_from, const size_t index_to)
std::enable_if< std::is_same< N, std::string >::value||std::is_pointer< N >::value, constPairType & >::type operator[](N name)
#define LOG_RUNTIME(format,...)
#define ASSERT(condition)