From: Baptiste L. <bl...@us...> - 2005-07-30 17:41:14
|
Update of /cvsroot/jsoncpp/jsoncpp/include/json In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8466/include/json Modified Files: json_forwards.h json_reader.h json_value.h json_writer.h Log Message: * added more doxygen documentation * added support for comment in StyledWriter Index: json_value.h =================================================================== RCS file: /cvsroot/jsoncpp/jsoncpp/include/json/json_value.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** json_value.h 30 Jul 2005 11:15:11 -0000 1.3 --- json_value.h 30 Jul 2005 17:40:58 -0000 1.4 *************** *** 26,29 **** --- 26,38 ---- }; + enum CommentPlacement + { + commentBefore = 0, ///< a comment placed on the line before a value + commentAfterOnSameLine, ///< a comment just after a value on the same line + commentAfter, ///< a comment on the line after a value (only make sense for root value) + numberOfCommentPlacement + }; + + /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value. * *************** *** 153,160 **** Members getMemberNames() const; ! void setId( ValueId id ); ! ValueId id() const; private: struct CZString { --- 162,183 ---- Members getMemberNames() const; ! void setComment( const char *comment, ! CommentPlacement placement ); ! void setComment( const std::string &comment, ! CommentPlacement placement ); ! bool hasComment( CommentPlacement placement ) const; ! std::string getComment( CommentPlacement placement ) const; private: + struct CommentInfo + { + CommentInfo(); + ~CommentInfo(); + + void setComment( const char *text ); + + char *comment_; + }; + struct CZString { *************** *** 192,199 **** } value_; ValueType type_; ! ValueId id_; }; class PathArgument { --- 215,224 ---- } value_; ValueType type_; ! CommentInfo *comments_; }; + /** \brief Experimental and untested: represents an element of the "path" to access a node. + */ class PathArgument { *************** *** 218,230 **** }; ! /* * Syntax: ! * "." => root node ! * ".[n]" => elements at index 'n' of root node (an array value) ! * ".name" => member named 'name' of root node (an object value) ! * ".name1.name2.name3" ! * ".[0][1][2].name1[3]" ! * ".%" => member name is provided as parameter ! * ".[%]" => index is provied as parameter */ class Path --- 243,256 ---- }; ! /** \brief Experimental and untested: represents a "path" to access a node. ! * * Syntax: ! * - "." => root node ! * - ".[n]" => elements at index 'n' of root node (an array value) ! * - ".name" => member named 'name' of root node (an object value) ! * - ".name1.name2.name3" ! * - ".[0][1][2].name1[3]" ! * - ".%" => member name is provided as parameter ! * - ".[%]" => index is provied as parameter */ class Path *************** *** 241,244 **** --- 267,271 ---- Value resolve( const Value &root, const Value &defaultValue ) const; + /// Creates the "path" to access the specified node and returns a reference on the node. Value &make( Value &root ) const; Index: json_reader.h =================================================================== RCS file: /cvsroot/jsoncpp/jsoncpp/include/json/json_reader.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** json_reader.h 30 Jul 2005 11:15:11 -0000 1.2 --- json_reader.h 30 Jul 2005 17:40:58 -0000 1.3 *************** *** 4,7 **** --- 4,8 ---- # include "json_forwards.h" # include "json_config.h" + # include "json_value.h" # include <deque> # include <map> *************** *** 11,15 **** namespace Json { - class CommentMemo; class Value; --- 12,15 ---- *************** *** 30,49 **** * \param root [out] Contains the root value of the document if it was * successfully parsed. ! * \return \c true if the document was successfully parsed, \c false if an error occurred. ! */ ! bool parse( const std::string &document, ! Value &root ); ! ! /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document and preserve comments. ! * \param document [in] UTF-8 encoded string containing the document to read. ! * \param root [out] Contains the root value of the document if it was ! * successfully parsed. ! * \param commentMemo [out] Contains the comment associated with the value if it was successfully ! * parsed. * \return \c true if the document was successfully parsed, \c false if an error occurred. */ bool parse( const std::string &document, Value &root, ! CommentMemo &commentMemo ); /** \brief Returns a user friendly string that list errors in the parsed document. --- 30,40 ---- * \param root [out] Contains the root value of the document if it was * successfully parsed. ! * \param collectComments \c true to collect comment and allow writing them back during ! * serialization, \c false to discard comments. * \return \c true if the document was successfully parsed, \c false if an error occurred. */ bool parse( const std::string &document, Value &root, ! bool collectComments = true ); /** \brief Returns a user friendly string that list errors in the parsed document. *************** *** 126,129 **** --- 117,124 ---- int &column ) const; std::string getLocationLineAndColumn( Location location ) const; + void addComment( Location begin, + Location end, + CommentPlacement placement ); + void skipCommentTokens( Token &token ); typedef std::stack<Value *> Nodes; *************** *** 134,191 **** Location end_; Location current_; ! CommentMemo *commentMemo_; ! }; ! ! class JSON_API CommentMemo ! { ! public: ! enum Placement ! { ! atDocumentStart = 1, ! beforeValue, ! afterValueOnSameLine, ! atDocumentEnd ! }; ! ! class CommentInfo ! { ! public: ! std::string comment_; ! Placement placement_; ! ValueId id_; ! }; ! ! CommentMemo(); ! ! void beginDocumentParsing(); ! void parsedCComment( Reader::Location begin, ! Reader::Location end ); ! void parsedCppComment( Reader::Location begin, ! Reader::Location end ); ! void parsedValue( Reader::Location begin, ! Reader::Location end, ! Value &value ); ! void endDocumentParsing(); ! ! unsigned int getCommentCount() const; ! const CommentInfo &getComment( unsigned int index ) const; ! const CommentInfo *findComment( ValueId id, Placement placement ) const; ! private: ! static bool containsNewLine( Reader::Location begin, ! Reader::Location end ); ! void addComment( Reader::Location begin, ! Reader::Location end, ! Placement placement ); ! void registerComment( Placement placement, ! unsigned int index ); ! ! ! typedef std::deque<CommentInfo> Comments; ! typedef std::map<unsigned int> CommentsById; ! Comments comments_; ! CommentsById commentsById_; ! ValueId currentId_; ! Reader::Location lastValueEnd_; ! int monitorNextValue_; }; --- 129,136 ---- Location end_; Location current_; ! Location lastValueEnd_; ! Value *lastValue_; ! std::string commentsBefore_; ! bool collectComments_; }; Index: json_forwards.h =================================================================== RCS file: /cvsroot/jsoncpp/jsoncpp/include/json/json_forwards.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** json_forwards.h 30 Jul 2005 11:15:11 -0000 1.3 --- json_forwards.h 30 Jul 2005 17:40:58 -0000 1.4 *************** *** 4,8 **** namespace Json { - class CommentMemo; class FastWriter; class Path; --- 4,7 ---- *************** *** 12,17 **** class Value; - typedef unsigned int ValueId; - } // namespace Json --- 11,14 ---- Index: json_writer.h =================================================================== RCS file: /cvsroot/jsoncpp/jsoncpp/include/json/json_writer.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** json_writer.h 30 Jul 2005 11:15:11 -0000 1.3 --- json_writer.h 30 Jul 2005 17:40:58 -0000 1.4 *************** *** 41,45 **** * - otherwise, it the values do not fit on one line, or the array contains * object or non empty array, then print one value per line. ! * \sa Reader, Value */ class JSON_API StyledWriter --- 41,48 ---- * - otherwise, it the values do not fit on one line, or the array contains * object or non empty array, then print one value per line. ! * ! * If the Value have comments then they are outputed according to their #CommentPlacement. ! * ! * \sa Reader, Value, Value::setComment() */ class JSON_API StyledWriter *************** *** 54,65 **** std::string write( const Value &root ); - /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format. - * \param root Value to serialize. - * \param commentMemo Memo generated while parsing a JSON document. - * \return String containing the JSON document that represent the root value. - */ - std::string write( const Value &root, - const CommentMemo &commentMemo ); - private: void writeValue( const Value &value ); --- 57,60 ---- *************** *** 71,80 **** void indent(); void unindent(); ! void writeInitialComment( const Value &root ); ! void writeFinalComment( const Value &root ); ! bool hasMoreComments() const; ! const CommentMemo::CommentInfo &getCurrentComment() const; ! void writeComment( const CommentMemo::CommentInfo &comment ); ! bool hasCommentForValue( const Value &value ) const; typedef std::vector<std::string> ChildValues; --- 66,73 ---- void indent(); void unindent(); ! void writeCommentBeforeValue( const Value &root ); ! void writeCommentAfterValueOnSameLine( const Value &root ); ! bool hasCommentForValue( const Value &value ); ! static std::string normalizeEOL( const std::string &text ); typedef std::vector<std::string> ChildValues; *************** *** 85,90 **** int rightMargin_; int indentSize_; - const CommentMemo *commentMemo_; - unsigned int currentComment_; bool addChildValues_; }; --- 78,81 ---- |