Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoOutput.h
1#ifndef COIN_SOOUTPUT_H
2#define COIN_SOOUTPUT_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/system/inttypes.h>
37#include <Inventor/SbBasic.h>
38#include <Inventor/SbString.h>
39#include <cstdio>
40
41class SbDict;
42class SbName;
43class SoBase;
44class SoOutputP;
45class SoProto;
46class SoField;
48
49typedef void * SoOutputReallocCB(void * ptr, size_t newSize);
50
52public:
53 enum Stage { COUNT_REFS, WRITE };
54 // Bitwise flags for the annotations.
55 enum Annotations { ADDRESSES = 0x01, REF_COUNTS = 0x02 };
56
57 SoOutput(void);
59 virtual ~SoOutput();
60
61 virtual void setFilePointer(FILE * newFP);
62 virtual FILE * getFilePointer(void) const;
63 virtual SbBool openFile(const char * const fileName);
64 virtual void closeFile(void);
65
66 SbBool setCompression(const SbName & compmethod,
67 const float level = 0.5f);
68 static const SbName * getAvailableCompressionMethods(unsigned int & num);
69
70 virtual void setBuffer(void * bufPointer, size_t initSize,
71 SoOutputReallocCB * reallocFunc, int32_t offset = 0);
72 virtual SbBool getBuffer(void * & bufPointer, size_t & nBytes) const;
73 virtual size_t getBufferSize(void) const;
74 virtual void resetBuffer(void);
75 virtual void setBinary(const SbBool flag);
76 virtual SbBool isBinary(void) const;
77 virtual void setHeaderString(const SbString & str);
78 virtual void resetHeaderString(void);
79 virtual void setFloatPrecision(const int precision);
80
81 void setStage(Stage stage);
82 Stage getStage(void) const;
83
84 void incrementIndent(const int levels = 1);
85 void decrementIndent(const int levels = 1);
86
87 virtual void write(const char c);
88 virtual void write(const char * s);
89 virtual void write(const SbString & s);
90 virtual void write(const SbName & n);
91 virtual void write(const int i);
92 virtual void write(const unsigned int i);
93 virtual void write(const short s);
94 virtual void write(const unsigned short s);
95 virtual void write(const float f);
96 virtual void write(const double d);
97#ifdef __CYGWIN__
98 //These function are not virtual as they are meant to be only wrappers to the real function calls, due to limitations in Cygwin g++ type demangling.
99 void write(long int i);
100 void write(long unsigned int i);
101#endif //__CYGWIN__
102 virtual void writeBinaryArray(const unsigned char * c, const int length);
103 virtual void writeBinaryArray(const int32_t * const l, const int length);
104 virtual void writeBinaryArray(const float * const f, const int length);
105 virtual void writeBinaryArray(const double * const d, const int length);
106
107 virtual void indent(void);
108 virtual void reset(void);
109 void setCompact(SbBool flag);
110 SbBool isCompact(void) const;
111 void setAnnotation(uint32_t bits);
112 uint32_t getAnnotation(void);
113
114 static SbString getDefaultASCIIHeader(void);
115 static SbString getDefaultBinaryHeader(void);
116
117 int addReference(const SoBase * base);
118 int findReference(const SoBase * base) const;
119 void setReference(const SoBase * base, int refid);
120
121 void addDEFNode(SbName name);
122 SbBool lookupDEFNode(SbName name);
123 void removeDEFNode(SbName name);
124
125 void pushProto(SoProto * proto);
126 SoProto * getCurrentProto(void) const;
127 void popProto(void);
128
129 void addRoute(SoFieldContainer * from, const SbName & fromfield,
130 SoFieldContainer * to, const SbName & tofield);
131 void resolveRoutes(void);
132
133protected:
134 SbBool isToBuffer(void) const;
135 size_t bytesInBuf(void) const;
136 SbBool makeRoomInBuf(size_t nBytes);
137 void convertShort(short s, char * to);
138 void convertInt32(int32_t l, char * to);
139 void convertFloat(float f, char * to);
140 void convertDouble(double d, char * to);
141 void convertShortArray(short * from, char * to, int len);
142 void convertInt32Array(int32_t * from, char * to, int len);
143 void convertFloatArray(float * from, char * to, int len);
144 void convertDoubleArray(double * from, char * to, int len);
145
146 static SbString padHeader(const SbString & inString);
147
149
150private:
151 SoOutputP * pimpl;
152
153 void constructorCommon(void);
154
155 void checkHeader(void);
156 void writeBytesWithPadding(const char * const p, const size_t nr);
157
158 friend class SoBase; // Need to be able to remove items from dict.
159 friend class SoWriterefCounter; // ditto
160 void removeSoBase2IdRef(const SoBase * base);
161};
162
163#endif // !COIN_SOOUTPUT_H
The SbDict class organizes a dictionary of keys and values.
Definition SbDict.h:63
The SbList class is a template container class for lists.
Definition SbList.h:70
The SbName class stores strings by reference.
Definition SbName.h:40
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition SoBase.h:45
The SoFieldContainer class is a base class for all classes that contain fields.
Definition SoFieldContainer.h:43
The SoField class is the top-level abstract base class for fields.
Definition SoField.h:47
The SoOutput class is an abstraction of an output stream.
Definition SoOutput.h:51
SbBool wroteHeader
Definition SoOutput.h:148
Annotations
Definition SoOutput.h:55
Stage
Definition SoOutput.h:53
@ COUNT_REFS
Definition SoOutput.h:53
The SoProto class handles PROTO definitions.
Definition SoProto.h:50