mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 15:16:49 +02:00
- VS2012: build/tests
- JSON: style and exceptions catch by ref fix - NumberParser: case-insensitive hex parsing - Dynamic::Var: const std::string& cast operator specialization (coaxing std::string ctor) - LocalDateTime: strftime fix (buffer too small for full tz string, use %Z instead of %z - makes no difference on windows but is more portable) - small buildwin.cmd vsvars32.bat call fix
This commit is contained in:
@@ -46,10 +46,8 @@
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
class Object;
|
||||
|
||||
@@ -58,37 +56,28 @@ class JSON_API Array
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<DynamicAny> ValueVector;
|
||||
|
||||
|
||||
typedef std::vector<Dynamic::Var> ValueVector;
|
||||
typedef SharedPtr<Array> Ptr;
|
||||
|
||||
|
||||
Array();
|
||||
/// Default constructor
|
||||
|
||||
|
||||
Array(const Array& copy);
|
||||
/// Copy Constructor
|
||||
|
||||
|
||||
virtual ~Array();
|
||||
/// Destructor
|
||||
|
||||
|
||||
ValueVector::const_iterator begin() const;
|
||||
/// Returns iterator
|
||||
|
||||
|
||||
ValueVector::const_iterator end() const;
|
||||
/// Returns iterator
|
||||
|
||||
|
||||
DynamicAny get(unsigned int index) const;
|
||||
Dynamic::Var get(unsigned int index) const;
|
||||
/// Retrieves an element. Will return an empty value
|
||||
/// when the element doesn't exist.
|
||||
|
||||
|
||||
Array::Ptr getArray(unsigned int index) const;
|
||||
/// Retrieves an array. When the element is not
|
||||
/// an array or doesn't exist, an empty SharedPtr is returned.
|
||||
@@ -101,11 +90,10 @@ public:
|
||||
/// exceptions for invalid values.
|
||||
/// Note: This will not work for an array or an object.
|
||||
{
|
||||
DynamicAny value = get(index);
|
||||
Dynamic::Var value = get(index);
|
||||
return value.convert<T>();
|
||||
}
|
||||
|
||||
|
||||
SharedPtr<Object> getObject(unsigned int index) const;
|
||||
/// Retrieves an object. When the element is not
|
||||
/// an object or doesn't exist, an empty SharedPtr is returned.
|
||||
@@ -113,20 +101,16 @@ public:
|
||||
unsigned int size() const;
|
||||
/// Returns the size of the array
|
||||
|
||||
|
||||
bool isArray(unsigned int index) const;
|
||||
/// Returns true when the element is an array
|
||||
|
||||
|
||||
bool isNull(unsigned int index) const;
|
||||
/// Returns true when the element is null or
|
||||
/// when the element doesn't exist.
|
||||
|
||||
|
||||
bool isObject(unsigned int index) const;
|
||||
/// Returns true when the element is an object
|
||||
|
||||
|
||||
template<typename T>
|
||||
T optElement(unsigned int index, const T& def) const
|
||||
/// Returns the element at the given index. When
|
||||
@@ -149,24 +133,20 @@ public:
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void add(const DynamicAny& value)
|
||||
void add(const Dynamic::Var& value)
|
||||
/// Add the given value to the array
|
||||
{
|
||||
_values.push_back(value);
|
||||
}
|
||||
|
||||
|
||||
void stringify(std::ostream& out, unsigned int indent) const;
|
||||
/// Prints the array to out. When indent is 0, the array
|
||||
/// will be printed on one line without indentation.
|
||||
|
||||
|
||||
void remove(unsigned int index);
|
||||
/// Removes the element on the given index.
|
||||
|
||||
private:
|
||||
|
||||
ValueVector _values;
|
||||
};
|
||||
|
||||
@@ -176,28 +156,32 @@ inline Array::ValueVector::const_iterator Array::begin() const
|
||||
return _values.begin();
|
||||
}
|
||||
|
||||
|
||||
inline Array::ValueVector::const_iterator Array::end() const
|
||||
|
||||
{
|
||||
return _values.end();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int Array::size() const
|
||||
{
|
||||
return _values.size();
|
||||
}
|
||||
|
||||
|
||||
inline bool Array::isArray(unsigned int index) const
|
||||
{
|
||||
DynamicAny value = get(index);
|
||||
Dynamic::Var value = get(index);
|
||||
return value.type() == typeid(Array::Ptr);
|
||||
}
|
||||
|
||||
|
||||
inline bool Array::isNull(unsigned int index) const
|
||||
{
|
||||
if ( index < _values.size() )
|
||||
{
|
||||
DynamicAny value = _values[index];
|
||||
Dynamic::Var value = _values[index];
|
||||
return value.isEmpty();
|
||||
}
|
||||
return true;
|
||||
@@ -211,11 +195,9 @@ inline void Array::remove(unsigned int index)
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
|
||||
namespace Dynamic
|
||||
{
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<JSON::Array::Ptr>: public VarHolder
|
||||
@@ -355,8 +337,7 @@ private:
|
||||
JSON::Array::Ptr _val;
|
||||
};
|
||||
|
||||
} // Namespace Dynamic
|
||||
} // Namespace Poco
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_Array_INCLUDED
|
||||
|
@@ -40,13 +40,12 @@
|
||||
|
||||
|
||||
#include "Poco/JSON/Handler.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API DefaultHandler : public Handler
|
||||
/// Provides a default handler for the JSON parser.
|
||||
@@ -55,82 +54,60 @@ class JSON_API DefaultHandler : public Handler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
DefaultHandler();
|
||||
/// Default Constructor
|
||||
|
||||
|
||||
virtual ~DefaultHandler();
|
||||
/// Destructor
|
||||
|
||||
|
||||
void startObject();
|
||||
/// Handles a {, meaning a new object will be read
|
||||
|
||||
|
||||
void endObject();
|
||||
/// Handles a }, meaning the object is read
|
||||
|
||||
|
||||
void startArray();
|
||||
/// Handles a [, meaning a new array will be read
|
||||
|
||||
|
||||
void endArray();
|
||||
/// Handles a ], meaning the array is read
|
||||
|
||||
|
||||
void key(const std::string& k);
|
||||
/// A key is read
|
||||
|
||||
|
||||
DynamicAny result() const;
|
||||
Dynamic::Var result() const;
|
||||
/// Returns the result of the parser. Which is an object or an array.
|
||||
|
||||
|
||||
virtual void value(int v);
|
||||
/// An integer value is read
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
virtual void value(Int64 v);
|
||||
/// A 64-bit integer value is read
|
||||
#endif
|
||||
|
||||
|
||||
virtual void value(const std::string& s);
|
||||
/// A string value is read.
|
||||
|
||||
|
||||
virtual void value(double d);
|
||||
/// A double value is read
|
||||
|
||||
|
||||
virtual void value(bool b);
|
||||
/// A boolean value is read
|
||||
|
||||
|
||||
virtual void null();
|
||||
/// A null value is read
|
||||
|
||||
|
||||
private:
|
||||
void setValue(const Poco::Dynamic::Var& value);
|
||||
|
||||
|
||||
void setValue(const Poco::DynamicAny& value);
|
||||
|
||||
|
||||
std::stack<DynamicAny> _stack;
|
||||
|
||||
|
||||
std::string _key;
|
||||
|
||||
|
||||
DynamicAny _result;
|
||||
std::stack<Dynamic::Var> _stack;
|
||||
std::string _key;
|
||||
Dynamic::Var _result;
|
||||
};
|
||||
|
||||
|
||||
inline DynamicAny DefaultHandler::result() const
|
||||
inline Dynamic::Var DefaultHandler::result() const
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
@@ -141,6 +118,7 @@ inline void DefaultHandler::value(int v)
|
||||
setValue(v);
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
inline void DefaultHandler::value(Int64 v)
|
||||
{
|
||||
@@ -169,11 +147,11 @@ inline void DefaultHandler::value(bool b)
|
||||
|
||||
inline void DefaultHandler::null()
|
||||
{
|
||||
Poco::DynamicAny empty;
|
||||
Poco::Dynamic::Var empty;
|
||||
setValue(empty);
|
||||
}
|
||||
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
#endif // JSON_DefaultHandler_INCLUDED
|
||||
|
@@ -39,65 +39,51 @@
|
||||
#define JSON_Handler_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/JSON/JSON.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Handler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
virtual void startObject() = 0;
|
||||
/// The parser has read a {, meaning a new object will be read
|
||||
|
||||
|
||||
virtual void endObject() = 0;
|
||||
/// The parser has read a }, meaning the object is read
|
||||
|
||||
|
||||
virtual void startArray() = 0;
|
||||
/// The parser has read a [, meaning a new array will be read
|
||||
|
||||
|
||||
virtual void endArray() = 0;
|
||||
/// The parser has read a ], meaning the array is read
|
||||
|
||||
|
||||
virtual void key(const std::string& k) = 0;
|
||||
/// A key of an object is read
|
||||
|
||||
|
||||
virtual void null() = 0;
|
||||
/// A null value is read
|
||||
|
||||
|
||||
virtual void value(int v) = 0;
|
||||
/// An integer value is read
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
virtual void value(Int64 v) = 0;
|
||||
/// A 64-bit integer value is read
|
||||
#endif
|
||||
|
||||
|
||||
virtual void value(const std::string& value) = 0;
|
||||
/// A string value is read.
|
||||
|
||||
|
||||
virtual void value(double d) = 0;
|
||||
/// A double value is read
|
||||
|
||||
|
||||
virtual void value(bool b) = 0;
|
||||
/// A boolean value is read
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Handler();
|
||||
@@ -107,6 +93,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
#endif // JSON_Handler_INCLUDED
|
||||
|
@@ -54,16 +54,16 @@
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(JSON_EXPORTS)
|
||||
#define JSON_API __declspec(dllexport)
|
||||
#else
|
||||
#define JSON_API __declspec(dllimport)
|
||||
#endif
|
||||
#if defined(JSON_EXPORTS)
|
||||
#define JSON_API __declspec(dllexport)
|
||||
#else
|
||||
#define JSON_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(JSON_API)
|
||||
#define JSON_API
|
||||
#define JSON_API
|
||||
#endif
|
||||
|
||||
|
||||
|
@@ -43,13 +43,12 @@
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
POCO_DECLARE_EXCEPTION(JSON_API, JSONException, Poco::Exception)
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif //JSON_JSONException_INCLUDED
|
||||
|
@@ -50,10 +50,8 @@
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Object
|
||||
@@ -63,34 +61,29 @@ public:
|
||||
|
||||
typedef SharedPtr<Object> Ptr;
|
||||
|
||||
|
||||
Object();
|
||||
/// Default constructor
|
||||
|
||||
Object(const Object& copy);
|
||||
/// Copy constructor
|
||||
|
||||
|
||||
virtual ~Object();
|
||||
/// Destructor
|
||||
|
||||
DynamicAny get(const std::string& key) const;
|
||||
Dynamic::Var get(const std::string& key) const;
|
||||
/// Retrieves a property. An empty value is
|
||||
/// returned when the property doesn't exist.
|
||||
|
||||
|
||||
Array::Ptr getArray(const std::string& key) const;
|
||||
/// Returns a SharedPtr to an array when the property
|
||||
/// is an array. An empty SharedPtr is returned when
|
||||
/// the element doesn't exist or is not an array.
|
||||
|
||||
|
||||
Object::Ptr getObject(const std::string& key) const;
|
||||
/// Returns a SharedPtr to an object when the property
|
||||
/// is an object. An empty SharedPtr is returned when
|
||||
/// the property doesn't exist or is not an object
|
||||
|
||||
|
||||
template<typename T>
|
||||
T getValue(const std::string& key) const
|
||||
/// Retrieves the property with the given name and will
|
||||
@@ -99,30 +92,25 @@ public:
|
||||
/// which can also throw exceptions for invalid values.
|
||||
/// Note: This will not work for an array or an object.
|
||||
{
|
||||
DynamicAny value = get(key);
|
||||
Dynamic::Var value = get(key);
|
||||
return value.convert<T>();
|
||||
}
|
||||
|
||||
void getNames(std::vector<std::string>& names) const;
|
||||
/// Returns all property names
|
||||
|
||||
|
||||
bool has(const std::string& key) const;
|
||||
/// Returns true when the given property exists
|
||||
|
||||
|
||||
bool isArray(const std::string& key) const;
|
||||
/// Returns true when the given property contains an array
|
||||
|
||||
|
||||
bool isNull(const std::string& key) const;
|
||||
/// Returns true when the given property contains a null value
|
||||
|
||||
|
||||
bool isObject(const std::string& key) const;
|
||||
/// Returns true when the given property contains an object
|
||||
|
||||
|
||||
template<typename T>
|
||||
T optValue(const std::string& key, const T& def) const
|
||||
/// Returns the value of a property when the property exists
|
||||
@@ -146,27 +134,21 @@ public:
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
unsigned int size() const;
|
||||
/// Returns the number of properties
|
||||
|
||||
|
||||
void set(const std::string& key, const DynamicAny& value);
|
||||
void set(const std::string& key, const Dynamic::Var& value);
|
||||
/// Sets a new value
|
||||
|
||||
|
||||
void stringify(std::ostream& out, unsigned int indent = 0) const;
|
||||
/// Prints the object to out. When indent is 0, the object
|
||||
/// will be printed on one line without indentation.
|
||||
|
||||
|
||||
void remove(const std::string& key);
|
||||
/// Removes the property with the given key
|
||||
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<std::string, DynamicAny> ValueMap;
|
||||
typedef std::map<std::string, Dynamic::Var> ValueMap;
|
||||
ValueMap _values;
|
||||
};
|
||||
|
||||
@@ -177,47 +159,52 @@ inline bool Object::has(const std::string& key) const
|
||||
return it != _values.end();
|
||||
}
|
||||
|
||||
|
||||
inline bool Object::isArray(const std::string& key) const
|
||||
{
|
||||
ValueMap::const_iterator it = _values.find(key);
|
||||
return it != _values.end() || it->second.type() == typeid(Array::Ptr);
|
||||
}
|
||||
|
||||
|
||||
inline bool Object::isNull(const std::string& key) const
|
||||
{
|
||||
ValueMap::const_iterator it = _values.find(key);
|
||||
return it == _values.end() || it->second.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
inline bool Object::isObject(const std::string& key) const
|
||||
{
|
||||
ValueMap::const_iterator it = _values.find(key);
|
||||
return it != _values.end() || it->second.type() == typeid(Object::Ptr);
|
||||
}
|
||||
|
||||
inline void Object::set(const std::string& key, const DynamicAny& value)
|
||||
|
||||
inline void Object::set(const std::string& key, const Dynamic::Var& value)
|
||||
{
|
||||
_values[key] = value;
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int Object::size() const
|
||||
{
|
||||
return _values.size();
|
||||
}
|
||||
|
||||
|
||||
inline void Object::remove(const std::string& key)
|
||||
{
|
||||
_values.erase(key);
|
||||
}
|
||||
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
namespace Dynamic
|
||||
{
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<JSON::Object::Ptr>: public VarHolder
|
||||
@@ -357,7 +344,7 @@ private:
|
||||
JSON::Object::Ptr _val;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_Object_INCLUDED
|
||||
|
@@ -42,7 +42,7 @@
|
||||
#include <istream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/StreamTokenizer.h"
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
@@ -50,10 +50,9 @@
|
||||
#include "Poco/JSON/Array.h"
|
||||
#include "Poco/JSON/Handler.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Parser
|
||||
/// A class for passing JSON strings or streams
|
||||
@@ -63,33 +62,26 @@ public:
|
||||
Parser();
|
||||
/// Constructor
|
||||
|
||||
|
||||
virtual ~Parser();
|
||||
/// Destructor
|
||||
|
||||
|
||||
void parse(const std::string& source);
|
||||
/// Parses a string
|
||||
|
||||
|
||||
void parse(std::istream& in);
|
||||
/// Parses a JSON from the input stream
|
||||
|
||||
|
||||
void setHandler(Handler* handler);
|
||||
/// Set the handler
|
||||
|
||||
Handler* getHandler();
|
||||
/// Returns the handler
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
const Token* nextToken();
|
||||
/// Returns the next token
|
||||
|
||||
|
||||
void readObject();
|
||||
/// Starts reading an object
|
||||
|
||||
@@ -97,23 +89,17 @@ private:
|
||||
void readArray();
|
||||
/// Starts reading an array
|
||||
|
||||
|
||||
bool readRow(bool firstCall = false);
|
||||
/// Reads a property value pair. Returns true when a next row is expected.
|
||||
|
||||
|
||||
void readValue(const Token* token);
|
||||
/// Read a value from the token
|
||||
|
||||
|
||||
bool readElements(bool firstCall = false);
|
||||
/// Read all elements of an array
|
||||
|
||||
|
||||
StreamTokenizer _tokenizer;
|
||||
|
||||
|
||||
Handler* _handler;
|
||||
Handler* _handler;
|
||||
};
|
||||
|
||||
|
||||
@@ -135,6 +121,8 @@ inline Handler* Parser::getHandler()
|
||||
return _handler;
|
||||
}
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_JSONParser_INCLUDED
|
||||
|
@@ -44,40 +44,34 @@
|
||||
#include "Poco/JSON/Array.h"
|
||||
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Query
|
||||
/// Class that can be used to search for a value in a JSON object or array.
|
||||
{
|
||||
public:
|
||||
Query(const DynamicAny& source);
|
||||
Query(const Dynamic::Var& source);
|
||||
/// Constructor. Pass the start object/array.
|
||||
|
||||
|
||||
virtual ~Query();
|
||||
/// Destructor
|
||||
|
||||
|
||||
Object::Ptr findObject(const std::string& path) const;
|
||||
/// Search for an object. When the object can't be found, an empty
|
||||
/// SharedPtr is returned.
|
||||
|
||||
|
||||
Array::Ptr findArray(const std::string& path) const;
|
||||
/// Search for an array. When the array can't be found, an empty
|
||||
/// SharedPtr is returned.
|
||||
|
||||
|
||||
DynamicAny find(const std::string& path) const;
|
||||
Dynamic::Var find(const std::string& path) const;
|
||||
/// Searches a value
|
||||
/// For example: "person.children[0].name" will return the
|
||||
/// the name of the first child. When the value can't be found
|
||||
/// an empty value is returned.
|
||||
|
||||
|
||||
template<typename T>
|
||||
T findValue(const std::string& path, const T& def) const
|
||||
/// Searches for a value will convert it to the given type.
|
||||
@@ -85,16 +79,14 @@ public:
|
||||
/// the default value will be returned.
|
||||
{
|
||||
T result = def;
|
||||
DynamicAny value = find(path);
|
||||
Dynamic::Var value = find(path);
|
||||
if ( ! value.isEmpty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
result = value.convert<T>();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
catch(...) { }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -108,11 +100,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DynamicAny _source;
|
||||
|
||||
Dynamic::Var _source;
|
||||
};
|
||||
|
||||
}} // Namespace JSON
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_JSONQuery_INCLUDED
|
||||
|
@@ -41,24 +41,24 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/JSON/JSON.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Stringifier
|
||||
/// Helper class for creating a String from a JSON object or array
|
||||
{
|
||||
public:
|
||||
|
||||
static void stringify(const DynamicAny& any, std::ostream& out, unsigned int indent = 0);
|
||||
static void stringify(const Dynamic::Var& any, std::ostream& out, unsigned int indent = 0);
|
||||
/// Writes a String representation of the value to the output stream.
|
||||
/// When indent is 0, the String will be created as small as possible.
|
||||
};
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
#endif // JSON_JSONStringifier_INCLUDED
|
||||
|
@@ -43,21 +43,22 @@
|
||||
#include <stack>
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class MultiPart;
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(JSON_API, JSONTemplateException, Poco::Exception)
|
||||
|
||||
|
||||
class JSON_API Template
|
||||
/// Template is a template engine which uses JSON as input
|
||||
/// for generating output. There are commands for
|
||||
@@ -125,7 +126,7 @@ public:
|
||||
/// Returns the time when the template was parsed
|
||||
|
||||
|
||||
void render(const DynamicAny& data, std::ostream& out) const;
|
||||
void render(const Dynamic::Var& data, std::ostream& out) const;
|
||||
/// Renders the template and send the output to the stream
|
||||
|
||||
|
||||
@@ -177,6 +178,6 @@ inline Timestamp Template::parseTime() const
|
||||
return _parseTime;
|
||||
}
|
||||
|
||||
}} // Namespace Poco::JSON
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
#endif // JSON_JSONTemplate_INCLUDED
|
||||
|
@@ -45,13 +45,12 @@
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Logger.h"
|
||||
|
||||
#include "Poco/JSON/Template.h"
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace JSON
|
||||
{
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API TemplateCache
|
||||
/// Use to cache parsed templates. Templates are
|
||||
@@ -66,16 +65,13 @@ public:
|
||||
/// Constructor. The cache must be created
|
||||
/// and not destroyed as long as it is used.
|
||||
|
||||
|
||||
virtual ~TemplateCache();
|
||||
/// Destructor
|
||||
|
||||
|
||||
void addPath(const Path& path);
|
||||
/// Add a path for resolving template paths.
|
||||
/// The order of check is FIFO.
|
||||
|
||||
|
||||
Template::Ptr getTemplate(const Path& path);
|
||||
/// Returns a template from the cache.
|
||||
/// When the template file is not yet loaded
|
||||
@@ -85,32 +81,20 @@ public:
|
||||
/// even when the template isn't stored anymore in
|
||||
/// the cache.
|
||||
|
||||
|
||||
static TemplateCache* instance();
|
||||
/// Returns the only instance of this cache
|
||||
|
||||
|
||||
void setLogger(Logger& logger);
|
||||
/// Sets the logger for the cache.
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static TemplateCache* _instance;
|
||||
|
||||
|
||||
std::vector<Path> _includePaths;
|
||||
|
||||
|
||||
static TemplateCache* _instance;
|
||||
std::vector<Path> _includePaths;
|
||||
std::map<std::string, Template::Ptr> _cache;
|
||||
|
||||
|
||||
Logger* _logger;
|
||||
|
||||
|
||||
Logger* _logger;
|
||||
|
||||
void setup();
|
||||
|
||||
|
||||
Path resolvePath(const Path& path) const;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user