Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SoOutput.h

00001 /**************************************************************************\
00002  *
00003  *  This file is part of the Coin 3D visualization library.
00004  *  Copyright (C) 1998-2002 by Systems in Motion. All rights reserved.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public License
00008  *  version 2.1 as published by the Free Software Foundation. See the
00009  *  file LICENSE.LGPL at the root directory of the distribution for
00010  *  more details.
00011  *
00012  *  If you want to use Coin for applications not compatible with the
00013  *  LGPL, please contact SIM to acquire a Professional Edition license.
00014  *
00015  *  Systems in Motion, Prof Brochs gate 6, 7030 Trondheim, NORWAY
00016  *  http://www.sim.no support@sim.no Voice: +47 22114160 Fax: +47 22207097
00017  *
00018 \**************************************************************************/
00019 
00020 #ifndef COIN_SOOUTPUT_H
00021 #define COIN_SOOUTPUT_H
00022 
00023 #include <Inventor/system/inttypes.h>
00024 #include <Inventor/SbBasic.h>
00025 #include <Inventor/SbString.h>
00026 #include <stdio.h>
00027 
00028 class SbDict;
00029 class SbName;
00030 class SoBase;
00031 
00032 typedef void * SoOutputReallocCB(void * ptr, size_t newSize);
00033 
00034 class COIN_DLL_API SoOutput {
00035 public:
00036   enum Stage { COUNT_REFS, WRITE };
00037   // Bitwise flags for the annotations.
00038   enum Annotations { ADDRESSES = 0x01, REF_COUNTS = 0x02 };
00039 
00040   SoOutput(void);
00041   SoOutput(SoOutput * dictOut);
00042   virtual ~SoOutput();
00043 
00044   virtual void setFilePointer(FILE * newFP);
00045   virtual FILE * getFilePointer(void) const;
00046   virtual SbBool openFile(const char * const fileName);
00047   virtual void closeFile(void);
00048 
00049   virtual void setBuffer(void * bufPointer, size_t initSize,
00050                          SoOutputReallocCB * reallocFunc, int32_t offset = 0);
00051   virtual SbBool getBuffer(void * & bufPointer, size_t & nBytes) const;
00052   virtual size_t getBufferSize(void) const;
00053   virtual void resetBuffer(void);
00054   virtual void setBinary(const SbBool flag);
00055   virtual SbBool isBinary(void) const;
00056   virtual void setHeaderString(const SbString & str);
00057   virtual void resetHeaderString(void);
00058   virtual void setFloatPrecision(const int precision);
00059 
00060   void setStage(Stage stage);
00061   Stage getStage(void) const;
00062 
00063   void incrementIndent(const int levels = 1);
00064   void decrementIndent(const int levels = 1);
00065 
00066   virtual void write(const char c);
00067   virtual void write(const char * s);
00068   virtual void write(const SbString & s);
00069   virtual void write(const SbName & n);
00070   virtual void write(const int i);
00071   virtual void write(const unsigned int i);
00072   virtual void write(const short s);
00073   virtual void write(const unsigned short s);
00074   virtual void write(const float f);
00075   virtual void write(const double d);
00076   virtual void writeBinaryArray(const unsigned char * c, const int length);
00077   virtual void writeBinaryArray(const int32_t * const l, const int length);
00078   virtual void writeBinaryArray(const float * const f, const int length);
00079   virtual void writeBinaryArray(const double * const d, const int length);
00080 
00081   virtual void indent(void);
00082   virtual void reset(void);
00083   void setCompact(SbBool flag);
00084   SbBool isCompact(void) const;
00085   void setAnnotation(uint32_t bits);
00086   uint32_t getAnnotation(void);
00087 
00088   static SbString getDefaultASCIIHeader(void);
00089   static SbString getDefaultBinaryHeader(void);
00090 
00091   int addReference(const SoBase * base);
00092   int findReference(const SoBase * base) const;
00093 
00094 protected:
00095   SbBool isToBuffer(void) const;
00096   size_t bytesInBuf(void) const;
00097   SbBool makeRoomInBuf(size_t nBytes);
00098   void convertShort(short s, char * to);
00099   void convertInt32(int32_t l, char * to);
00100   void convertFloat(float f, char * to);
00101   void convertDouble(double d, char * to);
00102   void convertShortArray(short * from, char * to, int len);
00103   void convertInt32Array(int32_t * from, char * to, int len);
00104   void convertFloatArray(float * from, char * to, int len);
00105   void convertDoubleArray(double * from, char * to, int len);
00106 
00107   static SbString padHeader(const SbString & inString);
00108 
00109   SbBool wroteHeader;
00110 
00111 private:
00112   int precision;
00113   int indentlevel;
00114   SbBool usersetfp, binarystream, writecompact;
00115   SbBool disabledwriting, memorybuffer;
00116   FILE * filep;
00117   SbString * headerstring;
00118   void * buffer;
00119   size_t buffersize;
00120   SoOutputReallocCB * reallocfunc;
00121   int32_t bufferoffset;
00122   Stage stage;
00123   SbDict * sobase2id;
00124   int nextreferenceid;
00125   uint32_t annotationbits;
00126 
00127   void constructorCommon(void);
00128 
00129   void checkHeader(void);
00130   void writeBytesWithPadding(const char * const p, const size_t nr);
00131 
00132   friend class SoBase; // Need to be able to remove items from dict.
00133 };
00134 
00135 #endif // !COIN_SOOUTPUT_H

Generated at Tue Mar 5 03:31:15 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001