aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/config/sax.cpp
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/config/sax.cpp
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'library/cpp/config/sax.cpp')
-rw-r--r--library/cpp/config/sax.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/library/cpp/config/sax.cpp b/library/cpp/config/sax.cpp
new file mode 100644
index 00000000000..7837fe97b55
--- /dev/null
+++ b/library/cpp/config/sax.cpp
@@ -0,0 +1,67 @@
+#include "sax.h"
+
+using namespace NConfig;
+
+namespace {
+ class TSax: public IConfig, public IConfig::IValue {
+ public:
+ inline TSax(const TConfig& cfg)
+ : C_(cfg)
+ {
+ }
+
+ void DoForEach(IFunc* func) override {
+ if (C_.IsA<TArray>()) {
+ const TArray& a = C_.Get<TArray>();
+
+ for (size_t i = 0; i < a.size(); ++i) {
+ TSax slave(a[i]);
+
+ func->Consume(ToString(i), &slave);
+ }
+ } else if (C_.IsA<TDict>()) {
+ const TDict& d = C_.Get<TDict>();
+
+ for (const auto& it : d) {
+ TSax slave(it.second);
+
+ func->Consume(it.first, &slave);
+ }
+ }
+ }
+
+ TString AsString() override {
+ if (C_.IsA<TArray>()) {
+ TSax slave(C_.Get<TArray>()[0]);
+ return slave.AsString();
+ }
+ return C_.As<TString>();
+ }
+
+ bool AsBool() override {
+ return C_.As<bool>();
+ }
+
+ IConfig* AsSubConfig() override {
+ return this;
+ }
+ bool IsContainer() const override {
+ return C_.IsA<TArray>() || C_.IsA<TDict>();
+ }
+ void DumpJson(IOutputStream& stream) const override {
+ C_.DumpJson(stream);
+ }
+ void DumpLua(IOutputStream& stream) const override {
+ C_.DumpLua(stream);
+ }
+
+ private:
+ TConfig C_;
+ };
+}
+
+namespace NConfig {
+ THolder<IConfig> ConfigParser(IInputStream& in, const TGlobals& globals) {
+ return MakeHolder<TSax>(TConfig::FromStream(in, globals));
+ }
+}