5 // Written by Curtis Olson, started November 1999.
7 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <simgear/compiler.h>
33 #include "iochannel.hxx"
37 * A file I/O class based on SGIOChannel.
39 class SGFile : public SGIOChannel {
41 std::string file_name;
44 // Number of repetitions to play. -1 means loop infinitely.
46 int iteration; // number of current repetition,
52 * Create an instance of SGFile.
53 * When calling the constructor you need to provide a file
54 * name. This file is not opened immediately, but instead will be
55 * opened when the open() method is called.
56 * @param file name of file to open
57 * @param repeat On eof restart at the beginning of the file
59 SGFile( const std::string& file, int repeat_ = 1 );
62 * Create an SGFile from an existing, open file-descriptor
64 SGFile( int existingFd );
69 // open the file based on specified direction
70 bool open( const SGProtocolDir dir );
72 // read a block of data of specified size
73 int read( char *buf, int length );
75 // read a line of data, length is max size of input buffer
76 int readline( char *buf, int length );
78 // write data to a file
79 int write( const char *buf, const int length );
81 // write null terminated string to a file
82 int writestring( const char *str );
87 /** @return the name of the file being manipulated. */
88 inline std::string get_file_name() const { return file_name; }
90 /** @return true of eof conditions exists */
91 virtual bool eof() const { return eof_flag; };
95 #endif // _SG_FILE_HXX