libdballe  6.8
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
FILE * fd
FILE structure used to read or write to the file.
Definition: file.h:52
virtual void write(const Rawmsg &msg)
Write the encoded message data to the file.
Common definitions.
Definition: cmdline.h:34
Definition: file.h:46
static std::auto_ptr< File > create(Encoding type, const std::string &name, const char *mode)
Create a dba_file structure.
std::string m_name
Name of the file.
Definition: file.h:50
virtual bool read(Rawmsg &msg)=0
Read a message from the file.
int idx
Index of the last message read from the file or written to the file.
Definition: file.h:56
const std::string & name() const
Get the type of the dba_file.
Definition: file.h:73
Annotated string buffer for encoded messages.
Definition: rawmsg.h:38
FILE * stream() const
Get the file stream.
Definition: file.h:65
virtual Encoding type() const =0
Get the name of the dba_file.
bool close_on_exit
Set to true if fd should be closed when dba_file_delete() is called.
Definition: file.h:54