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

input.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 // input.h
00030 
00031 #ifndef _CTTL_INPUT_H_INCLUDED_
00032 #define _CTTL_INPUT_H_INCLUDED_
00033 
00034 #include "xtl_container.h"
00035 
00041 namespace cttl {
00042 
00043 using namespace cttl_impl;
00044 
00063 template< typename StringT = CTTL_STD_STRING >
00064 class input
00065 {
00066 private:
00067 
00069     xtl_text_container< StringT > m_container;
00070 
00071 public:
00073     typedef StringT string_T;
00074 
00076     typedef typename string_T::value_type char_T;
00077 
00079     // CONSTRUCTORS OF THE INPUT OBJECT //
00081 
00089     input( size_t vector_size_ = xtl_identity_vector_default_size )
00090         :
00091         m_container( xtl_flag_default, vector_size_ )
00092     {
00093     }
00094 
00105     input(
00106         char_T const* pchar_,
00107         size_t  vector_size_ = xtl_identity_vector_default_size
00108         )
00109         :
00110         m_container( pchar_, xtl_flag_default, vector_size_ )
00111     {
00112     }
00113 
00131     input(
00132         char_T* array_[],
00133         char_T delimiter_ = char_T( '\n' ),
00134         size_t vector_size_ = xtl_identity_vector_default_size
00135         )
00136         :
00137         m_container( xtl_flag_default, vector_size_ )
00138     {
00139         string_array2string( m_container.text(), array_, delimiter_ );
00140     }
00141 
00152     input(
00153         string_T const& str_,
00154         size_t  vector_size_ = xtl_identity_vector_default_size
00155         )
00156         :   m_container( str_, xtl_flag_default, vector_size_ )
00157     {
00158     }
00159 
00161     ~input()
00162     {
00163         assert( !m_container.stack_size() );
00164     }
00165 
00166 private:
00167     /*Copy constructor is disabled due to complexity of @c input object.*/
00168     explicit input( input const& )
00169     {
00170     }
00171 
00172     /*Assignment operator is disabled due to complexity of @c input object.*/
00173      input const& operator=( input const& )
00174     {
00175         return *this;
00176     }
00177 
00178 public:
00180     // PROPERTIES OF THE INPUT CLASS //
00182 
00183     xtl_text_container< StringT >& container()
00184     {
00185         return m_container;
00186     }
00187 
00189     xtl_text_container< StringT > const& container() const
00190     {
00191         return m_container;
00192     }
00193 
00207     size_t vector_size( size_t new_size_ )
00208     {
00209         return m_container.identity_vector_size( new_size_ );
00210     }
00211 
00213     size_t vector_size()
00214     {
00215         return m_container.identity_vector_size();
00216     }
00217 
00219     // Functions to store and access user input
00221 
00223     void text( char_T const* pchar_ )
00224     {
00225         m_container.text( pchar_ );
00226     }
00227 
00229     void text( string_T const& str_ )
00230     {
00231         m_container.text( str_ );
00232     }
00233 
00235     string_T const& text() const
00236     {
00237         return m_container.text();
00238     }
00239 
00241     string_T& text()
00242     {
00243         return container().text();
00244     }
00245  
00247     size_t length() const
00248     {
00249         return text().length();
00250     }
00251 
00252 };  // class input
00253 
00254 
00255 }   // namespace cttl
00256 
00257 #endif // _CTTL_INPUT_H_INCLUDED_

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