Circus 0.0.1-alpha
C++ Serialization Framework
Loading...
Searching...
No Matches
deserializer.hpp
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3
4#include "lexer.hpp"
5#include "parser.hpp"
6
7namespace circus {
12
22template <typename IStreamT>
23 requires(std::is_base_of_v<std::istream, IStreamT>)
25 std::unordered_map<std::string, circ_variable> root;
32 class circ_safe_proxy {
33 circ_variable& var;
34
35 public:
39 circ_safe_proxy(circ_variable& v) : var(v) {};
40
46 circ_safe_proxy operator[](const std::string& key) {
47 return circ_safe_proxy(var[key]);
48 };
54 circ_safe_proxy operator[](const char* key) {
55 return circ_safe_proxy(var[std::string(key)]);
56 }
62 template <typename T>
63 T& value() {
64 return std::get<T>(var.value);
65 }
70 template <typename T>
71 operator T() {
72 return std::get<T>(var.value);
73 }
74 };
75
76 public:
77 using circ_object = std::unordered_map<std::string, circ_variable>;
78
89 deserializer(IStreamT& is) {
90 std::string source = circus::filesystem::reader__{}(is);
91 std::vector<circus::tokens__> tokens = circus::lexer__{}(std::move(source));
92 std::unordered_map<std::string, circ_variable> rt = circus::parser__{}(std::move(tokens));
93 root = std::move(rt);
94 };
95
98 circ_safe_proxy operator[](const std::string& k) {
99 return circ_safe_proxy(root[k]);
100 };
101
102 ~deserializer() = default;
103};
104
105} // namespace circus
Parses structured circus-formatted input and exposes access to the parsed data.
Definition deserializer.hpp:24
circ_safe_proxy operator[](const std::string &k)
Destructor (default).
Definition deserializer.hpp:98
deserializer(IStreamT &is)
Constructs a deserializer from an input stream.
Definition deserializer.hpp:89
Utility class to read contents from input streams into a string.
Definition reader.hpp:17
Lexer for tokenizing input strings into Circus tokens.
Definition lexer.hpp:30
Parser for Circus token streams producing nested Circus variables.
Definition parser.hpp:57
Lexer class for tokenizing Circus input strings.
Represents a variable in Circus serialization.
Definition parser.hpp:18
circ_type_var_t value
The value stored in this variable.
Definition parser.hpp:34