osgDB/Input
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGDB_INPUT
#define OSGDB_INPUT 1
#include <osg/Image>
#include <osg/Shader>
#include <osg/Node>
#include <osg/Drawable>
#include <osg/StateAttribute>
#include <osg/ArgumentParser>
#include <osgDB/ReaderWriter>
#include <osgDB/Options>
#include <map>
#include <string>
namespace osgDB {
struct basic_type_wrapper {
virtual ~basic_type_wrapper() {}
virtual bool matches(const osg::Object *proto) const = 0;
};
template<class T>
struct type_wrapper: basic_type_wrapper {
bool matches(const osg::Object *proto) const
{
return dynamic_cast<const T*>(proto) != 0;
}
};
class OSGDB_EXPORT Field
{
public:
enum {
MIN_CACHE_SIZE = 256
};
Field();
Field(const Field& field);
virtual ~Field();
virtual Field& operator = (const Field& ic);
void reset();
void addChar(char c);
int getNoCharacters() const { return _fieldCacheSize; }
void setWithinQuotes(bool withinQuotes=true);
bool getWithinQuotes();
void setNoNestedBrackets(int no);
int getNoNestedBrackets();
enum FieldType
{
OPEN_BRACKET,
CLOSE_BRACKET,
STRING,
WORD,
REAL,
INTEGER,
BLANK,
UNINITIALISED
};
FieldType getFieldType() const;
bool isValid() const;
bool isOpenBracket() const;
bool isCloseBracket() const;
bool isWord() const;
bool matchWord(const char* str) const;
bool matchWord(const char* str,int noCharacters) const;
bool isString() const;
bool matchString(const char* str) const;
bool matchString(const char* str,int noCharacters) const;
bool isQuotedString() const;
const char* getStr() const;
char* takeStr();
bool isInt() const;
bool matchInt(int i) const;
bool getInt(int& i) const;
bool isUInt() const;
bool matchUInt(unsigned int i) const;
bool getUInt(unsigned int& i) const;
bool isFloat() const;
bool matchFloat(float f) const;
bool getFloat(float& f) const;
bool getFloat(double& f) const;
static FieldType calculateFieldType(const char* str,bool withinQuotes=false);
protected:
void _init();
void _free();
void _copy(const Field& ic);
int _fieldCacheCapacity;
int _fieldCacheSize;
char* _fieldCache;
mutable FieldType _fieldType;
bool _withinQuotes;
int _noNestedBrackets;
};
class OSGDB_EXPORT FieldReader
{
public:
FieldReader();
FieldReader(const FieldReader& ic);
virtual ~FieldReader();
virtual FieldReader& operator = (const FieldReader& ic);
void attach(std::istream* input);
void detach();
virtual bool eof() const;
bool readField(Field& fieldPtr);
void ignoreField();
int getNoNestedBrackets() const;
private:
bool _readField(Field* fieldPtr);
void _init();
void _free();
void _copy(const FieldReader& ic);
std::istream* _fin;
bool _eof;
bool findStartOfNextField();
int _noNestedBrackets;
bool _delimiterEatLookUp[256];
bool _delimiterKeepLookUp[256];
};
class OSGDB_EXPORT FieldReaderIterator
{
public:
enum {
MINIMUM_FIELD_READER_QUEUE_SIZE = 10
};
FieldReaderIterator();
FieldReaderIterator(const FieldReaderIterator& ic);
virtual ~FieldReaderIterator();
FieldReaderIterator& operator = (const FieldReaderIterator& ic);
void attach(std::istream* input);
void detach();
virtual bool eof() const;
FieldReader& getFieldReader() { return _reader; }
void insert(int pos,Field* field);
void insert(int pos,const char* str);
Field& operator [] (int pos);
Field& field (int pos);
FieldReaderIterator& operator ++ ();
FieldReaderIterator& operator += (int no);
void advanceOverCurrentFieldOrBlock();
void advanceToEndOfCurrentBlock();
void advanceToEndOfBlock(int noNestBrackets);
bool matchSequence(const char* str);
bool readSequence(const char* keyword,std::string& value);
bool readSequence(const char* keyword,unsigned int& value);
bool readSequence(const char* keyword,int& value);
bool readSequence(const char* keyword,float& value);
bool readSequence(const char* keyword,osg::Vec2f& value);
bool readSequence(const char* keyword,osg::Vec3f& value);
bool readSequence(const char* keyword,osg::Vec4f& value);
bool readSequence(const char* keyword,osg::Vec2d& value);
bool readSequence(const char* keyword,osg::Vec3d& value);
bool readSequence(const char* keyword,osg::Vec4d& value);
bool readSequence(std::string& value);
bool readSequence(unsigned int& value);
bool readSequence(int& value);
bool readSequence(float& value);
bool readSequence(osg::Vec2f& value);
bool readSequence(osg::Vec3f& value);
bool readSequence(osg::Vec4f& value);
bool readSequence(osg::Vec2d& value);
bool readSequence(osg::Vec3d& value);
bool readSequence(osg::Vec4d& value);
private:
void _init();
void _free();
void _copy(const FieldReaderIterator& ic);
FieldReader _reader;
Field _blank;
Field* _previousField;
Field** _fieldQueue;
int _fieldQueueSize;
int _fieldQueueCapacity;
};
class OSGDB_EXPORT Input : public FieldReaderIterator
{
public:
Input();
virtual ~Input();
void setOptions(const Options* options) { _options = options; }
const Options* getOptions() const { return _options.get(); }
virtual osg::Object* readObjectOfType(const osg::Object& compObj);
virtual osg::Object* readObjectOfType(const basic_type_wrapper &btw);
template<typename T>
inline T* readObjectOfType()
{
return dynamic_cast<T*>(readObjectOfType(osgDB::type_wrapper<T>()));
}
virtual osg::Object* readObject();
virtual osg::Image* readImage();
virtual osg::Drawable* readDrawable();
virtual osg::StateAttribute* readStateAttribute();
virtual osg::Uniform* readUniform();
virtual osg::Node* readNode();
virtual osg::Shader* readShader();
virtual osg::ref_ptr<osg::Object> readObject(const std::string& fileName);
virtual osg::ref_ptr<osg::Image> readImage(const std::string& fileName);
virtual osg::ref_ptr<osg::Node> readNode(const std::string& fileName);
virtual osg::ref_ptr<osg::Shader> readShader(const std::string& fileName);
virtual osg::Object* getObjectForUniqueID(const std::string& uniqueID);
virtual void registerUniqueIDForObject(const std::string& uniqueID,osg::Object* obj);
typedef osg::ArgumentParser::Parameter Parameter;
bool read(Parameter value1);
bool read(Parameter value1, Parameter value2);
bool read(Parameter value1, Parameter value2, Parameter value3);
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4);
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
bool read(const char* str);
bool read(const char* str, Parameter value1);
bool read(const char* str, Parameter value1, Parameter value2);
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3);
bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4);
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, Parameter value4, Parameter value5, Parameter value6);
bool read(const char* str, 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, Parameter value8);
private:
typedef std::map< std::string, osg::ref_ptr<osg::Object> > UniqueIDToObjectMapping;
UniqueIDToObjectMapping _uniqueIDToObjectMap;
osg::ref_ptr<const Options> _options;
};
}
#endif // __SG_INPUT_H
ArgumentParser
Drawable
Image
Node
Options
ReaderWriter
Shader
StateAttribute
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec3f &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec2f &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec4f &value)
osgDB::FieldReaderIterator::attach
void attach(std::istream *input)
osgDB::FieldReaderIterator::detach
void detach()
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec2d &value)
osgDB::FieldReaderIterator::eof
virtual bool eof() const
osgDB::FieldReaderIterator::advanceOverCurrentFieldOrBlock
void advanceOverCurrentFieldOrBlock()
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec4f &value)
osgDB::FieldReaderIterator::MINIMUM_FIELD_READER_QUEUE_SIZE
@ MINIMUM_FIELD_READER_QUEUE_SIZE
Definition osgDB/Input:189
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec4d &value)
osgDB::FieldReaderIterator::advanceToEndOfCurrentBlock
void advanceToEndOfCurrentBlock()
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, float &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, int &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec2d &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec3f &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(unsigned int &value)
osgDB::FieldReaderIterator::insert
void insert(int pos, const char *str)
osgDB::FieldReaderIterator::field
Field & field(int pos)
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec2f &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, std::string &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(float &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(int &value)
osgDB::FieldReaderIterator::matchSequence
bool matchSequence(const char *str)
osgDB::FieldReaderIterator::getFieldReader
FieldReader & getFieldReader()
Definition osgDB/Input:203
osgDB::FieldReaderIterator::~FieldReaderIterator
virtual ~FieldReaderIterator()
osgDB::FieldReaderIterator::insert
void insert(int pos, Field *field)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec3d &value)
osgDB::FieldReaderIterator::FieldReaderIterator
FieldReaderIterator(const FieldReaderIterator &ic)
osgDB::FieldReaderIterator::FieldReaderIterator
FieldReaderIterator()
osgDB::FieldReaderIterator::advanceToEndOfBlock
void advanceToEndOfBlock(int noNestBrackets)
osgDB::FieldReaderIterator::readSequence
bool readSequence(osg::Vec3d &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(std::string &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, unsigned int &value)
osgDB::FieldReaderIterator::readSequence
bool readSequence(const char *keyword, osg::Vec4d &value)
osgDB::FieldReader
Definition osgDB/Input:143
osgDB::FieldReader::eof
virtual bool eof() const
osgDB::FieldReader::attach
void attach(std::istream *input)
osgDB::FieldReader::detach
void detach()
osgDB::FieldReader::ignoreField
void ignoreField()
osgDB::FieldReader::~FieldReader
virtual ~FieldReader()
osgDB::FieldReader::FieldReader
FieldReader(const FieldReader &ic)
osgDB::FieldReader::FieldReader
FieldReader()
osgDB::FieldReader::readField
bool readField(Field &fieldPtr)
osgDB::Field
Definition osgDB/Input:54
osgDB::Field::getFloat
bool getFloat(float &f) const
osgDB::Field::matchInt
bool matchInt(int i) const
osgDB::Field::takeStr
char * takeStr()
osgDB::Field::isFloat
bool isFloat() const
osgDB::Field::getStr
const char * getStr() const
osgDB::Field::calculateFieldType
static FieldType calculateFieldType(const char *str, bool withinQuotes=false)
osgDB::Field::matchWord
bool matchWord(const char *str, int noCharacters) const
osgDB::Field::isCloseBracket
bool isCloseBracket() const
osgDB::Field::isUInt
bool isUInt() const
osgDB::Field::isInt
bool isInt() const
osgDB::Field::~Field
virtual ~Field()
osgDB::Field::FieldType
FieldType
Definition osgDB/Input:78
osgDB::Field::CLOSE_BRACKET
@ CLOSE_BRACKET
Definition osgDB/Input:80
osgDB::Field::UNINITIALISED
@ UNINITIALISED
Definition osgDB/Input:86
osgDB::Field::WORD
@ WORD
Definition osgDB/Input:82
osgDB::Field::REAL
@ REAL
Definition osgDB/Input:83
osgDB::Field::INTEGER
@ INTEGER
Definition osgDB/Input:84
osgDB::Field::OPEN_BRACKET
@ OPEN_BRACKET
Definition osgDB/Input:79
osgDB::Field::STRING
@ STRING
Definition osgDB/Input:81
osgDB::Field::BLANK
@ BLANK
Definition osgDB/Input:85
osgDB::Field::Field
Field()
osgDB::Field::matchString
bool matchString(const char *str) const
osgDB::Field::setNoNestedBrackets
void setNoNestedBrackets(int no)
osgDB::Field::_free
void _free()
osgDB::Field::setWithinQuotes
void setWithinQuotes(bool withinQuotes=true)
osgDB::Field::getNoNestedBrackets
int getNoNestedBrackets()
osgDB::Field::matchWord
bool matchWord(const char *str) const
osgDB::Field::_noNestedBrackets
int _noNestedBrackets
Definition osgDB/Input:137
osgDB::Field::getFloat
bool getFloat(double &f) const
osgDB::Field::addChar
void addChar(char c)
osgDB::Field::getFieldType
FieldType getFieldType() const
osgDB::Field::isQuotedString
bool isQuotedString() const
osgDB::Field::_fieldCache
char * _fieldCache
Definition osgDB/Input:131
osgDB::Field::matchFloat
bool matchFloat(float f) const
osgDB::Field::getWithinQuotes
bool getWithinQuotes()
osgDB::Field::getInt
bool getInt(int &i) const
osgDB::Field::_init
void _init()
osgDB::Field::isValid
bool isValid() const
osgDB::Field::_copy
void _copy(const Field &ic)
osgDB::Field::isOpenBracket
bool isOpenBracket() const
osgDB::Field::isWord
bool isWord() const
osgDB::Field::_withinQuotes
bool _withinQuotes
Definition osgDB/Input:135
osgDB::Field::matchUInt
bool matchUInt(unsigned int i) const
osgDB::Field::_fieldCacheCapacity
int _fieldCacheCapacity
Definition osgDB/Input:129
osgDB::Field::isString
bool isString() const
osgDB::Field::_fieldCacheSize
int _fieldCacheSize
Definition osgDB/Input:130
osgDB::Field::getNoCharacters
int getNoCharacters() const
Definition osgDB/Input:69
osgDB::Field::getUInt
bool getUInt(unsigned int &i) const
osgDB::Field::MIN_CACHE_SIZE
@ MIN_CACHE_SIZE
Definition osgDB/Input:58
osgDB::Field::reset
void reset()
osgDB::Field::Field
Field(const Field &field)
osgDB::Field::matchString
bool matchString(const char *str, int noCharacters) const
osgDB::Field::_fieldType
FieldType _fieldType
Definition osgDB/Input:133
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2)
osgDB::Input::readStateAttribute
virtual osg::StateAttribute * readStateAttribute()
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
osgDB::Input::Input
Input()
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3)
osgDB::Input::readObject
virtual osg::Object * readObject()
osgDB::Input::readImage
virtual osg::Image * readImage()
osgDB::Input::readImage
virtual osg::ref_ptr< osg::Image > readImage(const std::string &fileName)
osgDB::Input::readShader
virtual osg::Shader * readShader()
osgDB::Input::readDrawable
virtual osg::Drawable * readDrawable()
osgDB::Input::readNode
virtual osg::Node * readNode()
osgDB::Input::readObjectOfType
virtual osg::Object * readObjectOfType(const basic_type_wrapper &btw)
osgDB::Input::readObjectOfType
T * readObjectOfType()
Definition osgDB/Input:278
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
osgDB::Input::readObject
virtual osg::ref_ptr< osg::Object > readObject(const std::string &fileName)
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
osgDB::Input::getOptions
const Options * getOptions() const
Definition osgDB/Input:271
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3)
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
osgDB::Input::setOptions
void setOptions(const Options *options)
Definition osgDB/Input:270
osgDB::Input::readShader
virtual osg::ref_ptr< osg::Shader > readShader(const std::string &fileName)
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4)
osgDB::Input::read
bool read(const char *str, Parameter value1)
osgDB::Input::readObjectOfType
virtual osg::Object * readObjectOfType(const osg::Object &compObj)
osgDB::Input::readUniform
virtual osg::Uniform * readUniform()
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4)
osgDB::Input::readNode
virtual osg::ref_ptr< osg::Node > readNode(const std::string &fileName)
osgDB::Input::read
bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
osgDB::Input::read
bool read(const char *str)
osgDB::Input::read
bool read(Parameter value1)
osgDB::Input::registerUniqueIDForObject
virtual void registerUniqueIDForObject(const std::string &uniqueID, osg::Object *obj)
osgDB::Input::read
bool read(const char *str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
osgDB::Input::read
bool read(Parameter value1, Parameter value2)
osgDB::Input::~Input
virtual ~Input()
osgDB::Input::getObjectForUniqueID
virtual osg::Object * getObjectForUniqueID(const std::string &uniqueID)
osgDB::Input::Parameter
osg::ArgumentParser::Parameter Parameter
Definition osgDB/Input:299
osgDB::Options
Definition Options:30
osg::ArgumentParser::Parameter
Definition ArgumentParser:32
osg::Drawable
Definition Drawable:89
osg::Image
Definition Image:179
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::Shader
Definition Shader:89
osg::StateAttribute
Definition StateAttribute:77
osg::Uniform
Definition Uniform:414
osg::Vec2d
Definition Vec2d:29
osg::Vec2f
Definition Vec2f:29
osg::Vec3d
Definition Vec3d:30
osg::Vec3f
Definition Vec3f:29
osg::Vec4d
Definition Vec4d:29
osg::Vec4f
Definition Vec4f:28
osg::ref_ptr
Definition ref_ptr:32
osgDB
Definition Archive:24
OSGDB_EXPORT
#define OSGDB_EXPORT
Definition osgDB/Export:39
osgDB::basic_type_wrapper
Definition osgDB/Input:33
osgDB::basic_type_wrapper::~basic_type_wrapper
virtual ~basic_type_wrapper()
Definition osgDB/Input:34
osgDB::basic_type_wrapper::matches
virtual bool matches(const osg::Object *proto) const =0
osgDB::type_wrapper
Definition osgDB/Input:45
osgDB::type_wrapper::matches
bool matches(const osg::Object *proto) const
Definition osgDB/Input:46