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