Panda3D
withOutputFile.h
1 // Filename: withOutputFile.h
2 // Created by: drose (11Apr01)
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 WITHOUTPUTFILE_H
16 #define WITHOUTPUTFILE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "programBase.h"
21 #include "filename.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : WithOutputFile
25 // Description : This is the bare functionality (intended to be
26 // inherited from along with ProgramBase or some
27 // derivative) for a program that might generate an
28 // output file.
29 //
30 // This provides the has_output_filename() and
31 // get_output_filename() methods.
32 ////////////////////////////////////////////////////////////////////
34 public:
35  WithOutputFile(bool allow_last_param, bool allow_stdout,
36  bool binary_output);
37  virtual ~WithOutputFile();
38 
39  ostream &get_output();
40  void close_output();
41  bool has_output_filename() const;
43 
44 protected:
45  INLINE void set_binary_output(bool binary_output);
46 
47  bool check_last_arg(ProgramBase::Args &args, int minimum_args);
48  bool verify_output_file_safe() const;
49 
50 protected:
51  bool _allow_last_param;
52  bool _allow_stdout;
53  bool _binary_output;
54  string _preferred_extension;
55  bool _got_output_filename;
56  Filename _output_filename;
57 
58 private:
59  ofstream _output_stream;
60  ostream *_output_ptr;
61  bool _owns_output_ptr;
62 };
63 
64 #include "withOutputFile.I"
65 
66 #endif
67 
68 
void close_output()
Closes the output stream previously opened by get_output().
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout...