#pragma once #include "config.h" #include #include #include #include #include class IInputStream; namespace NConfig { class IConfig { public: class IValue { public: virtual TString AsString() = 0; virtual bool AsBool() = 0; virtual IConfig* AsSubConfig() = 0; virtual bool IsContainer() const = 0; }; class IFunc { public: inline void Consume(const TString& key, IValue* value) { DoConsume(key, value); } virtual ~IFunc() = default; private: virtual void DoConsume(const TString& key, IValue* value) { (void)key; (void)value; } }; virtual ~IConfig() = default; inline void ForEach(IFunc* func) { DoForEach(func); } virtual void DumpJson(IOutputStream& stream) const = 0; virtual void DumpLua(IOutputStream& stream) const = 0; private: virtual void DoForEach(IFunc* func) = 0; }; template static inline bool ParseFromString(const TString& s, TMaybe& t) { t.ConstructInPlace(FromString(s)); return true; } template static inline bool ParseFromString(const TString& s, THolder& t) { t = MakeHolder(FromString(s)); return true; } template static inline bool ParseFromString(const TString& s, T& t) { t = FromString(s); return true; } THolder ConfigParser(IInputStream& in, const TGlobals& globals = TGlobals()); } #define START_PARSE \ void DoConsume(const TString& key, NConfig::IConfig::IValue* value) override { \ (void)key; \ (void)value; #define END_PARSE \ ythrow NConfig::TConfigParseError() << "unsupported key(" << key.Quote() << ")"; \ } #define ON_KEY(k, v) if (key == k && NConfig::ParseFromString(value->AsString(), v))