withOutputFile.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Filename: withOutputFile.h
  2. // Created by: drose (11Apr01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef WITHOUTPUTFILE_H
  19. #define WITHOUTPUTFILE_H
  20. #include "pandatoolbase.h"
  21. #include "programBase.h"
  22. #include "filename.h"
  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. ////////////////////////////////////////////////////////////////////
  33. class WithOutputFile {
  34. public:
  35. WithOutputFile(bool allow_last_param, bool allow_stdout,
  36. bool binary_output);
  37. virtual ~WithOutputFile();
  38. ostream &get_output();
  39. bool has_output_filename() const;
  40. Filename get_output_filename() const;
  41. protected:
  42. INLINE void set_binary_output(bool binary_output);
  43. bool check_last_arg(ProgramBase::Args &args, int minimum_args);
  44. bool verify_output_file_safe() const;
  45. protected:
  46. bool _allow_last_param;
  47. bool _allow_stdout;
  48. bool _binary_output;
  49. string _preferred_extension;
  50. bool _got_output_filename;
  51. Filename _output_filename;
  52. private:
  53. ofstream _output_stream;
  54. ostream *_output_ptr;
  55. };
  56. #include "withOutputFile.I"
  57. #endif