Panda3D
|
00001 // Filename: withOutputFile.h 00002 // Created by: drose (11Apr01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef WITHOUTPUTFILE_H 00016 #define WITHOUTPUTFILE_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "programBase.h" 00021 #include "filename.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : WithOutputFile 00025 // Description : This is the bare functionality (intended to be 00026 // inherited from along with ProgramBase or some 00027 // derivative) for a program that might generate an 00028 // output file. 00029 // 00030 // This provides the has_output_filename() and 00031 // get_output_filename() methods. 00032 //////////////////////////////////////////////////////////////////// 00033 class WithOutputFile { 00034 public: 00035 WithOutputFile(bool allow_last_param, bool allow_stdout, 00036 bool binary_output); 00037 virtual ~WithOutputFile(); 00038 00039 ostream &get_output(); 00040 void close_output(); 00041 bool has_output_filename() const; 00042 Filename get_output_filename() const; 00043 00044 protected: 00045 INLINE void set_binary_output(bool binary_output); 00046 00047 bool check_last_arg(ProgramBase::Args &args, int minimum_args); 00048 bool verify_output_file_safe() const; 00049 00050 protected: 00051 bool _allow_last_param; 00052 bool _allow_stdout; 00053 bool _binary_output; 00054 string _preferred_extension; 00055 bool _got_output_filename; 00056 Filename _output_filename; 00057 00058 private: 00059 ofstream _output_stream; 00060 ostream *_output_ptr; 00061 bool _owns_output_ptr; 00062 }; 00063 00064 #include "withOutputFile.I" 00065 00066 #endif 00067 00068