HoverRace  2.0
Emitter.h
Go to the documentation of this file.
1 
2 // Emitter.h
3 //
4 // Copyright (c) 2008, 2009, 2015-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <exception>
25 #include <string>
26 
27 #include <yaml.h>
28 
29 #include "../OS.h"
30 #include "YamlExn.h"
31 
32 namespace HoverRace {
33 namespace Util {
34 namespace yaml {
35 
37 class EmitterExn : public YamlExn
38 {
39  using SUPER = YamlExn;
40 
41 public:
42  EmitterExn() : SUPER() { }
43  EmitterExn(const char *const &msg) : SUPER(msg) { }
44  virtual ~EmitterExn() noexcept { }
45 };
46 
48 class Emitter
49 {
50 private:
51  Emitter() = delete;
52 public:
53  Emitter(FILE *file, bool versionDirective = true);
54  Emitter(std::ostream &os, bool versionDirective = true);
55  Emitter(std::string &s, bool versionDirective = true);
56  virtual ~Emitter();
57 
58 protected:
59  void InitEmitter();
60  void InitStream(bool versionDirective);
61 
62 public:
63  void StartMap();
64  void MapKey(const std::string &s);
65  void EndMap();
66 
67  void StartSeq();
68  void EndSeq();
69 
70  void Value(const std::string &val);
71  void Value(const char *val);
72  void Value(bool val);
73  void Value(int val);
74  void Value(double val);
75  void Value(float val);
76  void Value(const HoverRace::Util::OS::path_t &path);
77 
78  template<class T>
79  void Value(const T &val)
80  {
81  Value(boost::lexical_cast<std::string>(val));
82  }
83 
84 private:
85  yaml_emitter_t emitter;
86 };
87 
88 } // namespace yaml
89 } // namespace Util
90 } // namespace HoverRace
boost::filesystem::path path_t
Definition: OS.h:57
EmitterExn(const char *const &msg)
Definition: Emitter.h:43
Definition: YamlExn.h:28
EmitterExn()
Definition: Emitter.h:42
yaml_emitter_t emitter
Definition: Emitter.h:85
YamlExn()
Definition: YamlExn.h:33
Standard exception thrown for emitter errors.
Definition: Emitter.h:37
luabind::object val
Definition: Rulebook.cpp:52
std::string msg
Definition: YamlExn.h:41
void Value(const T &val)
Definition: Emitter.h:79
Definition: Announcement.h:24
virtual ~EmitterExn() noexcept
Definition: Emitter.h:44
Wrapper for the LibYAML emitter.
Definition: Emitter.h:48
Definition: Symbol.h:253