2010-05-21 03:13:36 +02:00
|
|
|
/**********************************************
|
|
|
|
|
|
|
|
License: BSD
|
|
|
|
Project Webpage: http://cajun-jsonapi.sourceforge.net/
|
|
|
|
Author: Terry Caton
|
|
|
|
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "elements.h"
|
|
|
|
#include "visitor.h"
|
|
|
|
|
|
|
|
namespace json
|
|
|
|
{
|
|
|
|
|
2011-12-22 22:12:25 +01:00
|
|
|
class Writer : private ConstVisitor {
|
|
|
|
Writer(std::ostream& ostr);
|
|
|
|
void Write(const Object& object);
|
|
|
|
void Write(const Array& array);
|
|
|
|
void Write(const String& string);
|
|
|
|
void Write(const Integer& number);
|
|
|
|
void Write(const Double& number);
|
|
|
|
void Write(const Boolean& boolean);
|
|
|
|
void Write(const Null& null);
|
|
|
|
void Write(const UnknownElement& unknown);
|
|
|
|
|
|
|
|
void Visit(const Array& array);
|
|
|
|
void Visit(const Object& object);
|
|
|
|
void Visit(const Integer& number);
|
|
|
|
void Visit(const Double& number);
|
|
|
|
void Visit(const String& string);
|
|
|
|
void Visit(const Boolean& boolean);
|
|
|
|
void Visit(const Null& null);
|
|
|
|
|
|
|
|
std::ostream& m_ostr;
|
|
|
|
int tab_depth;
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
public:
|
2011-12-22 22:12:25 +01:00
|
|
|
template <typename ElementTypeT>
|
|
|
|
static void Write(const ElementTypeT& element, std::ostream& ostr) {
|
|
|
|
Writer writer(ostr);
|
|
|
|
writer.Write(element);
|
|
|
|
ostr.flush(); // all done
|
|
|
|
}
|
2010-05-21 03:13:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // End namespace
|