Used to write Open Inventor data files. More...
#include <Inventor/SoOutput.h>
Public Types | |
enum | FileProperty { DefaultProperty = 0 , CompressedZlib = 1 } |
This enum defines the properties used when data are written to a file. More... | |
Public Member Functions | |
SoOutput () | |
Constructor. | |
virtual | ~SoOutput () |
Destructor. | |
virtual void | setFileProperty (const FileProperty properties) |
Sets a combination of properties for the current file. | |
FileProperty | getFileProperty () const |
Returns the current properties used by SoOutput. | |
virtual void | setFilePointer (FILE *newFP) |
Sets file pointer to write to. | |
virtual FILE * | getFilePointer () const |
Returns the file pointer in use, or NULL if using a buffer. | |
size_t | fileWrite (void *buffer, size_t elemSize, size_t count) |
Write a buffer to the currently open file. | |
int | filePuts (const char *) |
Write a string to the currently open file. | |
int | filePutc (int) |
Write a byte to the currently open file. | |
virtual SoNONUNICODE SbBool | openFile (const char *fileName) |
Opens named file, sets current file to result. | |
virtual SbBool | openFile (const SbString &fileName) |
Opens named file, sets current file to result. | |
virtual void | closeFile () |
Closes current file if opened with openFile(). | |
virtual void | setBuffer (void *bufPointer, size_t initSize, SoOutputReallocCB *reallocFunc, int32_t offset=0) |
Sets up memory buffer to write to, initial size, reallocation function (which is called if there is not enough room in the buffer), and offset in the buffer at which to begin writing. | |
virtual SbBool | getBuffer (void *&bufPointer, size_t &nBytes) const |
Returns memory buffer being written to and the new size of the buffer. | |
virtual size_t | getBufferSize () const |
The total number of bytes allocated to a memory buffer may be larger than the number of bytes written. | |
virtual void | resetBuffer () |
Resets buffer for output again. | |
virtual void | setBinary (SbBool flag) |
Sets whether output should be ASCII (default) or binary. | |
virtual SbBool | isBinary () const |
Returns current state of binary flag. | |
SbBool | isWritingForScaleViz () const |
Returns TRUE if ScaleViz is currently writing data for synchronization. | |
virtual void | setHeaderString (const SbString &str) |
Sets the header for output files. | |
virtual void | resetHeaderString () |
Resets the header for output files to be the default header. | |
virtual void | setFloatPrecision (int precision) |
Sets the precision for writing floating point numbers (type float), i.e. the number of significant digits. | |
virtual void | setDoublePrecision (int precision) |
Sets the precision for writing floating point numbers (type double), i.e. the number of significant digits. | |
Static Public Member Functions | |
static SbString | getDefaultASCIIHeader () |
Returns the string representing the default ASCII header. | |
static SbString | getDefaultBinaryHeader () |
Returns the string representing the default binary header. | |
Friends | |
class | SoBase |
class | SoDB |
Used to write Open Inventor data files.
This class is used for writing Open Inventor data files. It supports both ASCII (default) and binary formats and provides some convenience functions for opening and closing files. See SbFileHelper for more convenience functions. It can write to a buffer in memory as well as to a file. Since Open Inventor 8.1, SoOutput can write compressed data in the lossless Zlib (aka gzip) format. Both ASCII and binary format files may be compressed.
An instance of SoOutput is automatically created by SoWriteAction and can be queried using the getOutput() method in that class. This is typically the only instance needed. For example:
Note that file properties (binary, compression, header string, etc) should be set before calling openFile() or setFilePointer().
File extensions
The recommended file extension for Open Inventor format files, both ASCII and binary is ".iv". Open Inventor will automatically detect if the file is ASCII or binary based on the file header string. Compressed Open Inventor files may be given the extension ".ivz" for convenience, but it is not required. Open Inventor automatically detects compressed files.
File Header
Open Inventor writes a human readable file header as the first line of both ASCII and binary format files. Since Open Inventor 8.0, the default file header looks like this:
ASCII : "#Inventor V8.0 ascii"
Binary: "#Inventor V8.0 binary LE"
The two character code at the end of the binary header indicates if the file was written on a little-endian (LE) or big-endian (BE) machine. The version number string may change again in the future if incompatible changes are made to the file format. You can always query the current default headers using static methods getDefaultASCIIHeader() and getDefaultBinaryHeader().
All versions of Open Inventor from version 2.1 through version 7.x, wrote the version number string "V2.1" by default and did not append "LE" (or "BE") to the binary header. Open Inventor cannot, in general, load files containing a file header from a newer version. However all versions of Open Inventor can load files written by older versions and can load files containing the V2.1 file header. We recommend always using the default file header because newer versions enable performance enhancing features in the file format. If you need to write a file compatible with older versions, call setHeaderString() with "#Inventor V2.1 ascii" or "#Inventor V2.1 binary".
SoInput, SoWriteAction, SoTranSender, SbFileHelper
Definition at line 185 of file SoOutput.h.
This enum defines the properties used when data are written to a file.
The function setFileProperty uses this enum.
Enumerator | |
---|---|
DefaultProperty | Regular ascii or binary output. This is the default property value. |
CompressedZlib | Compressed ascii or binary output using the zlib module. |
Definition at line 204 of file SoOutput.h.
SoOutput::SoOutput | ( | ) |
Constructor.
The default SoOutput writes to stdout.
|
virtual |
Destructor.
The destructor closes any files opened by the SoOutput.
|
virtual |
Closes current file if opened with openFile().
int SoOutput::filePutc | ( | int | ) |
Write a byte to the currently open file.
If the file is compressed the byte is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns the byte value specified if successful.
int SoOutput::filePuts | ( | const char * | ) |
Write a string to the currently open file.
If the file is compressed the string is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns a non-negative value if successful (same as fputs).
size_t SoOutput::fileWrite | ( | void * | buffer, |
size_t | elemSize, | ||
size_t | count | ||
) |
Write a buffer to the currently open file.
If the file is compressed the buffer is compressed on the fly. Returns -1 if no file is currently open, else returns total number of elements successfully written (same as fwrite).
|
virtual |
Returns memory buffer being written to and the new size of the buffer.
Returns FALSE if not writing into a buffer.
|
inlinevirtual |
The total number of bytes allocated to a memory buffer may be larger than the number of bytes written.
This returns that total number.
Definition at line 312 of file SoOutput.h.
|
static |
Returns the string representing the default ASCII header.
|
static |
Returns the string representing the default binary header.
|
virtual |
Returns the file pointer in use, or NULL if using a buffer.
Using this function can be dangerous, for example when the output is compressed! In such case the compressed file can be corrupt!
FileProperty SoOutput::getFileProperty | ( | ) | const |
Returns the current properties used by SoOutput.
|
inlinevirtual |
Returns current state of binary flag.
Definition at line 327 of file SoOutput.h.
SbBool SoOutput::isWritingForScaleViz | ( | ) | const |
Returns TRUE if ScaleViz is currently writing data for synchronization.
|
virtual |
Opens named file, sets current file to result.
This returns FALSE on error.
Non Unicode: This function should not be used in a Unicode application.
Opens named file, sets current file to result.
This returns FALSE on error. If the file extension is .ivz the file is compressed so the compression module is initialized during the call to openFile.
|
virtual |
Resets buffer for output again.
Output starts over at beginning of buffer.
|
virtual |
Resets the header for output files to be the default header.
|
virtual |
Sets whether output should be ASCII (default) or binary.
|
virtual |
Sets up memory buffer to write to, initial size, reallocation function (which is called if there is not enough room in the buffer), and offset in the buffer at which to begin writing.
If the reallocation function returns NULL, writing will be disabled.
|
virtual |
Sets the precision for writing floating point numbers (type double), i.e. the number of significant digits.
Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.
|
virtual |
Sets file pointer to write to.
|
virtual |
Sets a combination of properties for the current file.
The function must be called before the output of any data. It can be called before the openFile or setFilePointer functions.
The default property is DefaultProperty when the SoOutput object is created.
|
virtual |
Sets the precision for writing floating point numbers (type float), i.e. the number of significant digits.
Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.
|
virtual |
Sets the header for output files.
This is useful, for example, if you have a file format that is a superset of the Open Inventor file format and you want Open Inventor to read the files. It is highly recommend that in your new header you simply append to the header of the Open Inventor file format you are extending. For example, if a new file format is based on the Open Inventor 2.1 file format, register a header similar to: "#Inventor V2.1 ascii MY FILE FORMAT EXTENSION". Then all Open Inventor 2.1 applications (and later) can read the file.
|
friend |
Definition at line 597 of file SoOutput.h.
|
friend |
Definition at line 598 of file SoOutput.h.