Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

xml_tree_show.h

Go to the documentation of this file.
00001 
00002 // Common Text Transformation Library
00003 // Copyright (C) 1997-2006 by Igor Kholodov. 
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the
00017 // Free Software Foundation, Inc.,
00018 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 // mailto:cttl@users.sourceforge.net
00021 // http://sourceforge.net/projects/cttl/
00023 
00029 // xml_tree_show.h
00030 
00031 #ifndef _XML_TREE_SHOW_H_INCLUDED_
00032 #define _XML_TREE_SHOW_H_INCLUDED_
00033 
00034 using namespace cttl;
00035 
00041 struct xml_tree_show : public std::unary_function< inode_reader<>, void >
00042 {
00044     size_t level;
00045 
00047     std::vector< std::string > const& vect_xml_names;
00048 
00050     std::vector< std::string > const& vect_xml_text;
00051 
00053     xml_tree_show(
00054         size_t level_,
00055         std::vector< std::string > const& vect_xml_names_,
00056         std::vector< std::string > const& vect_xml_text_
00057         )
00058         :
00059         level( level_ ),
00060         vect_xml_names( vect_xml_names_ ),
00061         vect_xml_text( vect_xml_text_ )
00062     {
00063     }
00064 
00066     void operator=( xml_tree_show const& ) const
00067     {
00068     }
00069 
00071     void show_level( char c_ = '.' ) const
00072     {
00073         for ( size_t lvl = 0; lvl < level; ++lvl )
00074             std::cout << c_;
00075     }
00076 
00078     void operator() ( inode_reader<> const& inode_ ) const
00079     {
00080         show_level();
00081         std::cout
00082             /*
00083             << "element("
00084             << inode_.offset()
00085             <<") = "
00086             << inode_[ ELEMENT_NAME ] << '^'
00087             << inode_[ FIRST_ATTRIBUTE ] << '^'
00088             << inode_[ LAST_ATTRIBUTE ] << '^'
00089             << inode_[ FIRST_TEXT ] << '^'
00090             << inode_[ LAST_TEXT ] << '^'
00091             << inode_[ FIRST_ELEMENT ] << '^'
00092             << inode_[ LAST_ELEMENT ]
00093             << '\t'
00094             */
00095             << vect_xml_names[ inode_[ ELEMENT_NAME ] ]
00096             << std::endl
00097             ;
00098 
00099         for ( inode_reader<> attr = inode_( FIRST_ATTRIBUTE ); attr != inode_.end(); ++attr ) {
00100             show_level();
00101             std::cout
00102                 << '.'
00103                 << vect_xml_names[ attr[ ATTRIBUTE_NAME ] ]
00104                 /*
00105                 << "attribute("
00106                 << attr.offset()
00107                 <<") = "
00108                 << attr[ ATTRIBUTE_NAME ] << '^'
00109                 << attr[ ATTRIBUTE_VALUE ]
00110                 */
00111                 << '='
00112                 << vect_xml_text[ attr[ ATTRIBUTE_VALUE ] ]
00113                 << std::endl
00114                 ;
00115         }
00116 
00117         for ( inode_reader<> txt = inode_( FIRST_TEXT ); txt != inode_.end(); ++txt ) {
00118             show_level();
00119             std::cout
00120                 << '.'
00121                 << "txt="
00122                 << vect_xml_text[ txt[ TEXT_VALUE ] ]
00123                 << std::endl
00124                 ;
00125         }
00126 
00127         std::for_each(
00128             inode_( FIRST_ELEMENT ),
00129             inode_.end(),
00130             xml_tree_show(
00131                 level + 1,
00132                 vect_xml_names,
00133                 vect_xml_text
00134                 )
00135             );
00136 
00137     }
00138     
00139 }; // struct xml_tree_show
00140 
00141 
00142 #endif //_XML_TREE_SHOW_H_INCLUDED_

Generated on Thu Nov 2 17:43:27 2006 for CTTL XML stream parser sample by  doxygen 1.3.9.1