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

pipe_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 // pipe_input.h
00030 
00031 #ifndef _CTTL_PIPE_INPUT_H_INCLUDED_
00032 #define _CTTL_PIPE_INPUT_H_INCLUDED_
00033 
00034 #include <iostream>
00035 #include <string>
00036 #include <vector>
00037 
00038 namespace cttl {
00039 
00041 inline size_t pipe_input_2_vector( std::vector< std::basic_string< unsigned char > >& vect_input_, std::basic_string< unsigned char > filter_ = std::basic_string< unsigned char >() )
00042 {
00043     std::basic_string< unsigned char > inp_text;
00044     char buffer[ CTTL_STD_CIN_BUFFER_SIZE ];
00045     while ( std::cin >> buffer ) {
00046         inp_text = reinterpret_cast< unsigned char* >( buffer );
00047         // line by line:
00048         if ( filter_.length() ) {
00049             if ( inp_text.find( filter_ ) != std::basic_string< unsigned char >::npos ) {
00050                 vect_input_.push_back( inp_text );
00051             } else {
00052             }
00053         } else {
00054             // no filter was specified
00055             vect_input_.push_back( inp_text );
00056         }
00057     }
00058     return vect_input_.size();
00059 }
00060 
00062 inline size_t pipe_input_2_vector( std::vector< std::basic_string< char > >& vect_input_, std::basic_string< char > filter_ = std::basic_string< char >() )
00063 {
00064     std::basic_string< char > inp_text;
00065     while ( std::cin >> inp_text ) {
00066         // line by line:
00067         if ( filter_.length() ) {
00068             if ( inp_text.find( filter_ ) != std::basic_string< char >::npos ) {
00069                 vect_input_.push_back( inp_text );
00070             } else {
00071             }
00072         } else {
00073             // no filter was specified
00074             vect_input_.push_back( inp_text );
00075         }
00076     }
00077     return vect_input_.size();
00078 }
00079 
00081 inline size_t pipe_input_2_string( std::basic_string< unsigned char >& str_output_, unsigned char delimiter_ = ( unsigned char )( '\t' ) )
00082 {
00083     std::basic_string< unsigned char > inp_text;
00084     char buffer[ CTTL_STD_CIN_BUFFER_SIZE ];
00085     while ( std::cin >> buffer ) {
00086         inp_text = reinterpret_cast< unsigned char* >( buffer );
00087         // line by line:
00088         str_output_ += inp_text;
00089         str_output_ += delimiter_;
00090     }
00091 
00092     return str_output_.length();
00093 }
00094 
00096 inline size_t pipe_input_2_string( std::basic_string< char >& str_output_, char delimiter_ = char( '\t' ) )
00097 {
00098     std::basic_string< char > inp_text;
00099     while ( std::cin >> inp_text ) {
00100         // line by line:
00101         str_output_ += inp_text;
00102         str_output_ += delimiter_;
00103     }
00104 
00105     return str_output_.length();
00106 }
00107 
00108 }//namespace cttl
00109 
00110 #endif //_CTTL_PIPE_INPUT_H_INCLUDED_

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