Open Inventor Reference
SoOutput.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file contains the definition of the SoOutput class.
48 |
49 | Classes:
50 | SoOutput
51 |
52 | Author(s) : Paul S. Strauss, Gavin Bell
53 |
54 ______________ S I L I C O N G R A P H I C S I N C . ____________
55 _______________________________________________________________________
56 */
57
58#ifndef _SO_OUTPUT_
59#define _SO_OUTPUT_
60
62#include <Inventor/SbDict.h>
63#include <Inventor/SbString.h>
64
65class SoBase;
66
67typedef void *SoOutputReallocCB(void *ptr, size_t newSize);
68
69
72
89
91 public:
92
96
100
102 void setFilePointer(FILE *newFP);
103
105 FILE * getFilePointer() const;
106
108 bool openFile(const char *fileName);
109
112 void closeFile();
113
118 void setBuffer(void *bufPointer, size_t initSize,
119 SoOutputReallocCB *reallocFunc,
120 int32_t offset = 0);
121
124 bool getBuffer(void *&bufPointer, size_t &nBytes) const;
125
128 size_t getBufferSize() const { return bufSize; }
129
132
134 void setBinary(bool flag);
135
137 bool isBinary() const { return binary; }
138
149 void setHeaderString(const SbString &str);
150
153
158
163 void setFloatPrecision(int precision);
164
165 SoEXTENDER public:
166
168 enum Stage {
170 WRITE
171 };
172
174 void setStage(Stage stage) { curStage = stage; }
175 Stage getStage() const { return curStage; }
176
179 void incrementIndent(int amount = 1)
180 { indentLevel += amount; }
181 void decrementIndent(int amount = 1)
182 { indentLevel -= amount; }
183
185 void write(char c);
186 void write(const char *s);
187 void write(const SbString &s);
188 void write(const SbName &n);
189 void write(int i);
190 void write(unsigned int i);
191 void write(short s);
192 void write(unsigned short s);
199 void write(float f);
200 void write(double d);
201 void writeBinaryArray(unsigned char *c, int length);
202 void writeBinaryArray(int32_t *l, int length);
203 void writeBinaryArray(float *f, int length);
204 void writeBinaryArray(double *d, int length);
205
207 void indent();
208
209 SoINTERNAL public:
210
214
216 void reset();
217
220 void setCompact(bool flag) { compact = flag; }
221 bool isCompact() const { return compact; }
222
226 ADDRESSES = (1<<0),
227 REF_COUNTS = (1<<1)
228 };
230 { annotation = bits; }
232 { return (isCompact() || isBinary()) ? 0 : annotation; }
233
234 private:
235 FILE *fp;
236 bool toBuffer;
237 char *tmpBuffer;
238 void *buffer;
239 char *curBuf;
240 size_t bufSize;
241 size_t tmpBufSize;
242 SoOutputReallocCB *reallocFunc;
243 bool openedHere;
244 bool binary;
245 bool compact;
246 bool wroteHeader;
247 int indentLevel;
248 SbDict *refDict;
249 bool borrowedDict;
250 int refIdCount;
251 bool anyRef;
252 uint32_t annotation;
253 Stage curStage;
254 SbString headerString;
255 SbString fmtString;
256
258 void writeHeader();
259
262 static SbString padHeader(const SbString &inString);
263
265 bool isToBuffer() const
266 { return toBuffer; }
267
269 size_t bytesInBuf() const
270 { return (curBuf - (char *) buffer); }
271
273 bool makeRoomInBuf(size_t nBytes);
274
276 bool makeRoomInTmpBuf(size_t nBytes);
277
280 int addReference(const SoBase *base);
281
284 int findReference(const SoBase *base) const;
285
287 void convertShort(short s, char *to);
288 void convertInt32(int32_t l, char *to);
289 void convertFloat(float f, char *to);
290 void convertDouble(double d, char *to);
291 void convertShortArray( short *from, char *to, int len);
292 void convertInt32Array( int32_t *from, char *to, int len);
293 void convertFloatArray( float *from, char *to, int len);
294 void convertDoubleArray( double *from, char *to, int len);
295
296friend class SoBase;
297friend class SoDB;
298};
299
300#endif /* _SO_OUTPUT_ */
301
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
signed int int32_t
Definition SbTypeDefs.h:43
void * SoOutputReallocCB(void *ptr, size_t newSize)
Definition SoOutput.h:67
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
Character string stored in a hash table.
Definition SbString.h:264
Class for smart character strings.
Definition SbString.h:85
Base class for all nodes, paths, and engines.
Definition SoBase.h:90
Scene graph database class.
Definition SoDB.h:115
Used to write Inventor data files.
Definition SoOutput.h:90
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 n...
static SbString getDefaultASCIIHeader()
Returns the string representing the default ASCII header.
void setFilePointer(FILE *newFP)
Sets file pointer to write to.
void writeBinaryArray(int32_t *l, int length)
void writeBinaryArray(float *f, int length)
void write(double d)
SoOutput()
Constructor and destructor.
FILE * getFilePointer() const
Returns the file pointer in use, or NULL if using a buffer.
void writeBinaryArray(double *d, int length)
bool isCompact() const
Definition SoOutput.h:221
bool isBinary() const
Returns current state of binary flag.
Definition SoOutput.h:137
void write(unsigned int i)
void setBinary(bool flag)
Sets whether output should be ASCII (default) or binary.
void decrementIndent(int amount=1)
Definition SoOutput.h:181
Annotations
Bit mask for various output annotations.
Definition SoOutput.h:225
size_t getBufferSize() const
The total number of bytes allocated to a memory buffer may be larger than the number of bytes written...
Definition SoOutput.h:128
~SoOutput()
Constructor and destructor.
void write(short s)
void write(int i)
void setCompact(bool flag)
Prevents header and extra white space from being written.
Definition SoOutput.h:220
void setAnnotation(uint32_t bits)
Definition SoOutput.h:229
void write(const SbName &n)
void incrementIndent(int amount=1)
Increments/decrements indentation level by amount (default 1).
Definition SoOutput.h:179
static SbString getDefaultBinaryHeader()
Returns the string representing the default binary header.
void write(unsigned short s)
bool getBuffer(void *&bufPointer, size_t &nBytes) const
Returns pointer to memory buffer being written to and the new size of the buffer.
void resetHeaderString()
Resets the header for output files to be the default header.
void writeBinaryArray(unsigned char *c, int length)
Stage getStage() const
Definition SoOutput.h:175
void closeFile()
Closes current file if opened with openFile().
SoOutput(SoOutput *dictOut)
Constructor and destructor.
void write(float f)
was ... C-api: name=writeInt32 but typedef makes this redundant void write(int32_t l); was ....
void write(char c)
Writes item of particular type to current file pointer/buffer.
void write(const char *s)
void reset()
Resets things for writing to a new file or changing files.
void setStage(Stage stage)
Sets/returns current stage of operation of action.
Definition SoOutput.h:174
bool openFile(const char *fileName)
Opens named file, sets file pointer to result. This returns FALSE on error.
void setHeaderString(const SbString &str)
Sets the header for output files.
void resetBuffer()
Resets buffer for output again. Output starts over at beginning of buffer.
uint32_t getAnnotation()
Definition SoOutput.h:231
void indent()
Writes indentation to file/buffer based on current indentation level.
void write(const SbString &s)
Stage
Enum that determines stage of operation of writing.
Definition SoOutput.h:168
@ COUNT_REFS
Count write references.
Definition SoOutput.h:169
void setFloatPrecision(int precision)
Sets the precision for writing floating point numbers, i.e.