Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/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 
47 class SbDict;
48 class SoBase;
49 class SbString;
50 class SbTime;
51 class SbName;
52 class SbStringList;
53 class SoInput_FileInfo;
54 class SoProto;
55 class SoField;
56 class SoFieldContainer;
57 class SoInputP;
58 
59 // *************************************************************************
60 
61 class COIN_DLL_API SoInput {
62 public:
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 
155 protected:
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 
188 private:
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
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition: SoBase.h:45
The SoDB class keeps track of internal global data.
Definition: SoDB.h:55
The SoFieldContainer class is a base class for all classes that contain fields.
Definition: SoFieldContainer.h:43
The SbList class is a template container class for lists.
Definition: SoType.h:55
The SoField class is the top-level abstract base class for fields.
Definition: SoField.h:47
The SbDict class organizes a dictionary of keys and values.
Definition: SbDict.h:63
The SoProto class handles PROTO definitions.
Definition: SoProto.h:50
The SbTime class instances represents time values.
Definition: SbTime.h:50
The SoInput class is an abstraction of file import functionality.
Definition: SoInput.h:61
The SbString class is a string class with convenience functions for string operations.
Definition: SbString.h:52
The SbName class stores strings by reference.
Definition: SbName.h:40
The SbStringList class is a container for arrays of SbString pointers.
Definition: SbStringList.h:40