diff options
author | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2024-10-07 11:19:51 +0200 |
---|---|---|
committer | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2024-10-08 18:46:31 +0200 |
commit | 0ab73d70395747c31c15557501e27d13bf278418 (patch) | |
tree | 551d4cc27a49d509ea0999aa501b80d3b01614ef /include | |
parent | 5d81e666dc90278e524a34bdddc9f8d5f67d5102 (diff) |
WIPyaml-emitter
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/yaml_emitter.h | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/include/libcamera/internal/yaml_emitter.h b/include/libcamera/internal/yaml_emitter.h index f8df5265..14ea8241 100644 --- a/include/libcamera/internal/yaml_emitter.h +++ b/include/libcamera/internal/yaml_emitter.h @@ -9,7 +9,9 @@ #include <map> #include <memory> +#include <stack> #include <string> +#include <string_view> #include <libcamera/base/class.h> #include <libcamera/base/file.h> @@ -21,15 +23,105 @@ namespace libcamera { class File; class YamlEvent; +class YamlEmitter; +class YamlDict; +class YamlList; + +class YamlOutput +{ +protected: + enum class YamlType { + Root, + Scalar, + Dict, + List, + }; + +public: + virtual ~YamlOutput() {} + virtual void close() {} + + std::unique_ptr<YamlDict> dict(); + std::unique_ptr<YamlList> list(); + + YamlType type() { return type_; } + +protected: + YamlOutput(YamlEmitter *emitter, YamlType type) + : emitter_(emitter), type_(type) + { + } + + int emitScalar(std::string_view scalar); + int emitMappingStart(); + int emitMappingEnd(); + int emitSequenceStart(); + int emitSequenceEnd(); + + YamlEmitter *emitter_; + YamlType type_; +}; + +class YamlRoot : public YamlOutput +{ +public: + ~YamlRoot() {} + + std::unique_ptr<YamlList> list(); + std::unique_ptr<YamlDict> dict(); + void scalar(std::string_view scalar); + +private: + friend class YamlEmitter; + + YamlRoot(YamlEmitter *emitter) + : YamlOutput(emitter, YamlType::Root) + { + emitterRoot_ = std::unique_ptr<YamlEmitter>(emitter); + } + + std::unique_ptr<YamlEmitter> emitterRoot_; +}; + +class YamlList : public YamlOutput +{ +public: + ~YamlList(); + + std::unique_ptr<YamlList> list(); + std::unique_ptr<YamlDict> dict(); + void scalar(std::string_view scalar); + +private: + friend class YamlOutput; + + YamlList(YamlEmitter *emitter); +}; + + +class YamlDict : public YamlOutput +{ +public: + ~YamlDict(); + + void scalar(std::string_view key, std::string_view value); + std::unique_ptr<YamlList> list(std::string_view key); + std::unique_ptr<YamlDict> dict(std::string_view key); + +private: + friend class YamlOutput; + + YamlDict(YamlEmitter *emitter); +}; + class YamlEmitter final { public: ~YamlEmitter(); - static std::unique_ptr<YamlEmitter> create(std::string &path); + static std::unique_ptr<YamlRoot> root(std::string &path); - int emit(std::map<std::string, std::string>); - int emit(const std::string &scalar); + int emit(YamlEvent *event); private: LIBCAMERA_DISABLE_COPY(YamlEmitter); |