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
virtual time_t get_timestamp() const
Returns the on-disk timestamp of the file that was read, at the time it was opened,...
Keeps a reference-counted pointer to a file on disk.
Definition: fileReference.h:26
This class can be used to read a binary file that consists of an arbitrary header followed by a numbe...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
virtual bool save_datagram(SubfileInfo &info)
Skips over the next datagram without extracting it, but saves the relevant file information in the Su...
virtual const FileReference * get_file()
Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagr...
virtual VirtualFile * get_vfile()
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagram...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:26
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...
This class defines the abstract interace to any source of datagrams, whether it be from a file or fro...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
virtual const Filename & get_filename()
Returns the filename that provides the source for these datagrams, if any, or empty string if the dat...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.