Coin: SoInput.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

SoInput.h
1#ifndef COIN_SOINPUT_H
2#define COIN_SOINPUT_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/system/inttypes.h>
37#include <Inventor/SbBasic.h>
38#include <Inventor/lists/SbList.h>
39#include <cstdio> // FILE
40#ifndef COIN_INTERNAL
41 // For Open Inventor compatibility.
42 #include <Inventor/SoDB.h>
43#endif // COIN_INTERNAL
44
45// *************************************************************************
46
47class SbDict;
48class SoBase;
49class SbString;
50class SbTime;
51class SbName;
52class SbStringList;
53class SoInput_FileInfo;
54class SoProto;
55class SoField;
56class SoFieldContainer;
57class SoInputP;
58
59// *************************************************************************
60
61 class COIN_DLL_API SoInput {
62public:
63 SoInput(void);
64 SoInput(SoInput * dictIn);
65
66 SoProto * findProto(const SbName & name);
67 void addProto(SoProto * proto);
68 void pushProto(SoProto * proto);
69 SoProto * getCurrentProto(void) const;
70 void popProto(void);
71
72 void addRoute(const SbName & fromnode, const SbName & fromfield,
73 const SbName & tonode, const SbName & tofield);
74 SbBool checkISReference(SoFieldContainer * container, const SbName & fieldname,
75 SbBool & readok);
76
77 virtual ~SoInput(void);
78
79 virtual void setFilePointer(FILE * newFP);
80 virtual SbBool openFile(const char * fileName, SbBool okIfNotFound = FALSE);
81 virtual SbBool pushFile(const char * fileName);
82 virtual void closeFile(void);
83 virtual SbBool isValidFile(void);
84 virtual SbBool isValidBuffer(void);
85 virtual FILE * getCurFile(void) const;
86 virtual const char * getCurFileName(void) const;
87 virtual void setBuffer(const void * bufpointer, size_t bufsize);
88 void setStringArray(const char * strings[]);
89 virtual size_t getNumBytesRead(void) const;
90 virtual SbString getHeader(void);
91 virtual float getIVVersion(void);
92 virtual SbBool isBinary(void);
93
94 virtual SbBool get(char & c);
95 virtual SbBool getASCIIBuffer(char & c);
96 virtual SbBool getASCIIFile(char & c);
97 virtual SbBool readHex(uint32_t & l);
98 virtual SbBool read(char & c);
99 virtual SbBool read(char & c, SbBool skip);
100 virtual SbBool read(SbString & s);
101 virtual SbBool read(SbName & n, SbBool validIdent = FALSE);
102 virtual SbBool read(int & i);
103 virtual SbBool read(unsigned int & i);
104 virtual SbBool read(short & s);
105 virtual SbBool read(unsigned short & s);
106 virtual SbBool read(float & f);
107 virtual SbBool read(double & d);
108 virtual SbBool readByte(int8_t & b);
109 virtual SbBool readByte(uint8_t & b);
110#ifdef __CYGWIN__
111 //These function are not virtual as they are meant to be only wrappers to the real function calls, due to limitations in Cygwin g++ type demangling.
112 SbBool read(long int & i);
113 SbBool read(long unsigned int & i);
114#endif //__CYGWIN__
115 virtual SbBool readBinaryArray(unsigned char * c, int length);
116 virtual SbBool readBinaryArray(int32_t * l, int length);
117 virtual SbBool readBinaryArray(float * f, int length);
118 virtual SbBool readBinaryArray(double * d, int length);
119 virtual SbBool eof(void) const;
120
121 SbBool isFileVRML1(void);
122 SbBool isFileVRML2(void);
123 virtual void resetFilePointer(FILE * fptr);
124
125 virtual void getLocationString(SbString & string) const;
126 virtual void putBack(const char c);
127 virtual void putBack(const char * str);
128 virtual void addReference(const SbName & name, SoBase * base,
129 SbBool addToGlobalDict = TRUE);
130 virtual void removeReference(const SbName & name);
131 virtual SoBase * findReference(const SbName & name) const;
132
133 static void addDirectoryFirst(const char * dirName);
134 static void addDirectoryLast(const char * dirName);
135 static void addEnvDirectoriesFirst(const char * envVarName,
136 const char * separator = ":\t ");
137 static void addEnvDirectoriesLast(const char * envVarName,
138 const char * separator = ":\t ");
139 static void removeDirectory(const char * dirName);
140 static void clearDirectories(void);
141 static const SbStringList & getDirectories(void);
142
143 static void init(void);
144
145 static SbString getPathname(const char * const filename);
146 static SbString getPathname(const SbString & s);
147 static SbString getBasename(const char * const filename);
148 static SbString getBasename(const SbString & s);
149
150 static SbString searchForFile(const SbString & basename,
151 const SbStringList & directories,
152 const SbStringList & subdirectories);
153
154
155protected:
156 virtual SbBool popFile(void);
157 void setIVVersion(float version);
158 FILE * findFile(const char * fileName, SbString & fullName);
159 void initFile(FILE * newFP, const char * fileName, SbString * fullName,
160 SbBool openedHere, SbDict * refDict = NULL);
161 SbBool checkHeader(SbBool bValidateBufferHeader = FALSE);
162 SbBool fromBuffer(void) const;
163 SbBool skipWhiteSpace(void);
164 size_t freeBytesInBuf(void) const;
165 SbBool readInteger(int32_t & l);
166 SbBool readUnsignedInteger(uint32_t & l);
167 SbBool readReal(double & d);
168 SbBool readUnsignedIntegerString(char * str);
169 int readDigits(char * str);
170 int readHexDigits(char * str);
171 int readChar(char * str, char charToRead);
172
173 SbBool makeRoomInBuf(size_t nBytes);
174 void convertShort(char * from, short * s);
175 void convertInt32(char * from, int32_t * l);
176 void convertFloat(char * from, float * f);
177 void convertDouble(char * from, double * d);
178 void convertShortArray(char * from, short * to, int len);
179 void convertInt32Array(char * from, int32_t * to, int len);
180 void convertFloatArray(char * from, float * to, int len);
181 void convertDoubleArray(char * from, double * to, int len);
182 SbBool isFileURL(const char * url);
183 char * URLToFile(char * out_buf, const char * in_buf);
184 SbBool IsURL(const char * c_strng);
185
186 static void setDirectories(SbStringList * dirs);
187
188private:
189 friend class SoDB;
190 friend class SoInputP;
191
192 static void clean(void);
193 void constructorsCommon(void);
194
195 static void addDirectoryIdx(const int idx, const char * dirName);
196 static void addEnvDirectoriesIdx(int startidx, const char * envVarName,
197 const char * separator);
198 static SbStringList * dirsearchlist;
199
200 SbList<SoInput_FileInfo *> filestack;
201 SoInput_FileInfo * getTopOfStack(void) const {
202 return this->filestack[0];
203 }
204
205 SoInputP * pimpl;
206};
207
208#endif // !COIN_SOINPUT_H
SbDict
The SbDict class organizes a dictionary of keys and values.
Definition SbDict.h:63
SbList
The SbList class is a template container class for lists.
Definition SbList.h:70
SbName
The SbName class stores strings by reference.
Definition SbName.h:40
SbStringList
The SbStringList class is a container for pointers to SbString objects.
Definition SbStringList.h:40
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
SbTime
The SbTime class instances represents time values.
Definition SbTime.h:50
SoBase
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition SoBase.h:45
SoFieldContainer
The SoFieldContainer class is a base class for all classes that contain fields.
Definition SoFieldContainer.h:43
SoField
The SoField class is the top-level abstract base class for fields.
Definition SoField.h:47
SoInput::addEnvDirectoriesLast
static void addEnvDirectoriesLast(const char *envVarName, const char *separator=":\t ")
Definition SoInput.cpp:1722
SoInput::closeFile
virtual void closeFile(void)
Definition SoInput.cpp:580
SoInput::convertDouble
void convertDouble(char *from, double *d)
Definition SoInput.cpp:2336
SoInput::getNumBytesRead
virtual size_t getNumBytesRead(void) const
Definition SoInput.cpp:767
SoInput::setFilePointer
virtual void setFilePointer(FILE *newFP)
Definition SoInput.cpp:462
SoInput::getCurFileName
virtual const char * getCurFileName(void) const
Definition SoInput.cpp:663
SoInput::eof
virtual SbBool eof(void) const
Definition SoInput.cpp:1510
SoInput::readChar
int readChar(char *str, char charToRead)
Definition SoInput.cpp:2280
SoInput::skipWhiteSpace
SbBool skipWhiteSpace(void)
Definition SoInput.cpp:2145
SoInput::isFileVRML1
SbBool isFileVRML1(void)
Definition SoInput.cpp:2409
SoInput::popFile
virtual SbBool popFile(void)
Definition SoInput.cpp:2160
SoInput::getIVVersion
virtual float getIVVersion(void)
Definition SoInput.cpp:792
SoInput::readDigits
int readDigits(char *str)
Definition SoInput.cpp:2254
SoInput::convertShort
void convertShort(char *from, short *s)
Definition SoInput.cpp:2303
SoInput::getHeader
virtual SbString getHeader(void)
Definition SoInput.cpp:778
SoInput::checkISReference
SbBool checkISReference(SoFieldContainer *container, const SbName &fieldname, SbBool &readok)
Definition SoInput.cpp:385
SoInput::readUnsignedIntegerString
SbBool readUnsignedIntegerString(char *str)
Definition SoInput.cpp:2242
SoInput::convertInt32
void convertInt32(char *from, int32_t *l)
Definition SoInput.cpp:2314
SoInput::isFileURL
SbBool isFileURL(const char *url)
Definition SoInput.cpp:2445
SoInput::isBinary
virtual SbBool isBinary(void)
Definition SoInput.cpp:802
SoInput::addRoute
void addRoute(const SbName &fromnode, const SbName &fromfield, const SbName &tonode, const SbName &tofield)
Definition SoInput.cpp:284
SoInput::addEnvDirectoriesFirst
static void addEnvDirectoriesFirst(const char *envVarName, const char *separator=":\t ")
Definition SoInput.cpp:1705
SoInput::removeReference
virtual void removeReference(const SbName &name)
Definition SoInput.cpp:1590
SoInput::get
virtual SbBool get(char &c)
Definition SoInput.cpp:819
SoInput::init
static void init(void)
Definition SoInput.cpp:1857
SoInput::isValidFile
virtual SbBool isValidFile(void)
Definition SoInput.cpp:602
SoInput::clearDirectories
static void clearDirectories(void)
Definition SoInput.cpp:1829
SoInput::isValidBuffer
virtual SbBool isValidBuffer(void)
Definition SoInput.cpp:624
SoInput::addProto
void addProto(SoProto *proto)
Definition SoInput.cpp:318
SoInput::putBack
virtual void putBack(const char c)
Definition SoInput.cpp:1548
SoInput::resetFilePointer
virtual void resetFilePointer(FILE *fptr)
Definition SoInput.cpp:2435
SoInput::readHex
virtual SbBool readHex(uint32_t &l)
Definition SoInput.cpp:860
SoInput::readReal
SbBool readReal(double &d)
Definition SoInput.cpp:2227
SoInput::setBuffer
virtual void setBuffer(const void *bufpointer, size_t bufsize)
Definition SoInput.cpp:733
SoInput::initFile
void initFile(FILE *newFP, const char *fileName, SbString *fullName, SbBool openedHere, SbDict *refDict=NULL)
Definition SoInput.cpp:2089
SoInput::searchForFile
static SbString searchForFile(const SbString &basename, const SbStringList &directories, const SbStringList &subdirectories)
Definition SoInput.cpp:2004
SoInput::makeRoomInBuf
SbBool makeRoomInBuf(size_t nBytes)
Definition SoInput.cpp:2291
SoInput::convertInt32Array
void convertInt32Array(char *from, int32_t *to, int len)
Definition SoInput.cpp:2362
SoInput::openFile
virtual SbBool openFile(const char *fileName, SbBool okIfNotFound=FALSE)
Definition SoInput.cpp:495
SoInput::getBasename
static SbString getBasename(const char *const filename)
Definition SoInput.cpp:1934
SoInput::pushFile
virtual SbBool pushFile(const char *fileName)
Definition SoInput.cpp:529
SoInput::getASCIIFile
virtual SbBool getASCIIFile(char &c)
Definition SoInput.cpp:845
SoInput::removeDirectory
static void removeDirectory(const char *dirName)
Definition SoInput.cpp:1791
SoInput::checkHeader
SbBool checkHeader(SbBool bValidateBufferHeader=FALSE)
Definition SoInput.cpp:2106
SoInput::fromBuffer
SbBool fromBuffer(void) const
Definition SoInput.cpp:2133
SoInput::freeBytesInBuf
size_t freeBytesInBuf(void) const
Definition SoInput.cpp:2191
SoInput::setIVVersion
void setIVVersion(float version)
Definition SoInput.cpp:2078
SoInput::getLocationString
virtual void getLocationString(SbString &string) const
Definition SoInput.cpp:1522
SoInput::setDirectories
static void setDirectories(SbStringList *dirs)
Definition SoInput.cpp:2479
SoInput::convertFloat
void convertFloat(char *from, float *f)
Definition SoInput.cpp:2325
SoInput::convertFloatArray
void convertFloatArray(char *from, float *to, int len)
Definition SoInput.cpp:2378
SoInput::isFileVRML2
SbBool isFileVRML2(void)
Definition SoInput.cpp:2423
SoInput::pushProto
void pushProto(SoProto *proto)
Definition SoInput.cpp:336
SoInput::readBinaryArray
virtual SbBool readBinaryArray(unsigned char *c, int length)
Definition SoInput.cpp:1444
SoInput::findReference
virtual SoBase * findReference(const SbName &name) const
Definition SoInput.cpp:1614
SoInput::getASCIIBuffer
virtual SbBool getASCIIBuffer(char &c)
Definition SoInput.cpp:834
SoInput::SoInput
SoInput(void)
Definition SoInput.cpp:185
SoInput::readByte
virtual SbBool readByte(int8_t &b)
Definition SoInput.cpp:1328
SoInput::readHexDigits
int readHexDigits(char *str)
Definition SoInput.cpp:2266
SoInput::addDirectoryLast
static void addDirectoryLast(const char *dirName)
Definition SoInput.cpp:1659
SoInput::addReference
virtual void addReference(const SbName &name, SoBase *base, SbBool addToGlobalDict=TRUE)
Definition SoInput.cpp:1572
SoInput::readInteger
SbBool readInteger(int32_t &l)
Definition SoInput.cpp:2202
SoInput::IsURL
SbBool IsURL(const char *c_strng)
Definition SoInput.cpp:2467
SoInput::addDirectoryFirst
static void addDirectoryFirst(const char *dirName)
Definition SoInput.cpp:1646
SoInput::URLToFile
char * URLToFile(char *out_buf, const char *in_buf)
Definition SoInput.cpp:2456
SoInput::findProto
SoProto * findProto(const SbName &name)
Definition SoInput.cpp:301
SoInput::getCurFile
virtual FILE * getCurFile(void) const
Definition SoInput.cpp:649
SoInput::getDirectories
static const SbStringList & getDirectories(void)
Definition SoInput.cpp:1843
SoInput::read
virtual SbBool read(char &c)
Definition SoInput.cpp:886
SoInput::readUnsignedInteger
SbBool readUnsignedInteger(uint32_t &l)
Definition SoInput.cpp:2214
SoInput::convertShortArray
void convertShortArray(char *from, short *to, int len)
Definition SoInput.cpp:2347
SoInput::setStringArray
void setStringArray(const char *strings[])
Definition SoInput.cpp:707
SoInput::findFile
FILE * findFile(const char *fileName, SbString &fullName)
Definition SoInput.cpp:2520
SoInput::popProto
void popProto(void)
Definition SoInput.cpp:352
SoInput::getPathname
static SbString getPathname(const char *const filename)
Definition SoInput.cpp:1891
SoInput::getCurrentProto
SoProto * getCurrentProto(void) const
Definition SoInput.cpp:368
SoInput::convertDoubleArray
void convertDoubleArray(char *from, double *to, int len)
Definition SoInput.cpp:2394
SoProto
The SoProto class handles PROTO definitions.
Definition SoProto.h:50