00001 00005 // Written by Curtis Olson, started November 1999. 00006 // 00007 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License as 00011 // published by the Free Software Foundation; either version 2 of the 00012 // License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, but 00015 // WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 // 00023 // $Id: sg__file_8hxx-source.html,v 1.15 2007-12-17 15:37:10 curt Exp $ 00024 00025 00026 #ifndef _SG_FILE_HXX 00027 #define _SG_FILE_HXX 00028 00029 00030 #ifndef __cplusplus 00031 # error This library requires C++ 00032 #endif 00033 00034 #include <simgear/compiler.h> 00035 00036 #include <string> 00037 00038 #include <sys/types.h> // for open(), read(), write(), close() 00039 #include <sys/stat.h> // for open(), read(), write(), close() 00040 #include <fcntl.h> // for open(), read(), write(), close() 00041 #if !defined( _MSC_VER ) 00042 # include <unistd.h> // for open(), read(), write(), close() 00043 #endif 00044 00045 #include "iochannel.hxx" 00046 00047 SG_USING_STD(string); 00048 00049 00053 class SGFile : public SGIOChannel { 00054 00055 string file_name; 00056 int fp; 00057 bool eof_flag; 00058 00059 public: 00060 00068 SGFile( const string& file ); 00069 00071 ~SGFile(); 00072 00073 // open the file based on specified direction 00074 bool open( const SGProtocolDir dir ); 00075 00076 // read a block of data of specified size 00077 int read( char *buf, int length ); 00078 00079 // read a line of data, length is max size of input buffer 00080 int readline( char *buf, int length ); 00081 00082 // write data to a file 00083 int write( const char *buf, const int length ); 00084 00085 // write null terminated string to a file 00086 int writestring( const char *str ); 00087 00088 // close file 00089 bool close(); 00090 00092 inline string get_file_name() const { return file_name; } 00093 00095 inline bool eof() const { return eof_flag; }; 00096 }; 00097 00098 00099 #endif // _SG_FILE_HXX 00100 00101
1.5.1