Added istream/ostream funcs/operators

This commit is contained in:
Christopher Dunn
2007-03-23 09:57:01 +00:00
parent 2370789d67
commit 56a1d6cbf5
5 changed files with 82 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
# include <deque>
# include <stack>
# include <string>
# include <istream>
namespace Json {
@@ -47,6 +48,12 @@ namespace Json {
Value &root,
bool collectComments = true );
/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
bool parse( std::istream&,
Value &root,
bool collectComments = true );
/** \brief Returns a user friendly string that list errors in the parsed document.
* \return Formatted error message with the list of errors with their location in
* the parsed document. An empty string is returned if no error occurred
@@ -144,6 +151,31 @@ namespace Json {
bool collectComments_;
};
/** \brief Read from 'sin' into 'root'.
Always keep comments from the input JSON.
This can be used to read a file into a particular sub-object.
For example:
\code
Json::Value root;
cin >> root["dir"]["file"];
cout << root;
\endcode
Result:
\verbatim
{
"dir": {
"file": {
// The input stream JSON would be nested here.
}
}
}
\endverbatim
\throw std::exception on parse error.
\see Json::operator<<()
*/
std::istream& operator>>( std::istream&, Value& );
} // namespace Json

View File

@@ -4,6 +4,7 @@
# include "value.h"
# include <vector>
# include <string>
# include <ostream>
namespace Json {
@@ -68,7 +69,7 @@ namespace Json {
public: // overridden from Writer
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
* \param root Value to serialize.
* \return String containing the JSON document that represent the root value.
* \return String containing the JSON document that represents the root value.
*/
virtual std::string write( const Value &root );
@@ -102,6 +103,10 @@ namespace Json {
std::string JSON_API valueToString( bool value );
std::string JSON_API valueToQuotedString( const char *value );
/// \brief Output using the StyledWriter.
/// \see Json::operator>>()
std::ostream& operator<<( std::ostream&, const Value &root );
} // namespace Json