summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/yaml_emitter.h98
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);