Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.1.1.1 $ 00045 | 00046 | Description: 00047 | This file contains the definition of the SoInput class. 00048 | 00049 | Classes: 00050 | SoInput, SoInputFile (internal) 00051 | 00052 | Author(s) : Paul S. Strauss 00053 | 00054 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00055 _______________________________________________________________________ 00056 */ 00057 00058 #ifndef _SO_INPUT_ 00059 #define _SO_INPUT_ 00060 00061 #include <Inventor/misc/SoBasic.h> 00062 #include <Inventor/SbDict.h> 00063 #include <Inventor/SbPList.h> 00064 #include <Inventor/SbString.h> 00065 #include <Inventor/SoDB.h> 00066 00067 class SoNode; 00068 class SoPath; 00069 class SoBase; 00070 class SoDB; 00071 class SbStringList; 00072 00084 00085 SoINTERNAL struct SoInputFile { 00086 SbString name; 00087 SbString fullName; 00088 FILE *fp; 00089 void *buffer; 00090 char *curBuf; 00091 size_t bufSize; 00092 int lineNum; 00093 SbBool openedHere; 00094 SbBool binary; 00095 SbBool readHeader; 00096 SbBool headerOk; 00097 SbDict *refDict; 00098 SbBool borrowedDict; 00099 float ivVersion; 00100 SbString headerString; 00101 SoDBHeaderCB *postReadCB; 00102 void *CBData; 00103 00104 SoInputFile(); 00105 }; 00106 00107 00110 00126 00127 00128 class INVENTOR_API SoInput { 00129 public: 00130 00133 SoInput(); 00134 00137 ~SoInput(); 00138 00140 static void addDirectoryFirst(const char *dirName); 00142 static void addDirectoryLast(const char *dirName); 00143 00145 static void addEnvDirectoriesFirst(const char *envVarName); 00147 static void addEnvDirectoriesLast(const char *envVarName); 00148 00150 static void removeDirectory(const char *dirName); 00151 00153 static void clearDirectories(); 00154 00156 static const SbStringList &getDirectories(); 00157 00159 void setFilePointer(FILE *newFP); 00160 00165 SbBool openFile(const char *fileName, 00166 SbBool okIfNotFound = FALSE); 00167 00170 SbBool pushFile(const char *fileName); 00171 00174 void closeFile(); 00175 00179 SbBool isValidFile(); 00180 00182 FILE * getCurFile() const; 00183 00186 const char * getCurFileName() const; 00187 00189 void setBuffer(void *bufPointer, size_t bufSize); 00190 00193 size_t getNumBytesRead() const; 00194 00196 SbString getHeader(); 00197 00202 float getIVVersion() 00203 { return curFile->ivVersion; } 00204 00205 00206 SoEXTENDER public: 00208 SbBool isBinary(); 00209 00212 SbBool get(char &c); 00213 00216 SbBool getASCIIBuffer(char &c); 00217 00220 SbBool getASCIIFile(char &c); 00221 00224 SbBool readHex(uint32_t &l); 00225 00229 SbBool read(char &c); 00230 SbBool read(SbString &s); 00231 SbBool read(SbName &n, SbBool validIdent = FALSE); 00232 SbBool read(int &i); 00233 SbBool read(unsigned int &i); 00234 SbBool read(short &s); 00235 SbBool read(unsigned short &s); 00242 SbBool read(float &f); 00243 SbBool read(double &d); 00244 SbBool readBinaryArray(unsigned char *c, int length); 00245 SbBool readBinaryArray(int32_t *l, int length); 00246 SbBool readBinaryArray(float *f, int length); 00247 SbBool readBinaryArray(double *d, int length); 00248 00250 SbBool eof() const; 00251 00252 SoINTERNAL public: 00254 static void init(); 00255 00258 SoInput(SoInput *dictIn); 00259 00262 void getLocationString(SbString &string) const; 00263 00265 void putBack(char c); 00266 void putBack(const char *string); 00267 00271 void addReference(const SbName &name, SoBase *base, 00272 SbBool addToGlobalDict = TRUE); 00273 00276 void removeReference(const SbName &name); 00277 00279 SoBase * findReference(const SbName &name) const; 00280 00281 private: 00282 static SbStringList *directories; 00283 SbPList files; 00284 struct SoInputFile *curFile; 00285 SbString backBuf; 00286 int backBufIndex; 00287 00288 void *tmpBuffer; 00289 char *curTmpBuf; 00290 size_t tmpBufSize; 00291 00292 char backupBuf[8]; 00293 00294 SbBool backupBufUsed; 00295 00297 void setIVVersion(float version) 00298 { curFile->ivVersion = version; } 00299 00301 FILE * findFile(const char *fileName, 00302 SbString &fullName) const; 00303 00305 void initFile(FILE *newFP, const char *fileName, 00306 SbString *fullName, SbBool openedHere, 00307 SbDict *refDict = NULL); 00308 00311 SbBool checkHeader(); 00312 00314 SbBool fromBuffer() const 00315 { return (curFile->buffer != NULL); } 00316 00319 SbBool skipWhiteSpace(); 00320 00322 SbBool popFile(); 00323 00325 size_t freeBytesInBuf() const 00326 { return (curFile->bufSize - 00327 (curFile->curBuf - (char *) curFile->buffer)); } 00328 00331 SbBool readInteger(int32_t &l); 00332 SbBool readUnsignedInteger(uint32_t &l); 00333 SbBool readReal(double &d); 00334 00337 SbBool readUnsignedIntegerString(char *str); 00338 00341 int readDigits(char *string, uint32_t maxDigits = 0xffffffff); 00342 int readHexDigits(char *string); 00343 00345 int readChar(char *string, char charToRead); 00346 00348 SbBool makeRoomInBuf(size_t nBytes); 00349 00351 void convertShort(char *from, short *s); 00352 void convertInt32(char *from, int32_t *l); 00353 void convertFloat(char *from, float *f); 00354 void convertDouble(char *from, double *d); 00355 void convertShortArray( char *from, register short *to, 00356 register int len); 00357 void convertInt32Array( char *from, register int32_t *to, 00358 register int len); 00359 void convertFloatArray( char *from, register float *to, 00360 register int len); 00361 void convertDoubleArray( char *from, register double *to, 00362 register int len); 00363 friend class SoBase; 00364 friend class SoDB; 00365 }; 00366 00367 #endif /* _SO_INPUT_ */