Choreonoid  1.8
YAMLReader.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_YAML_READER_H
6 #define CNOID_UTIL_YAML_READER_H
7 
8 #include "ValueTree.h"
9 #include "exportdecl.h"
10 
11 namespace cnoid {
12 
13 class YAMLReaderImpl;
14 
15 class CNOID_EXPORT YAMLReader
16 {
17  class MappingFactoryBase {
18  public:
19  virtual Mapping* create(int line, int column) = 0;
20  virtual ~MappingFactoryBase() { }
21  };
22 
23  template <class MappingType> class MappingFactory : public MappingFactoryBase {
24  public:
25  virtual Mapping* create(int line, int column) { return new MappingType(line, column); }
26  };
27 
28 public:
29 
30  YAMLReader();
31  ~YAMLReader();
32 
33  template <class TMapping> inline void setMappingClass() {
34  setMappingFactory(new MappingFactory<TMapping>());
35  }
36 
37  void expectRegularMultiListing();
38 #ifdef CNOID_BACKWARD_COMPATIBILITY
39  void expectRegularMultiSequence() { expectRegularMultiListing(); }
40  bool load_string(const std::string& yamlstring) { return parse(yamlstring); }
41 #endif
42 
43  bool load(const std::string& filename);
44  bool parse(const std::string& yamlstring);
45  bool parse(const char* input, size_t size);
46 
47  ValueNode* loadDocument(const std::string& filename);
48 
49  int numDocuments();
50  ValueNode* document(int index = 0);
51 
52  ValueNode* findAnchoredNode(const std::string& anchor);
53  void importAnchors(const YAMLReader& anotherReader);
54 
55  void clearDocuments();
56 
57  const std::string& errorMessage();
58 
59 private:
60 
61  friend class YAMLReaderImpl;
62 
63  YAMLReaderImpl* impl;
64 
65  void setMappingFactory(MappingFactoryBase* factory);
66 };
67 
68 #ifdef CNOID_BACKWARD_COMPATIBILITY
69 typedef YAMLReader YamlReader;
70 #endif
71 
72 }
73 
74 #endif
cnoid::YAMLReader
Definition: YAMLReader.h:15
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::YAMLReader::setMappingClass
void setMappingClass()
Definition: YAMLReader.h:33
ValueTree.h
cnoid
Definition: AbstractSceneLoader.h:11