lineBasedFile.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: lineBasedFile.h,v 1.32.20.1 2007/03/28 08:23:44 bertsch Exp $
00005 //
00006 
00007 #ifndef BALL_FORMAT_LINEBASEDFILE_H
00008 #define BALL_FORMAT_LINEBASEDFILE_H
00009 
00010 #ifndef BALL_SYSTEM_FILE_H
00011 # include <BALL/SYSTEM/file.h>
00012 #endif
00013 
00014 #include <vector>
00015 
00016 namespace BALL 
00017 {
00022   class BALL_EXPORT LineBasedFile
00023     : public File
00024   {
00025     public:
00026 
00027     BALL_CREATE(LineBasedFile)
00028 
00029     
00032 
00034     LineBasedFile()
00035       ;
00036       
00042     LineBasedFile(const String& filename, File::OpenMode open_mode = std::ios::in, bool trim_whitespaces = false)
00043       throw(Exception::FileNotFound);
00044 
00048     LineBasedFile(const LineBasedFile& f)
00049       throw(Exception::FileNotFound);
00050 
00053     void clear() 
00054       ;
00055 
00057 
00060 
00063     bool operator == (const LineBasedFile& f)  ;
00064 
00067     bool operator != (const LineBasedFile& f)  ;
00069 
00073       
00077     const LineBasedFile& operator = (const LineBasedFile& file)
00078       throw(Exception::FileNotFound);
00079 
00081 
00084 
00086     Position getLineNumber() 
00087       const ;
00088 
00090     const String& getLine() 
00091       const ;
00092 
00094     String& getLine() 
00095       ;
00096 
00098 
00101 
00105     bool readLine()
00106       throw(Exception::ParseError);
00107 
00111     bool skipLines(Size number = 1)
00112       throw(Exception::ParseError);
00113 
00119     bool search(const String& text, bool return_to_start = false)
00120       throw(Exception::ParseError);
00121 
00122     /* Search for a line starting with a given string, abort at a stop tag.
00123     */
00124     bool search(const String& text, const String& stop, bool return_to_start = false)
00125       throw(Exception::ParseError);
00126 
00130     bool gotoLine(Position line_number)
00131       throw(Exception::ParseError);
00132 
00135     void rewind()
00136       throw(Exception::ParseError);
00137 
00150     void test(const char* file, int line, bool condition, const String& msg) 
00151       const throw(Exception::ParseError);
00152 
00155     String getField(Index pos = 0, const String& quotes = "",
00156                     const String& delimiters = String::CHARACTER_CLASS__WHITESPACE)
00157       const throw(Exception::IndexUnderflow);
00158 
00160     bool startsWith(const String& text) 
00161       const ;
00162 
00164     bool has(const String& text) 
00165       const ;
00166 
00170     Index switchString(const std::vector<String>& data) 
00171       const ;
00172 
00177     bool parseColumnFormat(const char* format, Position index, Size length, void* arg);
00178 
00180     void enableTrimWhitespaces(bool state)
00181       ;
00182     
00184     bool trimWhiteSpacesEnabled() const
00185       ;
00186 
00187     protected:
00189     /*  @name Protected Attributes
00190     */
00191     //_@{
00193     String line_;
00194 
00196     Position line_number_;
00197 
00198     bool trim_whitespaces_;
00199     //_@}
00200   };
00201 
00202 
00203 # ifndef BALL_NO_INLINE_FUNCTIONS
00204 #   include <BALL/FORMAT/lineBasedFile.iC>
00205 # endif
00206 } // namespace BALL
00207 
00208 #endif // BALL_FORMAT_LINEBASEDFILE_H