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

inode_reader.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 // inode_reader.h
00030 
00031 #ifndef _CTTL_INODE_READER_H_INCLUDED_
00032 #define _CTTL_INODE_READER_H_INCLUDED_
00033 
00034 #include <cassert>
00035 #include <vector>
00036 #include <iterator>
00037 #include <functional>
00038 
00039 namespace cttl {
00040 
00071 template< int PreviousLinkT = 1, int NextLinkT = 0, typename ContainerT = std::vector< int > >
00072 #ifdef __SGI_STL_PORT
00073 struct inode_reader : public stlport::bidirectional_iterator< inode_reader< PreviousLinkT, NextLinkT, ContainerT > > 
00074 #else
00075 struct inode_reader
00076 #endif
00077 {
00079     static const int previous_link_field = PreviousLinkT;
00080 
00082     static const int next_link_field = NextLinkT;
00083 
00085     typedef ContainerT container_T;
00086 
00088     typedef typename ContainerT::reference container_reference_T;
00089 
00091     typedef typename ContainerT::const_reference container_const_reference_T;
00092 
00094     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >       iterator;
00095 
00097     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >       const_iterator;
00098 
00100     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >        value_type;
00101 
00103     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >*       pointer;
00104 
00106     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >        reference;
00107 
00109     typedef inode_reader< PreviousLinkT, NextLinkT, ContainerT >        const_reference;
00110 
00112     typedef typename ContainerT::size_type size_type;
00113 
00115     typedef ptrdiff_t    difference_type;
00116 
00118     typedef std::bidirectional_iterator_tag iterator_category;
00119 
00120     // constructors
00121 
00123     inode_reader()
00124         :
00125         m_offset( 0 ),
00126         m_ptr_container( NULL )
00127     {
00128     }
00129 
00131     inode_reader( inode_reader< PreviousLinkT, NextLinkT, ContainerT > const& other_ )
00132         :
00133         m_offset( other_.m_offset ),
00134         m_ptr_container( other_.m_ptr_container )
00135     {
00136     }
00137 
00139     inode_reader( ContainerT& container_ )
00140         :
00141         m_offset( container_.size() ),
00142         m_ptr_container( &container_ )
00143     {
00144     }
00145 
00147     inode_reader( ContainerT& container_, size_type offset_ )
00148         :
00149         m_offset( offset_ ),
00150         m_ptr_container( &container_ )
00151     {
00152     }
00153 
00155     inode_reader< PreviousLinkT, NextLinkT, ContainerT >& operator=( inode_reader< PreviousLinkT, NextLinkT, ContainerT > const& other_ )
00156     {
00157         if ( this != &other_ ) {
00158             m_offset = other_.m_offset;
00159             m_ptr_container = other_.m_ptr_container;
00160         }
00161 
00162         return *this;
00163     }
00164 
00166     const_reference operator*() const
00167     {
00168         return *this;
00169     }
00170 
00172     reference operator*()
00173     {
00174         return *this;
00175     }
00176 
00178     value_type const* operator->() const
00179     {
00180         return this;
00181     }
00182 
00184     value_type* operator->()
00185     {
00186         return this;
00187     }
00188 
00190     inode_reader< PreviousLinkT, NextLinkT, ContainerT >& operator++()
00191     {
00192         offset( value( NextLinkT ) );
00193         return *this;
00194     }
00195 
00197     inode_reader< PreviousLinkT, NextLinkT, ContainerT > operator++( int )
00198     {
00199         inode_reader< PreviousLinkT, NextLinkT, ContainerT > sibling( *this );
00200         offset( value( NextLinkT ) );
00201         return sibling;
00202     }
00203 
00205     inode_reader< PreviousLinkT, NextLinkT, ContainerT >& operator--()
00206     {
00207         offset( value( PreviousLinkT ) );
00208         return *this;
00209     }
00210 
00212     inode_reader< PreviousLinkT, NextLinkT, ContainerT > operator--( int )
00213     {
00214         inode_reader< PreviousLinkT, NextLinkT, ContainerT > sibling( *this );
00215         offset( value( PreviousLinkT ) );
00216         return sibling;
00217     }
00218 
00220     bool operator== ( inode_reader< PreviousLinkT, NextLinkT, ContainerT > const& other_ ) const
00221     {
00222         return ( offset() == other_.offset() );
00223     }
00224 
00226     bool operator!= ( inode_reader< PreviousLinkT, NextLinkT, ContainerT > const& other_ ) const
00227     {
00228         return ( offset() != other_.offset() );
00229     }
00230 
00232     inode_reader< PreviousLinkT, NextLinkT, ContainerT > begin() const
00233     {
00234         return inode_reader< PreviousLinkT, NextLinkT, ContainerT >( *m_ptr_container, 0 );
00235     }
00236 
00238     inode_reader< PreviousLinkT, NextLinkT, ContainerT > begin( int offset_ ) const
00239     {
00240         return inode_reader< PreviousLinkT, NextLinkT, ContainerT >( *m_ptr_container, offset_ );
00241     }
00242 
00244     inode_reader< PreviousLinkT, NextLinkT, ContainerT > end() const
00245     {
00246         return begin();
00247     }
00248 
00250     // Position and data access functions
00252 
00254     container_reference_T value( int field_ )
00255     {
00256         return (*m_ptr_container)[ m_offset + field_ ];
00257     }
00258 
00260     container_const_reference_T value( int field_ ) const
00261     {
00262         return (*m_ptr_container)[ m_offset + field_ ];
00263     }
00264 
00266     container_reference_T operator[] ( int field_ )
00267     {
00268         return value( field_ );
00269     }
00270 
00272     container_const_reference_T operator[] ( int field_ ) const
00273     {
00274         return value( field_ );
00275     }
00276 
00278     void offset( size_type offset_ )
00279     {
00280         m_offset = offset_;
00281     }
00282 
00284     size_type offset() const
00285     {
00286         return m_offset;
00287     }
00288 
00290     // Tree linkage helper functions
00292 
00294     inode_reader< PreviousLinkT, NextLinkT, ContainerT > operator() ( int field_ ) const
00295     {
00296         return inode_reader< PreviousLinkT, NextLinkT, ContainerT >( *m_ptr_container, value( field_ ) );
00297     }
00298 
00300     int next_link() const
00301     {
00302         return NextLinkT;
00303     }
00304 
00306     int previous_link() const
00307     {
00308         return PreviousLinkT;
00309     }
00310 
00311 protected:
00313     // inode_reader state variables
00315 
00317     size_type m_offset;
00318 
00320     ContainerT* m_ptr_container;
00321 
00322 }; // inode_reader
00323 
00324 
00325 }   // namespace cttl
00326 
00327 #endif // _CTTL_INODE_READER_H_INCLUDED_

Generated on Thu Nov 2 17:43:39 2006 for CTTL Utility Classes and Functions by  doxygen 1.3.9.1