From: <vac...@us...> - 2008-12-16 19:05:16
|
Revision: 117 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=117&view=rev Author: vaclavslavik Date: 2008-12-16 19:05:11 +0000 (Tue, 16 Dec 2008) Log Message: ----------- added ability to create text nodes, using xml::node::text Modified Paths: -------------- trunk/NEWS trunk/include/xmlwrapp/node.h trunk/src/libxml/node.cxx trunk/tests/node/Makefile.am trunk/tests/node/runtest.pl Added Paths: ----------- trunk/tests/node/data/14.out trunk/tests/node/test_node-14.cxx Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-12-16 18:24:46 UTC (rev 116) +++ trunk/NEWS 2008-12-16 19:05:11 UTC (rev 117) @@ -27,6 +27,9 @@ Added xml::node::get_namespace() function. + Added new constructor to the xml::node class for creating text nodes, + using xml::node::text helper struct. + Version 0.5.1 Various compilation fixes. Modified: trunk/include/xmlwrapp/node.h =================================================================== --- trunk/include/xmlwrapp/node.h 2008-12-16 18:24:46 UTC (rev 116) +++ trunk/include/xmlwrapp/node.h 2008-12-16 19:05:11 UTC (rev 117) @@ -130,6 +130,18 @@ const char *n, *c; }; + /** + * Helper struct for creating a xml::node of type_text. + * + * @code + * xml::node mynode(xml::node::text("This is an XML text fragment")); + * @endcode + */ + struct text { + explicit text (const char *text) : t(text) { } + const char *t; + }; + //#################################################################### /** * Construct a new blank xml::node. @@ -212,6 +224,22 @@ //#################################################################### /** + * Construct a new xml::node that is of type_text. The text_info + * parameter should contain the text. + * + * @note Sample Use Example: + * @code + * xml::node mynode(xml::node::text("This is XML text")); + * @endcode + * + * @param text_info A text struct that tells xml::node what the text will be. + * @author Vaclav Slavik + **/ + //#################################################################### + explicit node (text text_info); + + //#################################################################### + /** * Construct a new xml::node by copying another xml::node. * * @param other The other node to copy. Modified: trunk/src/libxml/node.cxx =================================================================== --- trunk/src/libxml/node.cxx 2008-12-16 18:24:46 UTC (rev 116) +++ trunk/src/libxml/node.cxx 2008-12-16 19:05:11 UTC (rev 117) @@ -240,6 +240,16 @@ ap.release(); } //#################################################################### +xml::node::node (text text_info) { + std::auto_ptr<node_impl> ap(pimpl_ = new node_impl); + + if ( (pimpl_->xmlnode_ = xmlNewText(reinterpret_cast<const xmlChar*>(text_info.t))) == 0) { + throw std::bad_alloc(); + } + + ap.release(); +} +//#################################################################### xml::node::node (const node &other) { std::auto_ptr<node_impl> ap(pimpl_ = new node_impl); Modified: trunk/tests/node/Makefile.am =================================================================== --- trunk/tests/node/Makefile.am 2008-12-16 18:24:46 UTC (rev 116) +++ trunk/tests/node/Makefile.am 2008-12-16 19:05:11 UTC (rev 117) @@ -25,7 +25,8 @@ test_node-10 \ test_node-11 \ test_node-12 \ - test_node-13 + test_node-13 \ + test_node-14 test_node_01_SOURCES = test_node-01.cxx test_node_02a_SOURCES = test_node-02a.cxx @@ -48,3 +49,4 @@ test_node_11_SOURCES = test_node-11.cxx test_node_12_SOURCES = test_node-12.cxx test_node_13_SOURCES = test_node-13.cxx +test_node_14_SOURCES = test_node-14.cxx Added: trunk/tests/node/data/14.out =================================================================== --- trunk/tests/node/data/14.out (rev 0) +++ trunk/tests/node/data/14.out 2008-12-16 19:05:11 UTC (rev 117) @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<root>some text</root> Modified: trunk/tests/node/runtest.pl =================================================================== --- trunk/tests/node/runtest.pl 2008-12-16 18:24:46 UTC (rev 116) +++ trunk/tests/node/runtest.pl 2008-12-16 19:05:11 UTC (rev 117) @@ -81,5 +81,7 @@ ########################################################################### $test->regression("empty (13)", "./test_node-13", "data/13.out"); ########################################################################### + $test->regression("empty (14)", "./test_node-14", "data/14.out"); + ########################################################################### } ########################################################################### Added: trunk/tests/node/test_node-14.cxx =================================================================== --- trunk/tests/node/test_node-14.cxx (rev 0) +++ trunk/tests/node/test_node-14.cxx 2008-12-16 19:05:11 UTC (rev 117) @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * This test checks xml::node::node(text) + */ + +#include <xmlwrapp/xmlwrapp.h> +#include <iostream> +#include <exception> + +int main (int argc, char *argv[]) { + if (argc != 1) { + std::cerr << "Usage: " << argv[0] << "\n"; + return 1; + } + + try { + xml::node root("root"); + xml::node n(xml::node::text("some text")); + root.push_back(n); + std::cout << root; + } catch (const std::exception &e) { + std::cout << e.what() << std::endl; + return 1; + } + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |