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

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-2007 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 http://www.coin3d.org/ for more information.
00021  *
00022  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
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   SbBool setCompression(const SbName & compmethod,
00058                         const float level = 0.5f);
00059   static const SbName * getAvailableCompressionMethods(unsigned int & num);
00060 
00061   virtual void setBuffer(void * bufPointer, size_t initSize,
00062                          SoOutputReallocCB * reallocFunc, int32_t offset = 0);
00063   virtual SbBool getBuffer(void * & bufPointer, size_t & nBytes) const;
00064   virtual size_t getBufferSize(void) const;
00065   virtual void resetBuffer(void);
00066   virtual void setBinary(const SbBool flag);
00067   virtual SbBool isBinary(void) const;
00068   virtual void setHeaderString(const SbString & str);
00069   virtual void resetHeaderString(void);
00070   virtual void setFloatPrecision(const int precision);
00071 
00072   void setStage(Stage stage);
00073   Stage getStage(void) const;
00074 
00075   void incrementIndent(const int levels = 1);
00076   void decrementIndent(const int levels = 1);
00077 
00078   virtual void write(const char c);
00079   virtual void write(const char * s);
00080   virtual void write(const SbString & s);
00081   virtual void write(const SbName & n);
00082   virtual void write(const int i);
00083   virtual void write(const unsigned int i);
00084   virtual void write(const short s);
00085   virtual void write(const unsigned short s);
00086   virtual void write(const float f);
00087   virtual void write(const double d);
00088   virtual void writeBinaryArray(const unsigned char * c, const int length);
00089   virtual void writeBinaryArray(const int32_t * const l, const int length);
00090   virtual void writeBinaryArray(const float * const f, const int length);
00091   virtual void writeBinaryArray(const double * const d, const int length);
00092 
00093   virtual void indent(void);
00094   virtual void reset(void);
00095   void setCompact(SbBool flag);
00096   SbBool isCompact(void) const;
00097   void setAnnotation(uint32_t bits);
00098   uint32_t getAnnotation(void);
00099 
00100   static SbString getDefaultASCIIHeader(void);
00101   static SbString getDefaultBinaryHeader(void);
00102 
00103   int addReference(const SoBase * base);
00104   int findReference(const SoBase * base) const;
00105   void setReference(const SoBase * base, int refid);
00106 
00107   void addDEFNode(SbName name);
00108   SbBool lookupDEFNode(SbName name);
00109   void removeDEFNode(SbName name);
00110 
00111   void pushProto(SoProto * proto);
00112   SoProto * getCurrentProto(void) const;
00113   void popProto(void);
00114   
00115   void addRoute(SoFieldContainer * from, const SbName & fromfield,
00116                 SoFieldContainer * to, const SbName & tofield);
00117   void resolveRoutes(void);
00118   
00119 protected:
00120   SbBool isToBuffer(void) const;
00121   size_t bytesInBuf(void) const;
00122   SbBool makeRoomInBuf(size_t nBytes);
00123   void convertShort(short s, char * to);
00124   void convertInt32(int32_t l, char * to);
00125   void convertFloat(float f, char * to);
00126   void convertDouble(double d, char * to);
00127   void convertShortArray(short * from, char * to, int len);
00128   void convertInt32Array(int32_t * from, char * to, int len);
00129   void convertFloatArray(float * from, char * to, int len);
00130   void convertDoubleArray(double * from, char * to, int len);
00131 
00132   static SbString padHeader(const SbString & inString);
00133 
00134   SbBool wroteHeader;
00135 
00136 private:
00137   SoOutputP * pimpl;
00138 
00139   void constructorCommon(void);
00140 
00141   void checkHeader(void);
00142   void writeBytesWithPadding(const char * const p, const size_t nr);
00143   
00144   friend class SoBase; // Need to be able to remove items from dict.
00145   friend class SoWriterefCounter; // ditto
00146   void removeSoBase2IdRef(const SoBase * base);
00147 };
00148 
00149 #endif // !COIN_SOOUTPUT_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 28 2011 10:11:57 for Coin by Doxygen. 1.7.3