Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

xtl_edge_trait.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 
00038 // xtl_edge_trait.h
00039 
00040 #ifndef _CTTL_XTL_EDGE_TRAIT_H_INCLUDED_
00041 #define _CTTL_XTL_EDGE_TRAIT_H_INCLUDED_
00042 
00043 #include "xtl_container_impl.h"
00044 
00045 namespace cttl_impl {
00046 
00051 class xtl_const_offset_manager
00052 {
00054     size_t m_offset;
00055 public:
00063     template< typename StringT >
00064     xtl_const_offset_manager( xtl_text_container< StringT >&, size_t offset_ )
00065         :
00066         m_offset( offset_ )
00067     {
00068     }
00069 
00071     xtl_const_offset_manager& operator=( size_t offset_ )
00072     {
00073         m_offset = offset_;
00074         return *this;
00075     }
00076 
00078     operator size_t() const
00079     {
00080         return m_offset;
00081     }
00082 };
00083 
00095 template< typename StringT >
00096 class xtl_mutable_offset_manager
00097 {
00099     xtl_text_container< StringT >& m_container;
00100 
00105     size_t m_stack_identity;
00106 
00107 public:
00108 
00115     xtl_mutable_offset_manager( xtl_text_container< StringT >& container_, size_t offset_ )
00116         :
00117         m_container( container_ )
00118     {
00119         m_stack_identity = m_container.stack_size();
00120         m_container.push_offset( offset_ );
00121     }
00122 
00129     ~xtl_mutable_offset_manager()
00130     {
00131         m_container.pop_offset();
00132     }
00133 
00135     xtl_mutable_offset_manager< StringT >& operator=( size_t offset_ )
00136     {
00137         m_container.stack_offset( m_stack_identity, offset_ );
00138         return *this;
00139     }
00140 
00142     xtl_mutable_offset_manager< StringT >& operator=( xtl_mutable_offset_manager< StringT > const& other_ )
00143     {
00144         m_container.stack_offset( m_stack_identity, size_t( other_ ) );
00145         return *this;
00146     }
00147 
00149     operator size_t() const
00150     {
00151         return m_container.stack_offset( m_stack_identity );
00152     }
00153 
00155     size_t stack_identity() const
00156     {
00157         return m_stack_identity;
00158     }
00159 };
00160 
00161 
00173 template< typename EdgeT >
00174 struct xtl_edge_offset_manager
00175 {
00180     typename EdgeT::offset_manager_T first;
00181 
00186     typename EdgeT::offset_manager_T second;
00187 
00197     xtl_edge_offset_manager( EdgeT& edge_ )
00198         :
00199         first( edge_.parent().container(), edge_.first.offset() ),
00200         second( edge_.parent().container(), edge_.second.offset() )
00201     {
00202     }
00203 
00212     void save( EdgeT& edge_ )
00213     {
00214         first = edge_.first.offset();
00215         second = edge_.second.offset();
00216     }
00217 
00226     void swap( EdgeT& edge_ )
00227     {
00228         size_t temp = first;
00229         first = edge_.first.offset();
00230         edge_.first.offset( temp );
00231 
00232         temp = second;
00233         second = edge_.second.offset();
00234         edge_.second.offset( temp );
00235     }
00236 
00245     void restore( EdgeT& edge_ )
00246     {
00247         edge_.first.offset( first );
00248         edge_.second.offset( second );
00249     }
00250 };  // struct xtl_edge_offset_manager
00251 
00252 }   // namespace cttl_impl
00253 
00254 #endif // _CTTL_XTL_EDGE_TRAIT_H_INCLUDED_

Generated on Thu Nov 2 17:44:06 2006 for Common Text Transformation Library by  doxygen 1.3.9.1