Panda3D

datagramInputFile.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file datagramInputFile.h
10 * @author drose
11 * @date 2000-10-30
12 */
13
14 #ifndef DATAGRAMINPUTFILE_H
15 #define DATAGRAMINPUTFILE_H
16
17 #include "pandabase.h"
18
19 #include "datagramGenerator.h"
20 #include "filename.h"
21 #include "fileReference.h"
22 #include "virtualFile.h"
23
24 /**
25 * This class can be used to read a binary file that consists of an arbitrary
26 * header followed by a number of datagrams.
27 */
28 class EXPCL_PANDA_PUTIL DatagramInputFile : public DatagramGenerator {
29 PUBLISHED:
30 INLINE DatagramInputFile();
31 INLINE ~DatagramInputFile();
32
33 bool open(const FileReference *file);
34 INLINE bool open(const Filename &filename);
35 bool open(std::istream &in, const Filename &filename = Filename());
36 INLINE std::istream &get_stream();
37
38 void close();
39
40 bool read_header(std::string &header, size_t num_bytes);
41 virtual bool get_datagram(Datagram &data);
42 virtual bool save_datagram(SubfileInfo &info);
43 virtual bool is_eof();
44 virtual bool is_error();
45
46 virtual const Filename &get_filename();
47 virtual time_t get_timestamp() const;
48 virtual const FileReference *get_file();
49 virtual VirtualFile *get_vfile();
50 virtual std::streampos get_file_pos();
51
52 private:
53 bool _read_first_datagram;
54 bool _error;
55 CPT(FileReference) _file;
56 PT(VirtualFile) _vfile;
57 std::istream *_in;
58 bool _owns_in;
59 Filename _filename;
60 time_t _timestamp;
61 };
62
63 #include "datagramInputFile.I"
64
65 #endif
DatagramGenerator
This class defines the abstract interace to any source of datagrams, whether it be from a file or fro...
Definition: datagramGenerator.h:30
DatagramGenerator::get_file_pos
virtual std::streampos get_file_pos()
Returns the current file position within the data stream, if any, or 0 if the file position is not me...
Definition: datagramGenerator.cxx:90
DatagramGenerator::get_file
virtual const FileReference * get_file()
Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagr...
Definition: datagramGenerator.cxx:68
DatagramGenerator::get_filename
virtual const Filename & get_filename()
Returns the filename that provides the source for these datagrams, if any, or empty string if the dat...
Definition: datagramGenerator.cxx:45
DatagramGenerator::get_timestamp
virtual time_t get_timestamp() const
Returns the on-disk timestamp of the file that was read, at the time it was opened,...
Definition: datagramGenerator.cxx:59
DatagramGenerator::save_datagram
virtual bool save_datagram(SubfileInfo &info)
Skips over the next datagram without extracting it, but saves the relevant file information in the Su...
Definition: datagramGenerator.cxx:36
DatagramGenerator::get_vfile
virtual VirtualFile * get_vfile()
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagram...
Definition: datagramGenerator.cxx:77
DatagramInputFile
This class can be used to read a binary file that consists of an arbitrary header followed by a numbe...
Definition: datagramInputFile.h:28
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
FileReference
Keeps a reference-counted pointer to a file on disk.
Definition: fileReference.h:26
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
SubfileInfo
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:26
VirtualFile
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:35
datagramGenerator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagramInputFile.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fileReference.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtualFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.