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