libdballe
5.18
|
00001 /* 00002 * dballe/file - File I/O 00003 * 00004 * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * Author: Enrico Zini <enrico@enricozini.com> 00020 */ 00021 00022 #ifndef DBA_CORE_FILE_H 00023 #define DBA_CORE_FILE_H 00024 00037 #include <dballe/core/defs.h> 00038 #include <memory> 00039 #include <string> 00040 #include <cstdio> 00041 00042 namespace dballe { 00043 struct Rawmsg; 00044 00045 00046 class File 00047 { 00048 protected: 00050 std::string m_name; 00052 FILE* fd; 00054 bool close_on_exit; 00056 int idx; 00057 00058 public: 00059 File(const std::string& name, FILE* fd, bool close_on_exit=true); 00060 virtual ~File(); 00061 00065 FILE* stream() const throw () { return fd; } 00066 00073 const std::string& name() const throw () { return m_name; } 00074 00081 virtual Encoding type() const throw () = 0; 00082 00091 virtual bool read(Rawmsg& msg) = 0; 00092 00099 virtual void write(const Rawmsg& msg); 00100 00117 static std::auto_ptr<File> create(Encoding type, const std::string& name, const char* mode); 00118 }; 00119 00120 } // namespace dballe 00121 00122 /* vim:set ts=4 sw=4: */ 00123 #endif