61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace RenderCadenceCompositor
|
|
{
|
|
class JsonWriter
|
|
{
|
|
public:
|
|
void BeginObject();
|
|
void EndObject();
|
|
void BeginArray();
|
|
void EndArray();
|
|
|
|
void Key(const std::string& name);
|
|
void String(const std::string& value);
|
|
void Bool(bool value);
|
|
void Null();
|
|
void Int(int64_t value);
|
|
void UInt(uint64_t value);
|
|
void Double(double value);
|
|
|
|
void KeyString(const std::string& name, const std::string& value);
|
|
void KeyBool(const std::string& name, bool value);
|
|
void KeyNull(const std::string& name);
|
|
void KeyInt(const std::string& name, int64_t value);
|
|
void KeyUInt(const std::string& name, uint64_t value);
|
|
void KeyDouble(const std::string& name, double value);
|
|
|
|
std::string StringValue() const;
|
|
void Reset();
|
|
|
|
static std::string EscapeString(const std::string& value);
|
|
|
|
private:
|
|
enum class ScopeKind
|
|
{
|
|
Object,
|
|
Array
|
|
};
|
|
|
|
struct Scope
|
|
{
|
|
ScopeKind kind = ScopeKind::Object;
|
|
bool first = true;
|
|
bool expectingValue = false;
|
|
};
|
|
|
|
void BeginValue();
|
|
void BeginKey();
|
|
void PushScope(ScopeKind kind);
|
|
void PopScope(ScopeKind kind);
|
|
|
|
std::ostringstream mStream;
|
|
Scope mScopes[32];
|
|
int mScopeDepth = 0;
|
|
};
|
|
}
|