Vcsn  2.1
Be Rational
getargs.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 
5 #include <boost/range/adaptor/map.hpp>
6 #include <boost/range/algorithm/copy.hpp>
7 
8 #include <vcsn/misc/export.hh>
9 #include <vcsn/misc/raise.hh>
10 
11 namespace vcsn LIBVCSN_API
12 {
13 
19  template <typename C>
20  typename C::mapped_type
21  getargs(const std::string& kind, const C& map, const std::string& key)
22  {
23  auto i = map.find(key);
24  if (i == end(map))
25  {
26  std::ostringstream o;
27  // Retrieve all keys
28  boost::copy(map | boost::adaptors::map_keys,
29  std::ostream_iterator<std::string>(o, " "));
30  raise("invalid ", kind, ": ", key, ", expected: ", o.str());
31  }
32  else
33  return i->second;
34  }
35 }
C::mapped_type getargs(const std::string &kind, const C &map, const std::string &key)
Find a correspondance in a map.
Definition: getargs.hh:21
AutOut copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans)
A copy of input keeping only its states that are accepted by keep_state.
Definition: copy.hh:254
#define LIBVCSN_API
Definition: export.hh:8