Copy JSON from SandBox to trunk

This commit is contained in:
Franky Braem
2012-04-29 20:09:55 +00:00
parent 5a639074d9
commit 95c62c00df
121 changed files with 5085 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
//
// Parser.h
//
// $Id$
//
// Library: JSON
// Package: JSON
// Module: Parser
//
// Definition of the Parser class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef JSON_JSONParser_INCLUDED
#define JSON_JSONParser_INCLUDED
#include <istream>
#include <sstream>
#include "Poco/DynamicAny.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"
namespace Poco
{
namespace JSON
{
class JSON_API Parser
/// A class for passing JSON strings or streams
{
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
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;
};
inline void Parser::parse(const std::string& source)
{
std::istringstream is(source);
parse(is);
}
inline void Parser::setHandler(Handler* handler)
{
_handler = handler;
}
inline Handler* Parser::getHandler()
{
return _handler;
}
}} // Namespace Poco::JSON
#endif // JSON_JSONParser_INCLUDED