2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#ifndef OSGDB_FIELD
|
|
|
|
#define OSGDB_FIELD 1
|
|
|
|
|
|
|
|
#include <osgDB/Export>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
namespace osgDB {
|
|
|
|
|
|
|
|
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,
|
2003-03-13 14:22:31 +08:00
|
|
|
UNINITIALISED
|
2001-09-20 05:08:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2003-02-13 03:20:47 +08:00
|
|
|
bool matchUInt(unsigned int i) const;
|
|
|
|
bool getUInt(unsigned int& i) const;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
bool isFloat() const;
|
|
|
|
bool matchFloat(float f) const;
|
|
|
|
bool getFloat(float& f) const;
|
2003-09-29 21:35:02 +08:00
|
|
|
bool getFloat(double& f) const;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
#endif // __SG_FIELD_H
|