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

SoOutput.h

00001 #ifndef COIN_SOOUTPUT_H
00002 #define COIN_SOOUTPUT_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Systems in Motion about acquiring
00018  *  a Coin Professional Edition License.
00019  *
00020  *  See <URL:http://www.coin3d.org> for  more information.
00021  *
00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
00023  *  <URL:http://www.sim.no>.
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/system/inttypes.h>
00028 #include <Inventor/SbBasic.h>
00029 #include <Inventor/SbString.h>
00030 #include <stdio.h>
00031 
00032 class SbDict;
00033 class SbName;
00034 class SoBase;
00035 class SoOutputP;
00036 class SoProto;
00037 class SoField;
00038 class SoFieldContainer;
00039 
00040 typedef void * SoOutputReallocCB(void * ptr, size_t newSize);
00041 
00042 class COIN_DLL_API SoOutput {
00043 public:
00044   enum Stage { COUNT_REFS, WRITE };
00045   // Bitwise flags for the annotations.
00046   enum Annotations { ADDRESSES = 0x01, REF_COUNTS = 0x02 };
00047 
00048   SoOutput(void);
00049   SoOutput(SoOutput * dictOut);
00050   virtual ~SoOutput();
00051 
00052   virtual void setFilePointer(FILE * newFP);
00053   virtual FILE * getFilePointer(void) const;
00054   virtual SbBool openFile(const char * const fileName);
00055   virtual void closeFile(void);
00056 
00057   virtual void setBuffer(void * bufPointer, size_t initSize,
00058                          SoOutputReallocCB * reallocFunc, int32_t offset = 0);
00059   virtual SbBool getBuffer(void * & bufPointer, size_t & nBytes) const;
00060   virtual size_t getBufferSize(void) const;
00061   virtual void resetBuffer(void);
00062   virtual void setBinary(const SbBool flag);
00063   virtual SbBool isBinary(void) const;
00064   virtual void setHeaderString(const SbString & str);
00065   virtual void resetHeaderString(void);
00066   virtual void setFloatPrecision(const int precision);
00067 
00068   void setStage(Stage stage);
00069   Stage getStage(void) const;
00070 
00071   void incrementIndent(const int levels = 1);
00072   void decrementIndent(const int levels = 1);
00073 
00074   virtual void write(const char c);
00075   virtual void write(const char * s);
00076   virtual void write(const SbString & s);
00077   virtual void write(const SbName & n);
00078   virtual void write(const int i);
00079   virtual void write(const unsigned int i);
00080   virtual void write(const short s);
00081   virtual void write(const unsigned short s);
00082   virtual void write(const float f);
00083   virtual void write(const double d);
00084   virtual void writeBinaryArray(const unsigned char * c, const int length);
00085   virtual void writeBinaryArray(const int32_t * const l, const int length);
00086   virtual void writeBinaryArray(const float * const f, const int length);
00087   virtual void writeBinaryArray(const double * const d, const int length);
00088 
00089   virtual void indent(void);
00090   virtual void reset(void);
00091   void setCompact(SbBool flag);
00092   SbBool isCompact(void) const;
00093   void setAnnotation(uint32_t bits);
00094   uint32_t getAnnotation(void);
00095 
00096   static SbString getDefaultASCIIHeader(void);
00097   static SbString getDefaultBinaryHeader(void);
00098 
00099   int addReference(const SoBase * base);
00100   int findReference(const SoBase * base) const;
00101   void setReference(const SoBase * base, int refid);
00102 
00103   void addDEFNode(SbName name);
00104   SbBool lookupDEFNode(SbName name);
00105   void removeDEFNode(SbName name);
00106 
00107   void pushProto(SoProto * proto);
00108   SoProto * getCurrentProto(void) const;
00109   void popProto(void);
00110   
00111   void addRoute(SoFieldContainer * from, const SbName & fromfield,
00112                 SoFieldContainer * to, const SbName & tofield);
00113   void resolveRoutes(void);
00114   
00115 protected:
00116   SbBool isToBuffer(void) const;
00117   size_t bytesInBuf(void) const;
00118   SbBool makeRoomInBuf(size_t nBytes);
00119   void convertShort(short s, char * to);
00120   void convertInt32(int32_t l, char * to);
00121   void convertFloat(float f, char * to);
00122   void convertDouble(double d, char * to);
00123   void convertShortArray(short * from, char * to, int len);
00124   void convertInt32Array(int32_t * from, char * to, int len);
00125   void convertFloatArray(float * from, char * to, int len);
00126   void convertDoubleArray(double * from, char * to, int len);
00127 
00128   static SbString padHeader(const SbString & inString);
00129 
00130   SbBool wroteHeader;
00131 
00132 private:
00133   SoOutputP * pimpl;
00134 
00135   void constructorCommon(void);
00136 
00137   void checkHeader(void);
00138   void writeBytesWithPadding(const char * const p, const size_t nr);
00139   
00140   friend class SoBase; // Need to be able to remove items from dict.
00141   void removeSoBase2IdRef(const SoBase * base);
00142 };
00143 
00144 #endif // !COIN_SOOUTPUT_H

Generated on Sat May 24 22:39:15 2003 for Coin by doxygen1.2.18