ed
json_reader.h
Go to the documentation of this file.
1 #ifndef ED_IO_JSON_READER_H_
2 #define ED_IO_JSON_READER_H_
3 
4 #include "ed/io/reader.h"
5 #include "ed/io/data.h"
6 
7 #include <sstream>
8 #include <vector>
9 
10 namespace ed
11 {
12 
13 namespace io
14 {
15 
16 class JSONReader : public ed::io::Reader
17 {
18 
19 public:
20 
21  JSONReader(const char* s);
22 
23  virtual ~JSONReader();
24 
25  bool readGroup(const std::string& name);
26  bool endGroup();
27 
28  bool readArray(const std::string& name);
29  bool endArray();
30 
31  bool nextArrayItem();
32 
33  bool readValue(const std::string&, float& f);
34  bool readValue(const std::string&, double& d);
35  bool readValue(const std::string&, int& i);
36  bool readValue(const std::string&, std::string& s);
37 
38  bool ok() { return error_.empty(); }
39 
40  std::string error() { return error_; }
41 
42 private:
43 
47 
49 
50  template<typename T>
51  bool value(const std::string& key, T& value) const
52  {
55  if (it == map.end())
56  return false;
57 
58  const Variant& v = data_.values[it->second.idx];
59 
60  if (!v.getValue(value))
61  return false;
62 
63  return true;
64  }
65 
66 };
67 
68 }
69 
70 }
71 
72 #endif
sstream
std::string
ed::io::JSONReader::value
bool value(const std::string &key, T &value) const
Definition: json_reader.h:51
ed::io::JSONReader
Definition: json_reader.h:16
vector
std::map::find
T find(T... args)
ed::io::Data::values
std::vector< Variant > values
Definition: data.h:46
ed::io::JSONReader::~JSONReader
virtual ~JSONReader()
Definition: json_reader.cpp:122
ed::io::JSONReader::JSONReader
JSONReader(const char *s)
Definition: json_reader.cpp:105
ed::io::JSONReader::nextArrayItem
bool nextArrayItem()
Definition: json_reader.cpp:185
ed::io::JSONReader::readValue
bool readValue(const std::string &, float &f)
Definition: json_reader.cpp:214
ed::io::JSONReader::readArray
bool readArray(const std::string &name)
Definition: json_reader.cpp:150
ed::io::JSONReader::readGroup
bool readGroup(const std::string &name)
Definition: json_reader.cpp:128
ed::io::JSONReader::n_current_
Node n_current_
Definition: json_reader.h:45
ed::io::Variant::getValue
bool getValue(int &v) const
Definition: io/variant.h:27
ed::io::JSONReader::ok
bool ok()
Definition: json_reader.h:38
ed::io::Reader
Definition: reader.h:14
reader.h
ed::io::JSONReader::data_
Data data_
Definition: json_reader.h:44
ed::io::JSONReader::error
std::string error()
Definition: json_reader.h:40
std::map
ed::io::Node::idx
unsigned int idx
Definition: data.h:32
ed::io::Node
Definition: data.h:27
ed::io::Variant
Definition: io/variant.h:15
ed::io::Data
Definition: data.h:38
ed::io::JSONReader::endArray
bool endArray()
Definition: json_reader.cpp:165
ed::io::JSONReader::endGroup
bool endGroup()
Definition: json_reader.cpp:141
ed::io::JSONReader::error_
std::string error_
Definition: json_reader.h:48
ed::io::Data::maps
std::vector< std::map< std::string, Node > > maps
Definition: data.h:43
data.h
std::string::empty
T empty(T... args)
ed
Definition: convex_hull.h:8
std::map::end
T end(T... args)
ed::io::JSONReader::array_index_stack_
std::vector< unsigned int > array_index_stack_
Definition: json_reader.h:46