ALPSCore reference
dict_types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #ifndef ALPS_PARAMS_PARAM_TYPES_HPP_2b33f1b375e64b6fa9adcb68d7de2407
8 #define ALPS_PARAMS_PARAM_TYPES_HPP_2b33f1b375e64b6fa9adcb68d7de2407
9 
10 #include <vector>
11 #include <string>
12 #include <stdexcept>
13 #include <boost/mpl/list/list10.hpp>
14 #include <boost/mpl/transform.hpp>
15 #include <boost/mpl/front_inserter.hpp>
16 #include <boost/mpl/push_front.hpp>
17 #include <boost/mpl/copy.hpp>
18 #include <boost/mpl/contains.hpp>
19 
20 
21 
22 // forward declarations
23 namespace alps{ namespace hdf5 {
24  class archive;
25 }}
26 
27 namespace alps {
28  namespace params_ns {
29  namespace detail {
30 
31  // Have namespaces handy
32  namespace mpl=::boost::mpl;
33  namespace mplh=::boost::mpl::placeholders;
34 
36  struct None {
37  void save(alps::hdf5::archive&) const { throw std::logic_error("None::save() should never be called"); }
38  void load(alps::hdf5::archive&) { throw std::logic_error("None::load() should never be called"); }
39  };
40  template <typename S>
41  inline S& operator<<(S&, const None&) { throw std::logic_error("Generic streaming operator of None should never be called"); }
42 
43  // List of allowed basic scalar types:
44  typedef mpl::list8<bool,
45  int,
46  unsigned int,
47  long int,
48  unsigned long int,
49  float,
50  double,
51  std::string> dict_scalar_types;
52 
53  // // List of allowed pairs: (removed until clarification)
54  // typedef mpl::transform< dict_scalar_types, std::pair<std::string, mplh::_1> >::type dict_pair_types;
55 
56  // List of allowed vectors:
57  typedef mpl::transform< dict_scalar_types, std::vector<mplh::_1> >::type dict_vector_types;
58 
59  // Meta-function returning a new sequence (FS, TS) from sequences FS and TS
60  template <typename FS, typename TS>
61  struct copy_to_front : public mpl::reverse_copy< FS, mpl::front_inserter<TS> > {};
62 
63  // List of allowed types, `None` being the first
64  typedef mpl::push_front<
65  copy_to_front<dict_scalar_types, dict_vector_types>::type,
66  None
67  >::type dict_all_types;
68  // This list includes std::pair, removed until clarification
69  // typedef mpl::push_front<
70  // copy_to_front<dict_scalar_types,
71  // copy_to_front<dict_vector_types, dict_pair_types>::type
72  // >::type,
73  // None
74  // >::type dict_all_types;
75 
76 
77  // Meta-predicate: is type supported
78  // (FIXME?: this is linear compile-time complexity; we can use per-type traits instead)
79  template <typename T>
80  struct is_supported : public boost::mpl::contains<dict_all_types, T> {};
81 
84  template <typename T>
85  struct type_info; /* intentionally not defined for types that are not supported */
86 
87  template <> struct type_info<None> { static std::string pretty_name() { return "None"; } };
88  template <> struct type_info<bool> { static std::string pretty_name() { return "bool"; } };
89  template <> struct type_info<int> { static std::string pretty_name() { return "int"; } };
90  template <> struct type_info<unsigned int> { static std::string pretty_name() { return "unsigned int"; } };
91  template <> struct type_info<long int> { static std::string pretty_name() { return "long int"; } };
92  template <> struct type_info<unsigned long int> { static std::string pretty_name() { return "unsigned long int"; } };
93  template <> struct type_info<float> { static std::string pretty_name() { return "float"; } };
94  template <> struct type_info<double> { static std::string pretty_name() { return "double"; } };
95  template <> struct type_info<std::string> { static std::string pretty_name() { return "std::string"; } };
96 
97  template <typename T>
98  struct type_info< std::vector<T> > {
99  static std::string pretty_name() { return "std::vector<"+type_info<T>::pretty_name()+">"; }
100  };
101 
102  } // ::detail
103  } // ::params_ns
104 }// ::alps
105 
106 
107 #endif /* ALPS_PARAMS_PARAM_TYPES_HPP_2b33f1b375e64b6fa9adcb68d7de2407 */
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
Definition: archive.hpp:309
STL namespace.
std::enable_if< has_complex_elements< typename alps::detail::remove_cvr< T >::type >::value, archive & >::type operator<<(archive &ar, detail::make_pvp_proxy< T > const &proxy)
Definition: archive.hpp:388
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
Definition: archive.hpp:292