mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-20 14:02:38 +02:00
code cleanups
This commit is contained in:
@@ -35,27 +35,28 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_Array_INCLUDED
|
||||
#define JSON_Array_INCLUDED
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class Object;
|
||||
|
||||
|
||||
class JSON_API Array
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<Dynamic::Var> ValueVector;
|
||||
typedef SharedPtr<Array> Ptr;
|
||||
|
||||
@@ -199,6 +200,7 @@ inline void Array::remove(unsigned int index)
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<JSON::Array::Ptr>: public VarHolder
|
||||
{
|
||||
@@ -337,6 +339,7 @@ private:
|
||||
JSON::Array::Ptr _val;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
|
@@ -35,6 +35,7 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_DefaultHandler_INCLUDED
|
||||
#define JSON_DefaultHandler_INCLUDED
|
||||
|
||||
@@ -154,4 +155,5 @@ inline void DefaultHandler::null()
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_DefaultHandler_INCLUDED
|
||||
|
@@ -35,12 +35,14 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_Handler_INCLUDED
|
||||
#define JSON_Handler_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
@@ -95,4 +97,5 @@ private:
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_Handler_INCLUDED
|
||||
|
@@ -35,6 +35,7 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_JSONException_INCLUDED
|
||||
#define JSON_JSONException_INCLUDED
|
||||
|
||||
@@ -46,8 +47,10 @@
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(JSON_API, JSONException, Poco::Exception)
|
||||
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
|
@@ -35,30 +35,29 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_Object_INCLUDED
|
||||
#define JSON_Object_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Object
|
||||
/// Represents a JSON object
|
||||
/// Represents a JSON object.
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SharedPtr<Object> Ptr;
|
||||
|
||||
Object();
|
||||
@@ -344,6 +343,7 @@ private:
|
||||
JSON::Object::Ptr _val;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
|
@@ -35,68 +35,66 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_JSONParser_INCLUDED
|
||||
#define JSON_JSONParser_INCLUDED
|
||||
|
||||
|
||||
#include <istream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/StreamTokenizer.h"
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
#include "Poco/JSON/Handler.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/StreamTokenizer.h"
|
||||
#include <istream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
|
||||
|
||||
class JSON_API Parser
|
||||
/// A class for passing JSON strings or streams
|
||||
/// A class for passing JSON strings or streams.
|
||||
{
|
||||
public:
|
||||
|
||||
Parser();
|
||||
/// Constructor
|
||||
/// Constructor.
|
||||
|
||||
virtual ~Parser();
|
||||
/// Destructor
|
||||
/// Destructor.
|
||||
|
||||
void parse(const std::string& source);
|
||||
/// Parses a string
|
||||
/// Parses a string.
|
||||
|
||||
void parse(std::istream& in);
|
||||
/// Parses a JSON from the input stream
|
||||
/// Parses a JSON from the input stream.
|
||||
|
||||
void setHandler(Handler* handler);
|
||||
/// Set the handler
|
||||
/// Set the handler.
|
||||
|
||||
Handler* getHandler();
|
||||
/// Returns the handler
|
||||
/// Returns the handler.
|
||||
|
||||
private:
|
||||
|
||||
const Token* nextToken();
|
||||
/// Returns the next token
|
||||
/// Returns the next token.
|
||||
|
||||
void readObject();
|
||||
/// Starts reading an object
|
||||
|
||||
/// Starts reading an object.
|
||||
|
||||
void readArray();
|
||||
/// Starts reading an array
|
||||
/// 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
|
||||
/// Read a value from the token.
|
||||
|
||||
bool readElements(bool firstCall = false);
|
||||
/// Read all elements of an array
|
||||
/// Read all elements of an array.
|
||||
|
||||
StreamTokenizer _tokenizer;
|
||||
Handler* _handler;
|
||||
|
@@ -35,14 +35,15 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef JSON_JSONStringifier_INCLUDED
|
||||
#define JSON_JSONStringifier_INCLUDED
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace JSON {
|
||||
@@ -52,7 +53,6 @@ class JSON_API Stringifier
|
||||
/// Helper class for creating a String from a JSON object or array
|
||||
{
|
||||
public:
|
||||
|
||||
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.
|
||||
@@ -61,4 +61,5 @@ public:
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_JSONStringifier_INCLUDED
|
||||
|
@@ -39,14 +39,13 @@
|
||||
#define JSON_JSONTemplate_INCLUDED
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -66,106 +65,91 @@ class JSON_API Template
|
||||
/// conditional output, ...
|
||||
///
|
||||
/// All text is send to the outputstream. A command is placed
|
||||
/// between <? and ?>.
|
||||
/// between
|
||||
/// <?
|
||||
/// and
|
||||
/// ?>
|
||||
/// ----
|
||||
///
|
||||
/// These are the available commands:
|
||||
/// <? echo query ?>
|
||||
/// The result of the query is send to the output stream
|
||||
/// This command can also be written as <?= query ?>
|
||||
/// <? if query ?> <? else ?> <? endif ?>
|
||||
/// When the result of query is true, all the text between
|
||||
/// if and else (or endif when there is no else) is send to the
|
||||
/// output stream. When the result of query is false, all the text
|
||||
/// between else and endif is send to the output stream. An empty
|
||||
/// object, an empty array or a null value is considered as a false value.
|
||||
/// For numbers a zero is false. An empty String is also false.
|
||||
/// <? ifexist query ?> <? else ?> <? endif ?>
|
||||
/// This can be used to check the existance of the value.
|
||||
/// Use this for example when a zero value is ok (which returns false for <? if ?>.
|
||||
/// <? for variable query ?> <? endfor ?>
|
||||
/// The result of the query must be an array. For each element
|
||||
/// in the array the text between for and endfor is send to the
|
||||
/// output stream. The active element is stored in the variable.
|
||||
/// <? include "filename" ?>
|
||||
/// Includes a template. When the filename is relative it will try
|
||||
/// to resolve the filename against the active template. When this
|
||||
/// file doesn't exist, it can still be found when the JSONTemplateCache
|
||||
/// is used.
|
||||
///
|
||||
/// <? echo query ?>
|
||||
/// ----
|
||||
/// The result of the query is send to the output stream
|
||||
/// This command can also be written as <?= query ?>
|
||||
///
|
||||
/// <? if query ?> <? else ?> <? endif ?>
|
||||
/// ----
|
||||
/// When the result of query is true, all the text between
|
||||
/// if and else (or endif when there is no else) is send to the
|
||||
/// output stream. When the result of query is false, all the text
|
||||
/// between else and endif is send to the output stream. An empty
|
||||
/// object, an empty array or a null value is considered as a false value.
|
||||
/// For numbers a zero is false. An empty String is also false.
|
||||
///
|
||||
/// <? ifexist query ?> <? else ?> <? endif ?>
|
||||
/// ----
|
||||
/// This can be used to check the existance of the value.
|
||||
/// Use this for example when a zero value is ok (which returns false for <? if ?>.
|
||||
///
|
||||
/// <? for variable query ?> <? endfor ?>
|
||||
/// ----
|
||||
/// The result of the query must be an array. For each element
|
||||
/// in the array the text between for and endfor is send to the
|
||||
/// output stream. The active element is stored in the variable.
|
||||
///
|
||||
/// <? include "filename" ?>
|
||||
/// ----
|
||||
/// Includes a template. When the filename is relative it will try
|
||||
/// to resolve the filename against the active template. When this
|
||||
/// file doesn't exist, it can still be found when the JSONTemplateCache
|
||||
/// is used.
|
||||
///
|
||||
/// A query is passed to Poco::JSON::Query to get the value.
|
||||
{
|
||||
public:
|
||||
typedef SharedPtr<Template> Ptr;
|
||||
|
||||
|
||||
Template();
|
||||
/// Constructor
|
||||
|
||||
/// Constructor.
|
||||
|
||||
Template(const Path& templatePath);
|
||||
/// Constructor. Creates a template from a file.
|
||||
|
||||
|
||||
virtual ~Template();
|
||||
/// Destructor
|
||||
|
||||
/// Destructor.
|
||||
|
||||
void parse();
|
||||
/// Parse a template from a file
|
||||
|
||||
/// Parse a template from a file.
|
||||
|
||||
void parse(const std::string& source);
|
||||
/// Parse a template from a String
|
||||
|
||||
/// Parse a template from a string.
|
||||
|
||||
void parse(std::istream& in);
|
||||
/// Parse a template from a input stream
|
||||
|
||||
/// Parse a template from a input stream.
|
||||
|
||||
Timestamp parseTime() const;
|
||||
/// Returns the time when the template was parsed
|
||||
|
||||
/// Returns the time when the template was parsed.
|
||||
|
||||
void render(const Dynamic::Var& data, std::ostream& out) const;
|
||||
/// Renders the template and send the output to the stream
|
||||
|
||||
/// Renders the template and send the output to the stream.
|
||||
|
||||
private:
|
||||
|
||||
|
||||
std::string readText(std::istream& in);
|
||||
|
||||
|
||||
std::string readWord(std::istream& in);
|
||||
|
||||
|
||||
std::string readQuery(std::istream& in);
|
||||
|
||||
|
||||
std::string readTemplateCommand(std::istream& in);
|
||||
|
||||
|
||||
std::string readString(std::istream& in);
|
||||
|
||||
|
||||
void readWhiteSpace(std::istream& in);
|
||||
|
||||
|
||||
MultiPart* _parts;
|
||||
|
||||
|
||||
std::stack<MultiPart*> _partStack;
|
||||
|
||||
|
||||
MultiPart* _currentPart;
|
||||
|
||||
|
||||
Path _templatePath;
|
||||
|
||||
|
||||
Timestamp _parseTime;
|
||||
};
|
||||
|
||||
|
||||
inline void Template::parse(const std::string& source)
|
||||
{
|
||||
std::istringstream is(source);
|
||||
@@ -178,6 +162,8 @@ inline Timestamp Template::parseTime() const
|
||||
return _parseTime;
|
||||
}
|
||||
|
||||
|
||||
}} // namespace Poco::JSON
|
||||
|
||||
|
||||
#endif // JSON_JSONTemplate_INCLUDED
|
||||
|
@@ -39,13 +39,13 @@
|
||||
#define JSON_JSONTemplateCache_INCLUDED
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "Poco/JSON/JSON.h"
|
||||
#include "Poco/JSON/Template.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/JSON/Template.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -60,13 +60,12 @@ class JSON_API TemplateCache
|
||||
/// and load a new one.
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateCache();
|
||||
/// Constructor. The cache must be created
|
||||
/// and not destroyed as long as it is used.
|
||||
|
||||
virtual ~TemplateCache();
|
||||
/// Destructor
|
||||
/// Destructor.
|
||||
|
||||
void addPath(const Path& path);
|
||||
/// Add a path for resolving template paths.
|
||||
@@ -88,7 +87,6 @@ public:
|
||||
/// Sets the logger for the cache.
|
||||
|
||||
private:
|
||||
|
||||
static TemplateCache* _instance;
|
||||
std::vector<Path> _includePaths;
|
||||
std::map<std::string, Template::Ptr> _cache;
|
||||
|
Reference in New Issue
Block a user