Open Inventor Reference
SoInput.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file contains the definition of the SoInput class.
48 |
49 | Classes:
50 | SoInput, SoInputFile (internal)
51 |
52 | Author(s) : Paul S. Strauss
53 |
54 ______________ S I L I C O N G R A P H I C S I N C . ____________
55 _______________________________________________________________________
56 */
57
58#ifndef _SO_INPUT_
59#define _SO_INPUT_
60
62#include <Inventor/SbDict.h>
63#include <Inventor/SbPList.h>
64#include <Inventor/SbString.h>
65#include <Inventor/SoDB.h>
66
67class SoNode;
68class SoPath;
69class SoBase;
70class SoDB;
71class SbStringList;
72
84
88 FILE *fp;
89 void *buffer;
90 char *curBuf;
91 size_t bufSize;
92 int lineNum;
94 bool binary;
96 bool headerOk;
99 float ivVersion;
102 void *CBData;
103
105};
106
107
110
127
129 public:
130
134
138
140 static void addDirectoryFirst(const char *dirName);
142 static void addDirectoryLast(const char *dirName);
143
145 static void addEnvDirectoriesFirst(const char *envVarName);
147 static void addEnvDirectoriesLast(const char *envVarName);
148
150 static void removeDirectory(const char *dirName);
151
153 static void clearDirectories();
154
157
159 void setFilePointer(FILE *newFP);
160
165 bool openFile(const char *fileName,
166 bool okIfNotFound = FALSE);
167
170 bool pushFile(const char *fileName);
171
174 void closeFile();
175
180
182 FILE * getCurFile() const;
183
186 const char * getCurFileName() const;
187
189 void setBuffer(void *bufPointer, size_t bufSize);
190
193 size_t getNumBytesRead() const;
194
197
203 { return curFile->ivVersion; }
204
205
206 SoEXTENDER public:
208 bool isBinary();
209
212 bool get(char &c);
213
216 bool getASCIIBuffer(char &c);
217
220 bool getASCIIFile(char &c);
221
225
229 bool read(char &c);
230 bool read(SbString &s);
231 bool read(SbName &n, bool validIdent = FALSE);
232 bool read(int &i);
233 bool read(unsigned int &i);
234 bool read(short &s);
235 bool read(unsigned short &s);
242 bool read(float &f);
243 bool read(double &d);
244 bool readBinaryArray(unsigned char *c, int length);
245 bool readBinaryArray(int32_t *l, int length);
246 bool readBinaryArray(float *f, int length);
247 bool readBinaryArray(double *d, int length);
248
250 bool eof() const;
251
252 SoINTERNAL public:
254 static void init();
255
258 SoInput(SoInput *dictIn);
259
262 void getLocationString(SbString &string) const;
263
265 void putBack(char c);
266 void putBack(const char *string);
267
271 void addReference(const SbName &name, SoBase *base,
272 bool addToGlobalDict = TRUE);
273
276 void removeReference(const SbName &name);
277
279 SoBase * findReference(const SbName &name) const;
280
281 private:
282 static SbStringList *directories;
283 SbPList files;
284 struct SoInputFile *curFile;
285 SbString backBuf;
286 int backBufIndex;
287
288 void *tmpBuffer;
289 char *curTmpBuf;
290 size_t tmpBufSize;
291
292 char backupBuf[8];
294 bool backupBufUsed;
295
297 void setIVVersion(float version)
298 { curFile->ivVersion = version; }
299
301 FILE * findFile(const char *fileName,
302 SbString &fullName) const;
303
305 void initFile(FILE *newFP, const char *fileName,
306 SbString *fullName, bool openedHere,
307 SbDict *refDict = NULL);
308
311 bool checkHeader();
312
314 bool fromBuffer() const
315 { return (curFile->buffer != NULL); }
316
319 bool skipWhiteSpace();
320
322 bool popFile();
323
325 size_t freeBytesInBuf() const
326 { return (curFile->bufSize -
327 (curFile->curBuf - (char *) curFile->buffer)); }
328
331 bool readInteger(int32_t &l);
332 bool readUnsignedInteger(uint32_t &l);
333 bool readReal(double &d);
334
337 bool readUnsignedIntegerString(char *str);
338
341 int readDigits(char *string, uint32_t maxDigits = 0xffffffff);
342 int readHexDigits(char *string);
343
345 int readChar(char *string, char charToRead);
346
348 bool makeRoomInBuf(size_t nBytes);
349
351 void convertShort(char *from, short *s);
352 void convertInt32(char *from, int32_t *l);
353 void convertFloat(char *from, float *f);
354 void convertDouble(char *from, double *d);
355 void convertShortArray( char *from, short *to,
356 int len);
357 void convertInt32Array( char *from, int32_t *to,
358 int len);
359 void convertFloatArray( char *from, float *to,
360 int len);
361 void convertDoubleArray( char *from, double *to,
362 int len);
363friend class SoBase;
364friend class SoDB;
365};
366
367#endif /* _SO_INPUT_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define TRUE
Definition SbBasic.h:76
#define FALSE
Definition SbBasic.h:79
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
signed int int32_t
Definition SbTypeDefs.h:43
void SoDBHeaderCB(void *userData, SoInput *in)
Definition SoDB.h:71
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
Character string stored in a hash table.
Definition SbString.h:264
List of generic (void *) pointers.
Definition SbPList.h:78
A list of strings.
Definition SbPList.h:239
Class for smart character strings.
Definition SbString.h:85
Base class for all nodes, paths, and engines.
Definition SoBase.h:90
Scene graph database class.
Definition SoDB.h:115
Used to read Inventor data files.
Definition SoInput.h:128
SoInput()
Constructor and destructor.
void addReference(const SbName &name, SoBase *base, bool addToGlobalDict=TRUE)
Adds a reference to dictionary in current file.
bool read(double &d)
void setFilePointer(FILE *newFP)
Sets file pointer to read from. Clears the stack of input files if necessary.
static void removeDirectory(const char *dirName)
Removes named directory from the list.
bool eof() const
Returns TRUE if current file/buffer is at EOF.
bool read(SbString &s)
const char * getCurFileName() const
Returns full name (including directory path) of current file, or NULL if reading from a buffer.
bool get(char &c)
Reads next character from current file/buffer.
bool getASCIIFile(char &c)
Reads next ASCII character from current file.
bool readBinaryArray(unsigned char *c, int length)
static void init()
Init function sets up global directory list.
static void addEnvDirectoriesFirst(const char *envVarName)
static void addEnvDirectoriesLast(const char *envVarName)
void removeReference(const SbName &name)
Removes a reference to dictionary in current file.
bool isBinary()
Returns whether current file/buffer being read is binary.
bool read(short &s)
bool read(char &c)
Reads item of particular type from current file pointer/buffer.
static void addDirectoryLast(const char *dirName)
bool read(int &i)
bool read(float &f)
was ... C-api: name=readInt32 but typedef makes this redundant.
bool read(unsigned short &s)
bool readBinaryArray(double *d, int length)
bool readHex(uint32_t &l)
Reads next ASCII format hex value from current file/buffer.
void closeFile()
Closes all files on stack opened with openFile() or pushFile().
void getLocationString(SbString &string) const
Fills in passed string to contain description of current location in all open input files.
bool readBinaryArray(int32_t *l, int length)
SbString getHeader()
Returns the header of the file being read.
float getIVVersion()
Returns the Inventor file version of the file being read (e.g.
Definition SoInput.h:202
SoBase * findReference(const SbName &name) const
Looks up a reference, returning the base pointer or NULL.
size_t getNumBytesRead() const
Returns number of bytes read from buffer.
void putBack(char c)
Puts a just-read character or string back in input stream/buffer.
static const SbStringList & getDirectories()
Returns the list of directories as an SbStringList.
static void clearDirectories()
Clears the list of directories (including the current directory).
bool read(SbName &n, bool validIdent=FALSE)
void putBack(const char *string)
bool read(unsigned int &i)
bool getASCIIBuffer(char &c)
Reads next ASCII character from current buffer.
bool isValidFile()
Returns TRUE if the currently open file is a valid Inventor file; that is, it begins with a valid Inv...
bool pushFile(const char *fileName)
Opens named file, pushing the resulting file pointer onto the stack.
bool openFile(const char *fileName, bool okIfNotFound=FALSE)
Opens named file, sets file pointer to result.
bool readBinaryArray(float *f, int length)
~SoInput()
Constructor and destructor.
void setBuffer(void *bufPointer, size_t bufSize)
Sets an in-memory buffer to read from, along with its size.
static void addDirectoryFirst(const char *dirName)
SoInput(SoInput *dictIn)
Constructor and destructor.
FILE * getCurFile() const
Returns a pointer to the current file, or NULL if reading from a buffer.
Abstract base class for all database nodes.
Definition SoNode.h:103
Path that points to a list of hierarchical nodes.
Definition SoPath.h:109
Structure: SoInputFile (internal)
Definition SoInput.h:85
bool headerOk
TRUE if header was read ok.
Definition SoInput.h:96
void * buffer
Buffer to read from (or NULL)
Definition SoInput.h:89
FILE * fp
File pointer.
Definition SoInput.h:88
SoInputFile()
Too complex for inlining.
SbString headerString
The header string of the input file.
Definition SoInput.h:100
char * curBuf
Current location in buffer.
Definition SoInput.h:90
SoDBHeaderCB * postReadCB
CB to be called after reading file.
Definition SoInput.h:101
bool openedHere
TRUE if opened by SoInput.
Definition SoInput.h:93
float ivVersion
Version if standard Inventor file;.
Definition SoInput.h:99
SbString fullName
Name of file with full path.
Definition SoInput.h:87
SbString name
Name of file.
Definition SoInput.h:86
bool readHeader
TRUE if header was checked for A/B.
Definition SoInput.h:95
size_t bufSize
Buffer size.
Definition SoInput.h:91
bool binary
TRUE if file has binary data.
Definition SoInput.h:94
int lineNum
Number of line currently reading.
Definition SoInput.h:92
void * CBData
User data to pass to the postReadCB.
Definition SoInput.h:102
bool borrowedDict
TRUE if dict from another SoInput.
Definition SoInput.h:98
SbDict * refDict
Node/path reference dictionary.
Definition SoInput.h:97