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

xtl_identity_functors.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 
00048 // xtl_identity_functors.h
00049 
00050 #ifndef _CTTL_XTL_IDENTITY_FUNCTORS_H_INCLUDED_
00051 #define _CTTL_XTL_IDENTITY_FUNCTORS_H_INCLUDED_
00052 
00053 namespace cttl_impl {
00054 
00056     class xtl_identity_adjust_base {
00057     protected:
00058 
00060         size_t  m_insertion_point_offset;
00061 
00063         int     m_delta_offset;
00064 
00065     public:
00066 
00068         xtl_identity_adjust_base( size_t insertion_point_offset_, int delta_offset_ )
00069             :
00070             m_insertion_point_offset( insertion_point_offset_ ),
00071             m_delta_offset( delta_offset_ )
00072         {}
00073 
00074     };  // class xtl_identity_adjust_base
00075 
00083     template< typename StringT >
00084     class xtl_identity_collapse : public xtl_identity_adjust_base {
00085     public:
00087         xtl_identity_collapse( size_t insertion_point_offset_, int delta_offset_ )
00088             :
00089             xtl_identity_adjust_base( insertion_point_offset_, delta_offset_ )
00090         {}
00091 
00114         void adjust( size_t& target_offset_ ) const
00115         {
00116 
00117             if ( target_offset_ == StringT::npos )
00118                 return;
00119 
00120             if ( target_offset_ < m_insertion_point_offset ) {
00121                 if ( ( m_insertion_point_offset + m_delta_offset ) < target_offset_ )
00122                     target_offset_ = m_insertion_point_offset + m_delta_offset;
00123 
00124                 return; // skip low-offset nodes
00125             }
00126             target_offset_ += m_delta_offset;
00127         }
00128     };  // class xtl_identity_collapse
00129 
00130 
00138     template< typename StringT >
00139     class xtl_identity_insert_go : public xtl_identity_adjust_base {
00140     public:
00141 
00143         xtl_identity_insert_go( size_t insertion_point_offset_, int delta_offset_ )
00144             :
00145             xtl_identity_adjust_base( insertion_point_offset_, delta_offset_ )
00146         {}
00147 
00154         void adjust( size_t& target_offset_ ) const
00155         {
00156             if ( target_offset_ == StringT::npos )
00157                 return;
00158 
00159             if ( target_offset_ >= m_insertion_point_offset )
00160                 target_offset_ += m_delta_offset;
00161         }
00162     };  // class xtl_identity_insert_go
00163 
00164 
00172     template< typename StringT >
00173     class xtl_identity_insert_stay : public xtl_identity_adjust_base {
00174     public:
00175 
00177         xtl_identity_insert_stay( size_t insertion_point_offset_, int delta_offset_ )
00178             :
00179             xtl_identity_adjust_base( insertion_point_offset_, delta_offset_ )
00180         {}
00181 
00188         void adjust( size_t& target_offset_ ) const
00189         {
00190             if ( target_offset_ == StringT::npos )
00191                 return;
00192 
00193             if ( target_offset_ > m_insertion_point_offset )
00194                 target_offset_ += m_delta_offset;
00195         }
00196     };  // class xtl_identity_insert_stay
00197 
00198 }   // namespace cttl_impl
00199 
00200 #endif // _CTTL_XTL_IDENTITY_FUNCTORS_H_INCLUDED_

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