Panda3D
|
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivative) for a program that might generate an output file. More...
#include "withOutputFile.h"
Public Member Functions | |
WithOutputFile (bool allow_last_param, bool allow_stdout, bool binary_output) | |
void | close_output () |
Closes the output stream previously opened by get_output(). | |
ostream & | get_output () |
Returns an output stream that corresponds to the user's intended egg file output--either stdout, or the named output file. | |
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. | |
Protected Member Functions | |
bool | check_last_arg (ProgramBase::Args &args, int minimum_args) |
Checks if the last filename on the argument list is a file with the expected extension (if _allow_last_param was set true), and removes it from the argument list if it is. | |
void | set_binary_output (bool binary_output) |
Changes the flag specifying whether the output file is to be opened in binary mode or not. | |
bool | verify_output_file_safe () const |
This is called when the output file is given as the last parameter on the command line. | |
Protected Attributes | |
bool | _allow_last_param |
bool | _allow_stdout |
bool | _binary_output |
bool | _got_output_filename |
Filename | _output_filename |
string | _preferred_extension |
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivative) for a program that might generate an output file.
This provides the has_output_filename() and get_output_filename() methods.
Definition at line 33 of file withOutputFile.h.
bool WithOutputFile::check_last_arg | ( | ProgramBase::Args & | args, |
int | minimum_args | ||
) | [protected] |
Checks if the last filename on the argument list is a file with the expected extension (if _allow_last_param was set true), and removes it from the argument list if it is.
Returns true if the arguments are good, false if something is invalid.
minimum_args is the number of arguments we know must be input parameters and therefore cannot be interpreted as output filenames.
Definition at line 169 of file withOutputFile.cxx.
References Filename::from_os_specific(), Filename::get_extension(), and verify_output_file_safe().
Referenced by EggFilter::handle_args(), ImageFilter::handle_args(), FltTrans::handle_args(), VRMLTrans::handle_args(), XFileTrans::handle_args(), ImageWriter::handle_args(), EggTextureCards::handle_args(), EggWriter::handle_args(), and EggToSomething::handle_args().
void WithOutputFile::close_output | ( | ) |
Closes the output stream previously opened by get_output().
A subsequent call to get_output() will open a new stream.
Definition at line 117 of file withOutputFile.cxx.
ostream & WithOutputFile::get_output | ( | ) |
Returns an output stream that corresponds to the user's intended egg file output--either stdout, or the named output file.
Definition at line 58 of file withOutputFile.cxx.
References Filename::get_extension(), Filename::make_dir(), Filename::open_write(), Filename::set_binary(), and Filename::set_text().
Referenced by DXFPoints::done_entity(), and EggWriter::write_egg_file().
Filename WithOutputFile::get_output_filename | ( | ) | const |
If has_output_filename() returns true, this is the filename that the user specified.
Otherwise, it returns the empty string.
Definition at line 148 of file withOutputFile.cxx.
Referenced by ImageWriter::write_image().
bool WithOutputFile::has_output_filename | ( | ) | const |
Returns true if the user specified an output filename, false otherwise (e.g.
the output file is implicitly stdout).
Definition at line 136 of file withOutputFile.cxx.
void WithOutputFile::set_binary_output | ( | bool | binary_output | ) | [inline, protected] |
Changes the flag specifying whether the output file is to be opened in binary mode or not.
Definition at line 23 of file withOutputFile.I.
bool WithOutputFile::verify_output_file_safe | ( | ) | const [protected] |
This is called when the output file is given as the last parameter on the command line.
Since this is a fairly dangerous way to specify the output file (it's easy to accidentally overwrite an input file this way), the convention is to disallow this syntax if the output file already exists.
This function will test if the output file exists, and issue a warning message if it does, returning false. If all is well, it will return true.
Definition at line 215 of file withOutputFile.cxx.
Referenced by check_last_arg(), and SomethingToEgg::handle_args().