| 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 | |
|---|
| 30 | namespace osgDB { |
|---|
| 31 | |
|---|
| 32 | struct basic_type_wrapper; |
|---|
| 33 | |
|---|
| 34 | /** deprecated. */ |
|---|
| 35 | class OSGDB_EXPORT Field |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | |
|---|
| 39 | enum { |
|---|
| 40 | MIN_CACHE_SIZE = 256 |
|---|
| 41 | }; |
|---|
| 42 | |
|---|
| 43 | Field(); |
|---|
| 44 | Field(const Field& field); |
|---|
| 45 | virtual ~Field(); |
|---|
| 46 | |
|---|
| 47 | virtual Field& operator = (const Field& ic); |
|---|
| 48 | |
|---|
| 49 | void reset(); |
|---|
| 50 | void addChar(char c); |
|---|
| 51 | int getNoCharacters() const { return _fieldCacheSize; } |
|---|
| 52 | |
|---|
| 53 | void setWithinQuotes(bool withinQuotes=true); |
|---|
| 54 | bool getWithinQuotes(); |
|---|
| 55 | |
|---|
| 56 | void setNoNestedBrackets(int no); |
|---|
| 57 | int getNoNestedBrackets(); |
|---|
| 58 | |
|---|
| 59 | enum FieldType |
|---|
| 60 | { |
|---|
| 61 | OPEN_BRACKET, |
|---|
| 62 | CLOSE_BRACKET, |
|---|
| 63 | STRING, |
|---|
| 64 | WORD, |
|---|
| 65 | REAL, |
|---|
| 66 | INTEGER, |
|---|
| 67 | BLANK, |
|---|
| 68 | UNINITIALISED |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | FieldType getFieldType() const; |
|---|
| 72 | |
|---|
| 73 | bool isValid() const; |
|---|
| 74 | |
|---|
| 75 | bool isOpenBracket() const; |
|---|
| 76 | bool isCloseBracket() const; |
|---|
| 77 | |
|---|
| 78 | bool isWord() const; |
|---|
| 79 | bool matchWord(const char* str) const; |
|---|
| 80 | bool matchWord(const char* str,int noCharacters) const; |
|---|
| 81 | |
|---|
| 82 | bool isString() const; |
|---|
| 83 | bool matchString(const char* str) const; |
|---|
| 84 | bool matchString(const char* str,int noCharacters) const; |
|---|
| 85 | bool isQuotedString() const; |
|---|
| 86 | |
|---|
| 87 | const char* getStr() const; |
|---|
| 88 | char* takeStr(); |
|---|
| 89 | |
|---|
| 90 | bool isInt() const; |
|---|
| 91 | bool matchInt(int i) const; |
|---|
| 92 | bool getInt(int& i) const; |
|---|
| 93 | |
|---|
| 94 | bool isUInt() const; |
|---|
| 95 | bool matchUInt(unsigned int i) const; |
|---|
| 96 | bool getUInt(unsigned int& i) const; |
|---|
| 97 | |
|---|
| 98 | bool isFloat() const; |
|---|
| 99 | bool matchFloat(float f) const; |
|---|
| 100 | bool getFloat(float& f) const; |
|---|
| 101 | bool getFloat(double& f) const; |
|---|
| 102 | |
|---|
| 103 | static FieldType calculateFieldType(const char* str,bool withinQuotes=false); |
|---|
| 104 | |
|---|
| 105 | protected: |
|---|
| 106 | |
|---|
| 107 | void _init(); |
|---|
| 108 | void _free(); |
|---|
| 109 | void _copy(const Field& ic); |
|---|
| 110 | |
|---|
| 111 | int _fieldCacheCapacity; |
|---|
| 112 | int _fieldCacheSize; |
|---|
| 113 | char* _fieldCache; |
|---|
| 114 | |
|---|
| 115 | mutable FieldType _fieldType; |
|---|
| 116 | |
|---|
| 117 | bool _withinQuotes; |
|---|
| 118 | |
|---|
| 119 | int _noNestedBrackets; |
|---|
| 120 | |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | /** deprecated. */ |
|---|
| 124 | class OSGDB_EXPORT FieldReader |
|---|
| 125 | { |
|---|
| 126 | public: |
|---|
| 127 | |
|---|
| 128 | FieldReader(); |
|---|
| 129 | FieldReader(const FieldReader& ic); |
|---|
| 130 | virtual ~FieldReader(); |
|---|
| 131 | |
|---|
| 132 | virtual FieldReader& operator = (const FieldReader& ic); |
|---|
| 133 | |
|---|
| 134 | void attach(std::istream* input); |
|---|
| 135 | void detach(); |
|---|
| 136 | |
|---|
| 137 | virtual bool eof() const; |
|---|
| 138 | |
|---|
| 139 | bool readField(Field& fieldPtr); |
|---|
| 140 | void ignoreField(); |
|---|
| 141 | |
|---|
| 142 | /** no of unmatched `{' encountered so far in file*/ |
|---|
| 143 | int getNoNestedBrackets() const; |
|---|
| 144 | |
|---|
| 145 | private: |
|---|
| 146 | |
|---|
| 147 | bool _readField(Field* fieldPtr); |
|---|
| 148 | |
|---|
| 149 | void _init(); |
|---|
| 150 | void _free(); |
|---|
| 151 | void _copy(const FieldReader& ic); |
|---|
| 152 | |
|---|
| 153 | std::istream* _fin; |
|---|
| 154 | bool _eof; |
|---|
| 155 | |
|---|
| 156 | bool findStartOfNextField(); |
|---|
| 157 | |
|---|
| 158 | int _noNestedBrackets; |
|---|
| 159 | |
|---|
| 160 | bool _delimiterEatLookUp[256]; |
|---|
| 161 | bool _delimiterKeepLookUp[256]; |
|---|
| 162 | |
|---|
| 163 | }; |
|---|
| 164 | |
|---|
| 165 | /** deprecated. */ |
|---|
| 166 | class OSGDB_EXPORT FieldReaderIterator |
|---|
| 167 | { |
|---|
| 168 | public: |
|---|
| 169 | |
|---|
| 170 | enum { |
|---|
| 171 | MINIMUM_FIELD_READER_QUEUE_SIZE = 10 |
|---|
| 172 | }; |
|---|
| 173 | |
|---|
| 174 | FieldReaderIterator(); |
|---|
| 175 | FieldReaderIterator(const FieldReaderIterator& ic); |
|---|
| 176 | virtual ~FieldReaderIterator(); |
|---|
| 177 | |
|---|
| 178 | FieldReaderIterator& operator = (const FieldReaderIterator& ic); |
|---|
| 179 | |
|---|
| 180 | void attach(std::istream* input); |
|---|
| 181 | void detach(); |
|---|
| 182 | |
|---|
| 183 | virtual bool eof() const; |
|---|
| 184 | |
|---|
| 185 | FieldReader& getFieldReader() { return _reader; } |
|---|
| 186 | |
|---|
| 187 | void insert(int pos,Field* field); |
|---|
| 188 | void insert(int pos,const char* str); |
|---|
| 189 | |
|---|
| 190 | Field& operator [] (int pos); |
|---|
| 191 | Field& field (int pos); |
|---|
| 192 | |
|---|
| 193 | FieldReaderIterator& operator ++ (); |
|---|
| 194 | FieldReaderIterator& operator += (int no); |
|---|
| 195 | |
|---|
| 196 | /** increments the iterator of the next simple field or |
|---|
| 197 | * whole block if the current field[0] is an open bracket */ |
|---|
| 198 | void advanceOverCurrentFieldOrBlock(); |
|---|
| 199 | void advanceToEndOfCurrentBlock(); |
|---|
| 200 | void advanceToEndOfBlock(int noNestBrackets); |
|---|
| 201 | |
|---|
| 202 | bool matchSequence(const char* str); |
|---|
| 203 | |
|---|
| 204 | bool readSequence(const char* keyword,std::string& value); |
|---|
| 205 | bool readSequence(const char* keyword,unsigned int& value); |
|---|
| 206 | bool readSequence(const char* keyword,int& value); |
|---|
| 207 | bool readSequence(const char* keyword,float& value); |
|---|
| 208 | bool readSequence(const char* keyword,osg::Vec2f& value); |
|---|
| 209 | bool readSequence(const char* keyword,osg::Vec3f& value); |
|---|
| 210 | bool readSequence(const char* keyword,osg::Vec4f& value); |
|---|
| 211 | bool readSequence(const char* keyword,osg::Vec2d& value); |
|---|
| 212 | bool readSequence(const char* keyword,osg::Vec3d& value); |
|---|
| 213 | bool readSequence(const char* keyword,osg::Vec4d& value); |
|---|
| 214 | |
|---|
| 215 | bool readSequence(std::string& value); |
|---|
| 216 | bool readSequence(unsigned int& value); |
|---|
| 217 | bool readSequence(int& value); |
|---|
| 218 | bool readSequence(float& value); |
|---|
| 219 | bool readSequence(osg::Vec2f& value); |
|---|
| 220 | bool readSequence(osg::Vec3f& value); |
|---|
| 221 | bool readSequence(osg::Vec4f& value); |
|---|
| 222 | bool readSequence(osg::Vec2d& value); |
|---|
| 223 | bool readSequence(osg::Vec3d& value); |
|---|
| 224 | bool readSequence(osg::Vec4d& value); |
|---|
| 225 | |
|---|
| 226 | private: |
|---|
| 227 | |
|---|
| 228 | void _init(); |
|---|
| 229 | void _free(); |
|---|
| 230 | void _copy(const FieldReaderIterator& ic); |
|---|
| 231 | |
|---|
| 232 | FieldReader _reader; |
|---|
| 233 | |
|---|
| 234 | Field _blank; |
|---|
| 235 | |
|---|
| 236 | Field* _previousField; |
|---|
| 237 | |
|---|
| 238 | Field** _fieldQueue; |
|---|
| 239 | int _fieldQueueSize; |
|---|
| 240 | int _fieldQueueCapacity; |
|---|
| 241 | |
|---|
| 242 | }; |
|---|
| 243 | |
|---|
| 244 | /** deprecated. */ |
|---|
| 245 | class OSGDB_EXPORT Input : public FieldReaderIterator |
|---|
| 246 | { |
|---|
| 247 | public: |
|---|
| 248 | |
|---|
| 249 | Input(); |
|---|
| 250 | virtual ~Input(); |
|---|
| 251 | |
|---|
| 252 | void setOptions(const Options* options) { _options = options; } |
|---|
| 253 | const Options* getOptions() const { return _options.get(); } |
|---|
| 254 | |
|---|
| 255 | virtual osg::Object* readObjectOfType(const osg::Object& compObj); |
|---|
| 256 | virtual osg::Object* readObjectOfType(const basic_type_wrapper &btw); |
|---|
| 257 | |
|---|
| 258 | virtual osg::Object* readObject(); |
|---|
| 259 | virtual osg::Image* readImage(); |
|---|
| 260 | virtual osg::Drawable* readDrawable(); |
|---|
| 261 | virtual osg::StateAttribute* readStateAttribute(); |
|---|
| 262 | virtual osg::Uniform* readUniform(); |
|---|
| 263 | virtual osg::Node* readNode(); |
|---|
| 264 | virtual osg::Shader* readShader(); |
|---|
| 265 | |
|---|
| 266 | virtual osg::Object* readObject(const std::string& fileName); |
|---|
| 267 | virtual osg::Image* readImage(const std::string& fileName); |
|---|
| 268 | virtual osg::Node* readNode(const std::string& fileName); |
|---|
| 269 | virtual osg::Shader* readShader(const std::string& fileName); |
|---|
| 270 | |
|---|
| 271 | virtual osg::Object* getObjectForUniqueID(const std::string& uniqueID); |
|---|
| 272 | virtual void registerUniqueIDForObject(const std::string& uniqueID,osg::Object* obj); |
|---|
| 273 | |
|---|
| 274 | typedef osg::ArgumentParser::Parameter Parameter; |
|---|
| 275 | |
|---|
| 276 | bool read(Parameter value1); |
|---|
| 277 | bool read(Parameter value1, Parameter value2); |
|---|
| 278 | bool read(Parameter value1, Parameter value2, Parameter value3); |
|---|
| 279 | bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4); |
|---|
| 280 | bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); |
|---|
| 281 | bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); |
|---|
| 282 | bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); |
|---|
| 283 | bool read(Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); |
|---|
| 284 | |
|---|
| 285 | bool read(const char* str); |
|---|
| 286 | bool read(const char* str, Parameter value1); |
|---|
| 287 | bool read(const char* str, Parameter value1, Parameter value2); |
|---|
| 288 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3); |
|---|
| 289 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); |
|---|
| 290 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); |
|---|
| 291 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); |
|---|
| 292 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); |
|---|
| 293 | bool read(const char* str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); |
|---|
| 294 | |
|---|
| 295 | private: |
|---|
| 296 | |
|---|
| 297 | typedef std::map< std::string, osg::ref_ptr<osg::Object> > UniqueIDToObjectMapping; |
|---|
| 298 | UniqueIDToObjectMapping _uniqueIDToObjectMap; |
|---|
| 299 | |
|---|
| 300 | osg::ref_ptr<const Options> _options; |
|---|
| 301 | |
|---|
| 302 | }; |
|---|
| 303 | |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | #endif // __SG_INPUT_H |
|---|