/Users/jack/Code/basso_dev/inc/TextInput.h

Go to the documentation of this file.
00001 
00011 #ifndef _TEXT_INPUT_BASSO_H_
00012 #define _TEXT_INPUT_BASSO_H_
00013 
00014 // std includes 
00015 #include <map>
00016 
00017 // Basso includes
00018 #include "Basso.h" 
00019 #include "Input.h"
00020 
00021 namespace basso {
00022 
00023 
00024 
00034 class TextInput : public Input {
00035         
00036 public:
00037 
00043         TextInput( char keyword='$', char comment='#' ) : Input( ) 
00044                 { fKeyword=keyword; fComment=comment; }
00045                 
00046         TextInput( const String &file, char keyword='$', char comment='#' ) : Input(file) 
00047                 { fKeyword=keyword; fComment=comment; }
00048         
00049         virtual ~TextInput() { }
00050 
00051         virtual int ProcessFile();
00052         
00059         int GetCards( const String &keyword, list<InputCard> &cards ) const;
00060         
00066         int GetCard( const String &keyword, InputCard &card ) const;
00067         
00068 protected:      
00069         multimap< String, InputCard > fCards;
00070         char fKeyword, fComment;
00071                 
00072 };
00073         
00074 int TextInput::GetCards( const String &keyword, list<InputCard> &cards ) const
00075 {
00076         cards.clear();
00077         
00078         pair< multimap<String,InputCard>::const_iterator, 
00079                 multimap<String,InputCard>::const_iterator > range;
00080         range = fCards.equal_range( keyword );
00081         
00082         if ( range.first!=fCards.end() ) {
00083                 multimap<String,InputCard>::const_iterator itr;
00084                 for ( itr=range.first; itr!=range.second; ++itr )
00085                         cards.push_back( itr->second );
00086                 return 1;
00087         }
00088         return 0;
00089 }
00090 
00091 int TextInput::GetCard( const String &keyword, InputCard &card ) const
00092 {
00093         multimap<String,InputCard>::const_iterator itr=fCards.find(keyword);
00094         if ( itr!=fCards.end() ) {
00095                 card = itr->second;
00096                 return 1;
00097         }
00098         return 0;       
00099 }
00100 
00101 int TextInput::ProcessFile()
00102 {
00103         ifstream inFile;
00104         if ( OpenFile(inFile) )
00105                 return 1;
00106         
00107         InputCard card('$','#');
00108         
00109         while ( !inFile.eof() ) {
00110                 card.Read(inFile);      
00111                 fCards.insert( pair<String,InputCard>(card.Keyword(),card) );
00112         }
00113         
00114         CloseFile(inFile);
00115         
00116 }
00117 
00118 } // end namespace
00119 
00120 #endif

Generated on Sat Jan 19 09:03:57 2008 for Basso by  doxygen 1.5.2