Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoOutput.h
1 #ifndef COIN_SOOUTPUT_H
2 #define COIN_SOOUTPUT_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) by Kongsberg Oil & Gas Technologies.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Kongsberg Oil & Gas Technologies
18  * about acquiring a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <Inventor/system/inttypes.h>
28 #include <Inventor/SbBasic.h>
29 #include <Inventor/SbString.h>
30 #include <stdio.h>
31 
32 class SbDict;
33 class SbName;
34 class SoBase;
35 class SoOutputP;
36 class SoProto;
37 class SoField;
38 class SoFieldContainer;
39 
40 typedef void * SoOutputReallocCB(void * ptr, size_t newSize);
41 
42 class COIN_DLL_API SoOutput {
43 public:
44  enum Stage { COUNT_REFS, WRITE };
45  // Bitwise flags for the annotations.
46  enum Annotations { ADDRESSES = 0x01, REF_COUNTS = 0x02 };
47 
48  SoOutput(void);
49  SoOutput(SoOutput * dictOut);
50  virtual ~SoOutput();
51 
52  virtual void setFilePointer(FILE * newFP);
53  virtual FILE * getFilePointer(void) const;
54  virtual SbBool openFile(const char * const fileName);
55  virtual void closeFile(void);
56 
57  SbBool setCompression(const SbName & compmethod,
58  const float level = 0.5f);
59  static const SbName * getAvailableCompressionMethods(unsigned int & num);
60 
61  virtual void setBuffer(void * bufPointer, size_t initSize,
62  SoOutputReallocCB * reallocFunc, int32_t offset = 0);
63  virtual SbBool getBuffer(void * & bufPointer, size_t & nBytes) const;
64  virtual size_t getBufferSize(void) const;
65  virtual void resetBuffer(void);
66  virtual void setBinary(const SbBool flag);
67  virtual SbBool isBinary(void) const;
68  virtual void setHeaderString(const SbString & str);
69  virtual void resetHeaderString(void);
70  virtual void setFloatPrecision(const int precision);
71 
72  void setStage(Stage stage);
73  Stage getStage(void) const;
74 
75  void incrementIndent(const int levels = 1);
76  void decrementIndent(const int levels = 1);
77 
78  virtual void write(const char c);
79  virtual void write(const char * s);
80  virtual void write(const SbString & s);
81  virtual void write(const SbName & n);
82  virtual void write(const int i);
83  virtual void write(const unsigned int i);
84  virtual void write(const short s);
85  virtual void write(const unsigned short s);
86  virtual void write(const float f);
87  virtual void write(const double d);
88  virtual void writeBinaryArray(const unsigned char * c, const int length);
89  virtual void writeBinaryArray(const int32_t * const l, const int length);
90  virtual void writeBinaryArray(const float * const f, const int length);
91  virtual void writeBinaryArray(const double * const d, const int length);
92 
93  virtual void indent(void);
94  virtual void reset(void);
95  void setCompact(SbBool flag);
96  SbBool isCompact(void) const;
97  void setAnnotation(uint32_t bits);
98  uint32_t getAnnotation(void);
99 
100  static SbString getDefaultASCIIHeader(void);
101  static SbString getDefaultBinaryHeader(void);
102 
103  int addReference(const SoBase * base);
104  int findReference(const SoBase * base) const;
105  void setReference(const SoBase * base, int refid);
106 
107  void addDEFNode(SbName name);
108  SbBool lookupDEFNode(SbName name);
109  void removeDEFNode(SbName name);
110 
111  void pushProto(SoProto * proto);
112  SoProto * getCurrentProto(void) const;
113  void popProto(void);
114 
115  void addRoute(SoFieldContainer * from, const SbName & fromfield,
116  SoFieldContainer * to, const SbName & tofield);
117  void resolveRoutes(void);
118 
119 protected:
120  SbBool isToBuffer(void) const;
121  size_t bytesInBuf(void) const;
122  SbBool makeRoomInBuf(size_t nBytes);
123  void convertShort(short s, char * to);
124  void convertInt32(int32_t l, char * to);
125  void convertFloat(float f, char * to);
126  void convertDouble(double d, char * to);
127  void convertShortArray(short * from, char * to, int len);
128  void convertInt32Array(int32_t * from, char * to, int len);
129  void convertFloatArray(float * from, char * to, int len);
130  void convertDoubleArray(double * from, char * to, int len);
131 
132  static SbString padHeader(const SbString & inString);
133 
134  SbBool wroteHeader;
135 
136 private:
137  SoOutputP * pimpl;
138 
139  void constructorCommon(void);
140 
141  void checkHeader(void);
142  void writeBytesWithPadding(const char * const p, const size_t nr);
143 
144  friend class SoBase; // Need to be able to remove items from dict.
145  friend class SoWriterefCounter; // ditto
146  void removeSoBase2IdRef(const SoBase * base);
147 };
148 
149 #endif // !COIN_SOOUTPUT_H
The SoBase class is the top-level superclass for a number of class-hierarchies.SoBase provides the ba...
Definition: SoBase.h:36
The SoOutput class is an abstraction of an output stream.SoOutput offers the ability to write basic t...
Definition: SoOutput.h:42
Annotations
Definition: SoOutput.h:46
The SoFieldContainer class is a base class for all classes that contain fields.The classes containing...
Definition: SoFieldContainer.h:34
The SoField class is the top-level abstract base class for fields.Fields is the mechanism used throug...
Definition: SoField.h:38
The SbDict class organizes a dictionary of keys and values.It uses hashing to quickly insert and find...
Definition: SbDict.h:54
SbBool wroteHeader
Definition: SoOutput.h:134
The SoProto class handles PROTO definitions.
Definition: SoProto.h:41
Stage
Definition: SoOutput.h:44
The SbString class is a string class with convenience functions for string operations.This is the class used for storing and working with character strings. It automatically takes care of supporting all the "bookkeeping" tasks usually associated with working with character strings, like memory allocation and deallocation etc.
Definition: SbString.h:42
The SbName class stores strings by reference.The class is used by Coin for storing keywords...
Definition: SbName.h:31

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Wed Feb 7 2018 for Coin by Doxygen 1.8.14.