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

SoInput.h

00001 #ifndef COIN_SOINPUT_H
00002 #define COIN_SOINPUT_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/lists/SbList.h>
00030 #include <stdio.h> // FILE
00031 #ifndef COIN_INTERNAL
00032  // For Open Inventor compatibility.
00033  #include <Inventor/SoDB.h>
00034  #include <Inventor/SbDict.h>
00035 #else
00036  #define COIN_ALLOW_SBDICT // Coin 2.x hack, for ABI compatibility
00037  #include <Inventor/SbDict.h>
00038  #undef COIN_ALLOW_SBDICT
00039 #endif // COIN_INTERNAL
00040 
00041 // *************************************************************************
00042 
00043 class SoBase;
00044 class SbString;
00045 class SbTime;
00046 class SbName;
00047 class SbStringList;
00048 class SoInput_FileInfo;
00049 class SoProto;
00050 class SoField;
00051 class SoFieldContainer;
00052 
00053 // *************************************************************************
00054 
00055 class COIN_DLL_API SoInput {
00056 public:
00057   SoInput(void);
00058   SoInput(SoInput * dictIn);
00059 
00060   SoProto * findProto(const SbName & name);
00061   void addProto(SoProto * proto);
00062   void pushProto(SoProto * proto);
00063   SoProto * getCurrentProto(void) const;
00064   void popProto(void);
00065 
00066   void addRoute(const SbName & fromnode, const SbName & fromfield,
00067                 const SbName & tonode, const SbName & tofield);
00068   SbBool checkISReference(SoFieldContainer * container, const SbName & fieldname, 
00069                           SbBool & readok);
00070   
00071   virtual ~SoInput(void);
00072 
00073   virtual void setFilePointer(FILE * newFP);
00074   virtual SbBool openFile(const char * fileName, SbBool okIfNotFound = FALSE);
00075   virtual SbBool pushFile(const char * fileName);
00076   virtual void closeFile(void);
00077   virtual SbBool isValidFile(void);
00078   virtual SbBool isValidBuffer(void);
00079   virtual FILE * getCurFile(void) const;
00080   virtual const char * getCurFileName(void) const;
00081   virtual void setBuffer(void * bufpointer, size_t bufsize);
00082           void setStringArray(const char * strings[]);
00083   virtual size_t getNumBytesRead(void) const;
00084   virtual SbString getHeader(void);
00085   virtual float getIVVersion(void);
00086   virtual SbBool isBinary(void);
00087 
00088   virtual SbBool get(char & c);
00089   virtual SbBool getASCIIBuffer(char & c);
00090   virtual SbBool getASCIIFile(char & c);
00091   virtual SbBool readHex(uint32_t & l);
00092   virtual SbBool read(char & c);
00093   virtual SbBool read(char & c, SbBool skip);
00094   virtual SbBool read(SbString & s);
00095   virtual SbBool read(SbName & n, SbBool validIdent = FALSE);
00096   virtual SbBool read(int & i);
00097   virtual SbBool read(unsigned int & i);
00098   virtual SbBool read(short & s);
00099   virtual SbBool read(unsigned short & s);
00100   virtual SbBool read(float & f);
00101   virtual SbBool read(double & d);
00102   virtual SbBool readBinaryArray(unsigned char * c, int length);
00103   virtual SbBool readBinaryArray(int32_t * l, int length);
00104   virtual SbBool readBinaryArray(float * f, int length);
00105   virtual SbBool readBinaryArray(double * d, int length);
00106   SbBool readByte(int8_t & b);
00107   SbBool readByte(uint8_t & b);
00108   virtual SbBool eof(void) const;
00109 
00110   SbBool isFileVRML1(void);
00111   SbBool isFileVRML2(void);
00112   virtual void resetFilePointer(FILE * fptr);
00113 
00114   virtual void getLocationString(SbString & string) const;
00115   virtual void putBack(const char c);
00116   virtual void putBack(const char * str);
00117   virtual void addReference(const SbName & name, SoBase * base,
00118                             SbBool addToGlobalDict = TRUE);
00119   virtual void removeReference(const SbName & name);
00120   virtual SoBase * findReference(const SbName & name) const;
00121 
00122   static void addDirectoryFirst(const char * dirName);
00123   static void addDirectoryLast(const char * dirName);
00124   static void addEnvDirectoriesFirst(const char * envVarName,
00125                                      const char * separator = ":\t ");
00126   static void addEnvDirectoriesLast(const char * envVarName,
00127                                     const char * separator = ":\t ");
00128   static void removeDirectory(const char * dirName);
00129   static void clearDirectories(void);
00130   static const SbStringList & getDirectories(void);
00131 
00132   static void init(void);
00133 
00134   static SbString getPathname(const char * const filename);
00135   static SbString getPathname(const SbString & s);
00136   static SbString getBasename(const char * const filename);
00137   static SbString getBasename(const SbString & s);
00138 
00139   static SbString searchForFile(const SbString & basename,
00140                                 const SbStringList & directories,
00141                                 const SbStringList & subdirectories);
00142 
00143 
00144 protected:
00145   virtual SbBool popFile(void);
00146   void setIVVersion(float version);
00147   FILE * findFile(const char * fileName, SbString & fullName);
00148   void initFile(FILE * newFP, const char * fileName, SbString * fullName,
00149                 SbBool openedHere, SbDict * refDict = (SbDict *) NULL);
00150   SbBool checkHeader(SbBool bValidateBufferHeader = FALSE);
00151   SbBool fromBuffer(void) const;
00152   SbBool skipWhiteSpace(void);
00153   size_t freeBytesInBuf(void) const;
00154   SbBool readInteger(int32_t & l);
00155   SbBool readUnsignedInteger(uint32_t & l);
00156   SbBool readReal(double & d);
00157   SbBool readUnsignedIntegerString(char * str);
00158   int readDigits(char * str);
00159   int readHexDigits(char * str);
00160   int readChar(char * str, char charToRead);
00161 
00162   SbBool makeRoomInBuf(size_t nBytes);
00163   void convertShort(char * from, short * s);
00164   void convertInt32(char * from, int32_t * l);
00165   void convertFloat(char * from, float * f);
00166   void convertDouble(char * from, double * d);
00167   void convertShortArray(char * from, short * to, int len);
00168   void convertInt32Array(char * from, int32_t * to, int len);
00169   void convertFloatArray(char * from, float * to, int len);
00170   void convertDoubleArray(char * from, double * to, int len);
00171   SbBool isFileURL(const char * url);
00172   char * URLToFile(char * out_buf, const char * in_buf);
00173   SbBool IsURL(const char * c_strng);
00174 
00175   static void setDirectories(SbStringList * dirs);
00176 
00177 private:
00178   friend class SoDB;
00179   friend class SoInputP;
00180 
00181   static void clean(void);
00182   void constructorsCommon(void);
00183 
00184   static void addDirectoryIdx(const int idx, const char * dirName);
00185   static void addEnvDirectoriesIdx(int startidx, const char * envVarName,
00186                                    const char * separator);
00187   static SbStringList * dirsearchlist;
00188 
00189   SbList<SoInput_FileInfo *> filestack;
00190   SoInput_FileInfo * getTopOfStack(void) const {
00191     return this->filestack[0];
00192   }
00193 
00194   // OBSOLETE, only kept for Coin 2.x ABI compatibility.
00195   SbDict refdict;
00196 };
00197 
00198 #endif // !COIN_SOINPUT_H

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

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