OpenSceneGraph 3.6.5
Input
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGDB_INPUT
15#define OSGDB_INPUT 1
16
17#include <osg/Image>
18#include <osg/Shader>
19#include <osg/Node>
20#include <osg/Drawable>
21#include <osg/StateAttribute>
22#include <osg/ArgumentParser>
23
24#include <osgDB/ReaderWriter>
25#include <osgDB/Options>
26
27#include <map>
28#include <string>
29
30namespace osgDB {
31
35 virtual bool matches(const osg::Object *proto) const = 0;
36};
37
44template<class T>
46 bool matches(const osg::Object *proto) const
47 {
48 return dynamic_cast<const T*>(proto) != 0;
49 }
50};
51
54{
55 public:
56
57 enum {
59 };
60
62 Field(const Field& field);
63 virtual ~Field();
64
65 virtual Field& operator = (const Field& ic);
66
67 void reset();
68 void addChar(char c);
69 int getNoCharacters() const { return _fieldCacheSize; }
70
71 void setWithinQuotes(bool withinQuotes=true);
73
74 void setNoNestedBrackets(int no);
76
88
90
91 bool isValid() const;
92
93 bool isOpenBracket() const;
94 bool isCloseBracket() const;
95
96 bool isWord() const;
97 bool matchWord(const char* str) const;
98 bool matchWord(const char* str,int noCharacters) const;
99
100 bool isString() const;
101 bool matchString(const char* str) const;
102 bool matchString(const char* str,int noCharacters) const;
103 bool isQuotedString() const;
104
105 const char* getStr() const;
106 char* takeStr();
107
108 bool isInt() const;
109 bool matchInt(int i) const;
110 bool getInt(int& i) const;
111
112 bool isUInt() const;
113 bool matchUInt(unsigned int i) const;
114 bool getUInt(unsigned int& i) const;
115
116 bool isFloat() const;
117 bool matchFloat(float f) const;
118 bool getFloat(float& f) const;
119 bool getFloat(double& f) const;
120
121 static FieldType calculateFieldType(const char* str,bool withinQuotes=false);
122
123 protected:
124
125 void _init();
126 void _free();
127 void _copy(const Field& ic);
128
132
134
136
138
139};
140
143{
144 public:
145
148 virtual ~FieldReader();
149
150 virtual FieldReader& operator = (const FieldReader& ic);
151
152 void attach(std::istream* input);
153 void detach();
154
155 virtual bool eof() const;
156
157 bool readField(Field& fieldPtr);
159
162
163 private:
164
165 bool _readField(Field* fieldPtr);
166
167 void _init();
168 void _free();
169 void _copy(const FieldReader& ic);
170
171 std::istream* _fin;
172 bool _eof;
173
174 bool findStartOfNextField();
175
176 int _noNestedBrackets;
177
178 bool _delimiterEatLookUp[256];
179 bool _delimiterKeepLookUp[256];
180
181};
182
185{
186 public:
187
188 enum {
190 };
191
195
197
198 void attach(std::istream* input);
199 void detach();
200
201 virtual bool eof() const;
202
203 FieldReader& getFieldReader() { return _reader; }
204
205 void insert(int pos,Field* field);
206 void insert(int pos,const char* str);
207
208 Field& operator [] (int pos);
209 Field& field (int pos);
210
211 FieldReaderIterator& operator ++ ();
212 FieldReaderIterator& operator += (int no);
213
218 void advanceToEndOfBlock(int noNestBrackets);
219
220 bool matchSequence(const char* str);
221
222 bool readSequence(const char* keyword,std::string& value);
223 bool readSequence(const char* keyword,unsigned int& value);
224 bool readSequence(const char* keyword,int& value);
225 bool readSequence(const char* keyword,float& value);
226 bool readSequence(const char* keyword,osg::Vec2f& value);
227 bool readSequence(const char* keyword,osg::Vec3f& value);
228 bool readSequence(const char* keyword,osg::Vec4f& value);
229 bool readSequence(const char* keyword,osg::Vec2d& value);
230 bool readSequence(const char* keyword,osg::Vec3d& value);
231 bool readSequence(const char* keyword,osg::Vec4d& value);
232
233 bool readSequence(std::string& value);
234 bool readSequence(unsigned int& value);
235 bool readSequence(int& value);
236 bool readSequence(float& value);
243
244 private:
245
246 void _init();
247 void _free();
248 void _copy(const FieldReaderIterator& ic);
249
250 FieldReader _reader;
251
252 Field _blank;
253
254 Field* _previousField;
255
256 Field** _fieldQueue;
257 int _fieldQueueSize;
258 int _fieldQueueCapacity;
259
260};
261
264{
265 public:
266
268 virtual ~Input();
269
270 void setOptions(const Options* options) { _options = options; }
271 const Options* getOptions() const { return _options.get(); }
272
273 virtual osg::Object* readObjectOfType(const osg::Object& compObj);
275
276
277 template<typename T>
279 {
280 return dynamic_cast<T*>(readObjectOfType(osgDB::type_wrapper<T>()));
281 }
282
288 virtual osg::Node* readNode();
290
291 virtual osg::ref_ptr<osg::Object> readObject(const std::string& fileName);
292 virtual osg::ref_ptr<osg::Image> readImage(const std::string& fileName);
293 virtual osg::ref_ptr<osg::Node> readNode(const std::string& fileName);
294 virtual osg::ref_ptr<osg::Shader> readShader(const std::string& fileName);
295
296 virtual osg::Object* getObjectForUniqueID(const std::string& uniqueID);
297 virtual void registerUniqueIDForObject(const std::string& uniqueID,osg::Object* obj);
298
300
301 bool read(Parameter value1);
302 bool read(Parameter value1, Parameter value2);
303 bool read(Parameter value1, Parameter value2, Parameter value3);
304 bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4);
305 bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
306 bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
307 bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
308 bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
309
310 bool read(const char* str);
311 bool read(const char* str, Parameter value1);
312 bool read(const char* str, Parameter value1, Parameter value2);
313 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3);
314 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4);
315 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
316 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
317 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
318 bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
319
320 private:
321
322 typedef std::map< std::string, osg::ref_ptr<osg::Object> > UniqueIDToObjectMapping;
323 UniqueIDToObjectMapping _uniqueIDToObjectMap;
324
326
327};
328
329}
330
331#endif // __SG_INPUT_H
The osgDB library provides support for reading and writing scene graphs, providing a plugin framework...
Definition Archive:24
Definition ArgumentParser:32
Pure virtual base class for drawable geometry.
Definition Drawable:89
Image class for encapsulating the storage texture image data.
Definition Image:179
Base class for all internal nodes in the scene graph.
Definition Node:72
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
osg::Shader is an application-level abstraction of an OpenGL glShader.
Definition Shader:89
Base class for state attributes.
Definition StateAttribute:77
Uniform encapsulates glUniform values.
Definition Uniform:414
General purpose double pair, uses include representation of texture coordinates.
Definition Vec2d:29
General purpose float pair.
Definition Vec2f:29
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
General purpose float triple for use as vertices, vectors and normals.
Definition Vec3f:29
General purpose double quad.
Definition Vec4d:29
General purpose float quad.
Definition Vec4f:28
basic structure for custom runtime inheritance checking
Definition Input:33
virtual ~basic_type_wrapper()
Definition Input:34
virtual bool matches(const osg::Object *proto) const =0
a class template that checks inheritance between a given Object's class and a class defined at compil...
Definition Input:45
bool matches(const osg::Object *proto) const
Definition Input:46
deprecated.
Definition Input:54
bool getFloat(float &f) const
bool matchInt(int i) const
char * takeStr()
bool isFloat() const
const char * getStr() const
static FieldType calculateFieldType(const char *str, bool withinQuotes=false)
bool matchWord(const char *str, int noCharacters) const
bool isCloseBracket() const
bool isUInt() const
bool isInt() const
virtual ~Field()
FieldType
Definition Input:78
@ CLOSE_BRACKET
Definition Input:80
@ UNINITIALISED
Definition Input:86
@ WORD
Definition Input:82
@ REAL
Definition Input:83
@ INTEGER
Definition Input:84
@ OPEN_BRACKET
Definition Input:79
@ STRING
Definition Input:81
@ BLANK
Definition Input:85
bool matchString(const char *str) const
void setNoNestedBrackets(int no)
void setWithinQuotes(bool withinQuotes=true)
int getNoNestedBrackets()
bool matchWord(const char *str) const
int _noNestedBrackets
Definition Input:137
bool getFloat(double &f) const
void addChar(char c)
FieldType getFieldType() const
bool isQuotedString() const
char * _fieldCache
Definition Input:131
@ MIN_CACHE_SIZE
Definition Input:58
bool matchFloat(float f) const
bool getWithinQuotes()
bool getInt(int &i) const
bool isValid() const
void _copy(const Field &ic)
bool isOpenBracket() const
bool isWord() const
bool _withinQuotes
Definition Input:135
bool matchUInt(unsigned int i) const
int _fieldCacheCapacity
Definition Input:129
bool isString() const
int _fieldCacheSize
Definition Input:130
int getNoCharacters() const
Definition Input:69
bool getUInt(unsigned int &i) const
Field(const Field &field)
bool matchString(const char *str, int noCharacters) const
FieldType _fieldType
Definition Input:133
deprecated.
Definition Input:143
virtual bool eof() const
void attach(std::istream *input)
virtual ~FieldReader()
FieldReader(const FieldReader &ic)
bool readField(Field &fieldPtr)
int getNoNestedBrackets() const
no of unmatched ‘{’ encountered so far in file
bool readSequence(osg::Vec3f &value)
bool readSequence(const char *keyword, osg::Vec2f &value)
bool readSequence(const char *keyword, osg::Vec4f &value)
void attach(std::istream *input)
bool readSequence(osg::Vec2d &value)
virtual bool eof() const
void advanceOverCurrentFieldOrBlock()
increments the iterator of the next simple field or whole block if the current field[0] is an open br...
bool readSequence(osg::Vec4f &value)
bool readSequence(osg::Vec4d &value)
bool readSequence(const char *keyword, float &value)
bool readSequence(const char *keyword, int &value)
bool readSequence(const char *keyword, osg::Vec2d &value)
bool readSequence(const char *keyword, osg::Vec3f &value)
bool readSequence(unsigned int &value)
void insert(int pos, const char *str)
Field & field(int pos)
bool readSequence(osg::Vec2f &value)
bool readSequence(const char *keyword, std::string &value)
bool readSequence(float &value)
bool readSequence(int &value)
bool matchSequence(const char *str)
FieldReader & getFieldReader()
Definition Input:203
void insert(int pos, Field *field)
bool readSequence(const char *keyword, osg::Vec3d &value)
FieldReaderIterator(const FieldReaderIterator &ic)
void advanceToEndOfBlock(int noNestBrackets)
bool readSequence(osg::Vec3d &value)
bool readSequence(std::string &value)
@ MINIMUM_FIELD_READER_QUEUE_SIZE
Definition Input:189
bool readSequence(const char *keyword, unsigned int &value)
bool readSequence(const char *keyword, osg::Vec4d &value)
bool read(const char *str, Parameter value1, Parameter value2)
virtual osg::StateAttribute * readStateAttribute()
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3)
virtual osg::Object * readObject()
virtual osg::Image * readImage()
virtual osg::ref_ptr< osg::Image > readImage(const std::string &fileName)
virtual osg::Shader * readShader()
virtual osg::Drawable * readDrawable()
virtual osg::Node * readNode()
virtual osg::Object * readObjectOfType(const basic_type_wrapper &btw)
T * readObjectOfType()
Definition Input:278
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
virtual osg::ref_ptr< osg::Object > readObject(const std::string &fileName)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
const Options * getOptions() const
Definition Input:271
bool read(Parameter value1, Parameter value2, Parameter value3)
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
void setOptions(const Options *options)
Definition Input:270
virtual osg::ref_ptr< osg::Shader > readShader(const std::string &fileName)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4)
bool read(const char *str, Parameter value1)
virtual osg::Object * readObjectOfType(const osg::Object &compObj)
virtual osg::Uniform * readUniform()
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4)
virtual osg::ref_ptr< osg::Node > readNode(const std::string &fileName)
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
bool read(const char *str)
bool read(Parameter value1)
virtual void registerUniqueIDForObject(const std::string &uniqueID, osg::Object *obj)
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
bool read(Parameter value1, Parameter value2)
virtual ~Input()
virtual osg::Object * getObjectForUniqueID(const std::string &uniqueID)
osg::ArgumentParser::Parameter Parameter
Definition Input:299
Options base class used for passing options into plugins to control their operation.
Definition Options:30
#define OSGDB_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.