libdballe  5.18
file.h
Go to the documentation of this file.
1 /*
2  * dballe/file - File I/O
3  *
4  * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_CORE_FILE_H
23 #define DBA_CORE_FILE_H
24 
37 #include <dballe/core/defs.h>
38 #include <memory>
39 #include <string>
40 #include <cstdio>
41 
42 namespace dballe {
43 struct Rawmsg;
44 
45 
46 class File
47 {
48 protected:
50  std::string m_name;
52  FILE* fd;
56  int idx;
57 
58 public:
59  File(const std::string& name, FILE* fd, bool close_on_exit=true);
60  virtual ~File();
61 
65  FILE* stream() const throw () { return fd; }
66 
73  const std::string& name() const throw () { return m_name; }
74 
81  virtual Encoding type() const throw () = 0;
82 
91  virtual bool read(Rawmsg& msg) = 0;
92 
99  virtual void write(const Rawmsg& msg);
100 
117  static std::auto_ptr<File> create(Encoding type, const std::string& name, const char* mode);
118 };
119 
120 } // namespace dballe
121 
122 /* vim:set ts=4 sw=4: */
123 #endif