19 #include <boost/shared_ptr.hpp>
20 #include <boost/variant.hpp>
21 #include <boost/call_traits.hpp>
22 #include <boost/static_assert.hpp>
29 struct RT {
typedef const X& type; };
30 template<>
struct RT<double> {
typedef double type; };
34 static inline V op() {
return V(); }
37 struct buildval<double> {
38 static inline double op() {
return 0.0; }
43 struct is_config_value {
45 #define IS_CONFIG_VALUE(TYPE) \
46 namespace detail {template<> struct is_config_value<TYPE> { typedef TYPE type; };}
48 IS_CONFIG_VALUE(
double)
49 IS_CONFIG_VALUE(
std::
string)
50 IS_CONFIG_VALUE(
std::vector<
double>)
70 typedef boost::variant<
77 typedef std::vector<Config> vector_t;
79 typedef std::map<std::string, value_t> values_t;
81 typedef boost::shared_ptr<values_t> values_pointer;
82 typedef boost::shared_ptr<const values_t> const_values_pointer;
84 values_pointer values;
85 const_values_pointer implicit_values;
93 Config(
const Config&);
96 Config& operator=(
const Config&);
101 bool tryGetAny(
const std::string& name, value_t& ret)
const;
105 const value_t& getAny(
const std::string& name)
const;
108 void setAny(
const std::string& name,
const value_t& val);
110 void swapAny(
const std::string& name, value_t& val);
122 typename detail::RT<T>::type
123 get(
const std::string& name)
const {
125 return boost::get<typename detail::is_config_value<T>::type>(getAny(name));
126 }
catch(boost::bad_get&) {
127 throw key_error(SB()<<
"Wrong type for '"<<name<<
"'. should be "<<
typeid(T).name());
140 typename detail::RT<T>::type
141 get(
const std::string& name,
typename boost::call_traits<T>::param_type def)
const {
143 return boost::get<typename detail::is_config_value<T>::type>(getAny(name));
144 }
catch(boost::bad_get&) {
145 }
catch(key_error&) {
156 tryGet(
const std::string& name, T& val)
const {
158 if(tryGetAny(name, ret)) {
160 val = boost::get<typename detail::is_config_value<T>::type>(ret);
162 }
catch(boost::bad_get&) {
175 void set(
const std::string& name,
176 typename boost::call_traits<
typename detail::is_config_value<T>::type>::param_type val)
179 (*values)[name] = val;
192 void swap(
const std::string& name,
193 typename boost::call_traits<
typename detail::is_config_value<T>::type>::reference val)
195 value_t temp = detail::buildval<T>::op();
196 val.swap(boost::get<T>(temp));
205 values.swap(c.values);
206 implicit_values.swap(c.implicit_values);
210 void show(std::ostream&,
unsigned indent=0)
const;
218 inline const_iterator
begin()
const {
return values->begin(); }
220 inline const_iterator
end()
const {
return values->end(); }
222 inline void reserve(
size_t) {}
224 Config new_scope()
const;
230 IS_CONFIG_VALUE(std::vector<Config>);
233 std::ostream& operator<<(std::ostream& strm,
const Config& c)
243 std::auto_ptr<Pvt> priv;
293 void GLPSPrint(std::ostream& strm,
const Config&);
296 #undef IS_CONFIG_VALUE
300 #endif // FLAME_CONFIG_H
values_t::iterator iterator
iterator
void setVar(const std::string &name, const Config::value_t &v)
Pre-define variable.
void setPrinter(std::ostream *)
Set output for lexer/parser error messages.
void set(const std::string &name, typename boost::call_traits< typename detail::is_config_value< T >::type >::param_type val)
Interface to lattice file parser.
void swap(const std::string &name, typename boost::call_traits< typename detail::is_config_value< T >::type >::reference val)
GLPSParser()
Construct an empty parser context.
Associative configuration container.
void show(std::ostream &, unsigned indent=0) const
Print listing of inner scope.
Config * parse_file(const char *fname)
Open and parse a file.
boost::variant< double, std::vector< double >, std::string, std::vector< Config > > value_t
An individual value (double, double[], string, or Config[])
const_iterator end() const
one after the last element
void swap(Config &c)
Exchange entire Config.
bool tryGet(const std::string &name, T &val) const
values_t::const_iterator const_iterator
const_iterator
Config * parse_byte(const char *s, size_t len, const char *path=NULL)
Parse from byte buffer.
const_iterator begin() const
The first element.