00001
00002 #ifndef _TEXTFILE_H
00003 #define _TEXTFILE_H
00004
00005 #include <cstdio>
00006 #include <string>
00007 #include <vector>
00008
00009 #include "IOResource.h"
00010
00011 namespace gk {
00012
00013
00014 struct TextSection
00015 {
00016 std::string filename;
00017 int line;
00018 std::string text;
00019
00020 TextSection( const std::string& _filename, const int _line= 1 )
00021 :
00022 filename(_filename),
00023 line(_line)
00024 {}
00025
00026 TextSection( const std::string& _text, const std::string& _filename, const int _line )
00027 :
00028 filename(_filename),
00029 line(_line),
00030 text(_text)
00031 {}
00032 };
00033
00034
00035 class TextFile : public IOResource
00036 {
00037 std::vector<TextSection> m_definitions;
00038 std::vector<TextSection> m_sections;
00039 std::string m_name;
00040
00041 int read( TextSection& section, FILE *in );
00042
00043 public:
00044 TextFile( const std::string& name )
00045 :
00046 m_name(name)
00047 {}
00048
00049 ~TextFile( ) {}
00050
00051
00052 int read( const std::string& filename );
00053
00054
00055 int include( const std::string& filename );
00056
00057
00058 int include( const std::string& source, const std::string& filename, const int line );
00059
00060
00061 int include( const TextFile *text );
00062
00063
00064 int define( const std::string& what, const std::string& value );
00065
00066
00067 std::string string( ) const;
00068
00069
00070 int getLine( const int line, std::string &string, std::string& file_name, int &file_line );
00071
00072
00073 const std::string& name( ) const
00074 {
00075 return m_name;
00076 }
00077
00078
00079 void print( ) const;
00080 };
00081
00082 }
00083
00084 #endif