Panda3D
datagramOutputFile.h
1 // Filename: datagramOutputFile.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 DATAGRAMOUTPUTFILE_H
16 #define DATAGRAMOUTPUTFILE_H
17 
18 #include "pandabase.h"
19 
20 #include "datagramSink.h"
21 #include "filename.h"
22 #include "fileReference.h"
23 #include "virtualFile.h"
24 #include "virtualFileSystem.h"
25 #include "config_util.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : DatagramOutputFile
29 // Description : This class can be used to write a binary file that
30 // consists of an arbitrary header followed by a number
31 // of datagrams.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_PUTIL DatagramOutputFile : public DatagramSink {
34 public:
35  INLINE DatagramOutputFile();
36  INLINE ~DatagramOutputFile();
37 
38  bool open(const FileReference *file);
39  INLINE bool open(const Filename &filename);
40  bool open(ostream &out, const Filename &filename = Filename());
41  INLINE ostream &get_stream();
42 
43  void close();
44 
45  bool write_header(const string &header);
46  virtual bool put_datagram(const Datagram &data);
47  virtual bool copy_datagram(SubfileInfo &result, const Filename &filename);
48  virtual bool copy_datagram(SubfileInfo &result, const SubfileInfo &source);
49  virtual bool is_error();
50  virtual void flush();
51 
52  virtual const Filename &get_filename();
53  virtual const FileReference *get_file();
54  virtual streampos get_file_pos();
55 
56 private:
57  bool _wrote_first_datagram;
58  bool _error;
59  CPT(FileReference) _file;
60  PT(VirtualFile) _vfile;
61  ostream *_out;
62  bool _owns_out;
63  Filename _filename;
64 };
65 
66 #include "datagramOutputFile.I"
67 
68 #endif
Keeps a reference-counted pointer to a file on disk.
Definition: fileReference.h:29
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:37
This class defines the abstract interface to sending datagrams to any target, whether it be into a fi...
Definition: datagramSink.h:32
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
virtual bool copy_datagram(SubfileInfo &result, const Filename &filename)
Copies the file data from the entire indicated file (via the vfs) as the next datagram.
virtual const Filename & get_filename()
Returns the filename that provides the target for these datagrams, if any, or empty string if the dat...
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...
This class can be used to write a binary file that consists of an arbitrary header followed by a numb...
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:29
virtual const FileReference * get_file()
Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagr...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43