Coin
4.0.3
Coin3D core library
|
The SoOutput class is an abstraction of an output stream. More...
#include <Inventor/SoOutput.h>
Public Types | |
enum | Annotations { ADDRESSES = 0x01 , REF_COUNTS = 0x02 } |
enum | Stage { COUNT_REFS , WRITE } |
Static Public Member Functions | |
static const SbName * | getAvailableCompressionMethods (unsigned int &num) |
static SbString | getDefaultASCIIHeader (void) |
static SbString | getDefaultBinaryHeader (void) |
Protected Member Functions | |
size_t | bytesInBuf (void) const |
void | convertDouble (double d, char *to) |
void | convertDoubleArray (double *from, char *to, int len) |
void | convertFloat (float f, char *to) |
void | convertFloatArray (float *from, char *to, int len) |
void | convertInt32 (int32_t l, char *to) |
void | convertInt32Array (int32_t *from, char *to, int len) |
void | convertShort (short s, char *to) |
void | convertShortArray (short *from, char *to, int len) |
SbBool | isToBuffer (void) const |
SbBool | makeRoomInBuf (size_t nBytes) |
Static Protected Member Functions | |
static SbString | padHeader (const SbString &inString) |
Protected Attributes | |
SbBool | wroteHeader |
The SoOutput class is an abstraction of an output stream.
SoOutput offers the ability to write basic types to a file or a memory buffer in either ASCII or binary format.
Enumerates the possible stages of a write operation (writing needs to be done in multiple passes).
Enumerator | |
---|---|
COUNT_REFS | Not writing, just counting the internal references in the scene graph. |
WRITE | Signifies that actual data export should take place during this pass. |
SoOutput::SoOutput | ( | void | ) |
The default constructor makes an SoOutput instance which will write to the standard output.
SoOutput::SoOutput | ( | SoOutput * | dictOut | ) |
Constructs an SoOutput which has a copy of the set of named references from dictOut.
|
virtual |
Destructor.
Adds name to the set of currently DEF'ed node names so far in the output process.
Makes a unique id for base and adds a mapping into our dictionary.
void SoOutput::addRoute | ( | SoFieldContainer * | from, |
const SbName & | fromfield, | ||
SoFieldContainer * | to, | ||
const SbName & | tofield ) |
|
protected |
Returns current write position.
Note that for memory buffer writing, this includes the offset from SoOutput::setBuffer(), if any.
Closes the currently opened file, but only if the file was passed to SoOutput through the openFile() method.
|
protected |
Convert the double-precision floating point number in d to most-significant-byte first format and put the resulting bytes sequentially at to.
|
protected |
Convert len double-precision floating point values from the array at from into the array at to from native host format to network independent format (i.e. most significant byte first).
|
protected |
Convert the single-precision floating point number in f to most-significant-byte first format and put the resulting bytes sequentially at to.
|
protected |
Convert len single-precision floating point values from the array at from into the array at to from native host format to network independent format (i.e. most significant byte first).
|
protected |
Convert the 32-bit integer in l to most-significant-byte first format and put the resulting bytes sequentially at to.
|
protected |
Convert len 32-bit integer values from the array at from into the array at to from native host format to network independent format (i.e. most significant byte first).
|
protected |
Convert the short integer in s to most-significant-byte first format and put the resulting bytes sequentially at to.
|
protected |
Convert len short integer values from the array at from into the array at to from native host format to network independent format (i.e. most significant byte first).
Decrease indentation level in the file.
Returns the unique identifier for base or -1 if not found.
uint32_t SoOutput::getAnnotation | ( | void | ) |
Returns the current annotation debug bitflag settings.
Returns the array of available compression methods. The number of elements in the array will be stored in num.
|
virtual |
Returns the current buffer in bufPointer and the current write position of the buffer in nBytes. If we're writing into a file and not a memory buffer, FALSE is returned and the other return values will be undefined.
|
virtual |
Returns total size of memory buffer.
Return the default header string written to ASCII files.
Return the default header string written to binary files.
Returns the current file pointer. If we're writing to a memory buffer, NULL
is returned.
Important note: do not use this method when the Coin library has been compiled as a Microsoft Windows DLL, as passing FILE* instances back or forth to DLLs is dangerous and will most likely cause a crash. This is an intrinsic limitation for Microsoft Windows DLLs.
SoOutput::Stage SoOutput::getStage | ( | void | ) | const |
Returns an indicator on the current write stage. Writing is done in two passes, one to count and check connections, one to do the actual ASCII or binary export of data.
You should not need to use this method, as it is meant for internal purposes in Coin.
Increase indentation level in the file.
Call this method after writing a newline to a file to indent the next line to the correct position.
|
virtual |
Returns a flag which indicates whether or not we're writing the output as a binary stream.
SbBool SoOutput::isCompact | ( | void | ) | const |
Returns whether or not the write routines try to compact the data when writing it (i.e. using less whitespace, etc).
Note that "compact" in this sense does not mean "bitwise compression", as it could easily be mistaken for.
|
protected |
Returns TRUE if we're set up to write to a memory buffer.
SbBool SoOutput::lookupDEFNode | ( | SbName | name | ) |
Checks whether name is already DEF'ed at this point in the output process. Returns TRUE if name is DEF'ed.
|
protected |
Check that the current memory buffer has enough space to contain the given number of bytes needed for the next write operation.
Returns FALSE if there's not enough space left, otherwise TRUE.
Note that there will automatically be made an attempt at allocating more memory if the reallocation callback function argument of setBuffer() was not NULL.
Opens a file for writing. If the file cannot be opened or is not writable, FALSE will be returned.
Files opened by this method will automatically be closed if the user supplies another file pointer, another filename for writing, or if the SoOutput instance is deleted.
Pads the header we're writing so it contains the correct amount of bytes for the alignment of the following binary writes.
Removes name from the set of DEF'ed node names. Used after the last reference to a DEF'ed node if we want to reuse the DEF at a later point in the file.
Reset all value and make ready for using another file pointer or buffer.
Reset the memory buffer write pointer back to the beginning of the buffer.
Reset the header string to the default one.
void SoOutput::setAnnotation | ( | uint32_t | bits | ) |
Set up annotation of different aspects of the output data. This is not useful for much else than debugging purposes, I suppose.
Set whether or not to write the output as a binary stream.
|
virtual |
Sets up a memory buffer of size initSize for writing. Writing will start at bufPointer + offset.
If the buffer is filled up, reallocFunc is called to get more memory. If reallocFunc returns NULL, further writing is disabled.
Important note: remember that the resultant memory buffer after write operations have completed may reside somewhere else in memory than on bufPointer if reallocFunc is set. It is a good idea to make it a habit to always use getBuffer() to retrieve the memory buffer pointer after write operations.
Here's a complete, standalone usage example which shows how to write a scene graph to a memory buffer:
void SoOutput::setCompact | ( | SbBool | flag | ) |
Set up the output to be more compact than with the default write routines.
Sets the compression method and level used when writing the file. compmethod is the compression library/method to use when compressing. level is the compression level, where 0.0 means no compression and 1.0 means maximum compression.
Currently BZIP2, GZIP are the only compression methods supported, and you have to compile Coin with zlib and bzip2-support to enable them.
Supply compmethod = NONE or level = 0.0 if you want to disable compression. The compression is disabled by default.
Please note that it's not possible to compress when writing to a memory buffer.
This method will return TRUE if the compression method selected is available. If it is not available, FALSE will be returned and compression is disabled.
Set up a new file pointer which we will write to.
Important note: do not use this method when the Coin library has been compiled as a Microsoft Windows DLL, as passing FILE* instances back or forth to DLLs is dangerous and will most likely cause a crash. This is an intrinsic limitation for Microsoft Windows DLLs.
Set the precision used when writing floating point numbers to ASCII files. precision should be between 0 and 8. The double precision will be set to precision * 2.
Set the output file header string.
Sets the reference for base manually.
Sets an indicator on the current stage. This is necessary to do as writing has to be done in multiple stages to account for the export of references/connections within the scene graphs.
This method is basically just used from within SoWriteAction, and should usually not be of interest to the application programmer. Do not use it unless you really know what you are doing.
Write the character string pointed to by s.
For binary write, a 4-byte MSB-ordered integer with the string length, plus the string plus padding zero characters to get on a 4-byte boundary (if necessary) will be written.
Write the character in c.
For binary write, the character plus 3 padding zero characters will be written.
Write i as a character string, or as an architecture independent binary pattern if the setBinary() flag is activated.
Write the character string in n. The name will be enclosed by apostrophes. If you want to write an SbName instance without the apostrophes, cast the argument to a char *.
If we are supposed to write in binary format, no apostrophes will be added, and writing will be done in the exact same manner as with SoOutput::write(const char * s).
Write the character string in s. The string will be written with apostrophes. Cast SbString to char * to write without apostrophes.
If we are supposed to write in binary format, no apostrophes will be added, and writing will be done in the exact same manner as with SoOutput::write(const char * s).
Write s as a character string, or as an architecture independent binary pattern if the setBinary() flag is activated.
Write i as a character string, or as an architecture independent binary pattern if the setBinary() flag is activated.
Write s as a character string, or as an architecture independent binary pattern if the setBinary() flag is activated. If we're writing in ASCII format, the value will be written in base 16 (hexadecimal).
Write an array of double values in binary format.
Write an array of float values in binary format.
Write an length array of int32_t values in binary format.
Write the given number of bytes to either a file or a memory buffer in binary format.
|
protected |
Indicates whether or not the file format header has been written out. As long as this is FALSE, the header will be written once upon the first invocation of any write method in the class.