Panda3D
datagramOutputFile.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 datagramOutputFile.h
10  * @author drose
11  * @date 2000-10-30
12  */
13 
14 #ifndef DATAGRAMOUTPUTFILE_H
15 #define DATAGRAMOUTPUTFILE_H
16 
17 #include "pandabase.h"
18 
19 #include "datagramSink.h"
20 #include "filename.h"
21 #include "fileReference.h"
22 #include "virtualFile.h"
23 #include "virtualFileSystem.h"
24 #include "config_putil.h"
25 
26 /**
27  * This class can be used to write a binary file that consists of an arbitrary
28  * header followed by a number of datagrams.
29  */
30 class EXPCL_PANDA_PUTIL DatagramOutputFile : public DatagramSink {
31 PUBLISHED:
32  INLINE DatagramOutputFile();
33  INLINE ~DatagramOutputFile();
34 
35  bool open(const FileReference *file);
36  INLINE bool open(const Filename &filename);
37  bool open(std::ostream &out, const Filename &filename = Filename());
38 
39  void close();
40 
41  bool write_header(const std::string &header);
42  virtual bool put_datagram(const Datagram &data);
43  virtual bool copy_datagram(SubfileInfo &result, const Filename &filename);
44  virtual bool copy_datagram(SubfileInfo &result, const SubfileInfo &source);
45  virtual bool is_error();
46  virtual void flush();
47 
48 public:
49  virtual const Filename &get_filename();
50  virtual const FileReference *get_file();
51  virtual std::streampos get_file_pos();
52 
53  INLINE std::ostream &get_stream();
54 
55 PUBLISHED:
56  MAKE_PROPERTY(stream, get_stream);
57 
58 private:
59  bool _wrote_first_datagram;
60  bool _error;
61  CPT(FileReference) _file;
62  PT(VirtualFile) _vfile;
63  std::ostream *_out;
64  bool _owns_out;
65  Filename _filename;
66 };
67 
68 #include "datagramOutputFile.I"
69 
70 #endif
Keeps a reference-counted pointer to a file on disk.
Definition: fileReference.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class defines the abstract interface to sending datagrams to any target, whether it be into a fi...
Definition: datagramSink.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
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.
This class can be used to write a binary file that consists of an arbitrary header followed by a numb...
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.