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

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

Generated on Sun May 1 2011 02:58:21 for Coin by Doxygen 1.7.3.