14#ifndef OSGDB_XML_PARSER
15#define OSGDB_XML_PARSER 1
57 typedef std::vector< osg::ref_ptr<XmlNode> >
Children;
84 void setUpControlMappings();
99 void open(
const std::string& filename);
104 operator bool ()
const {
return _currentPos<_buffer.size(); }
108 int get() {
if (_currentPos<_buffer.size())
return static_cast<unsigned char>(_buffer[_currentPos++]);
else return -1; }
110 int operator [] (
size_type i)
const {
if ((_currentPos+i)<_buffer.size())
return static_cast<unsigned char>(_buffer[_currentPos+i]);
else return -1; }
112 void operator ++ () {
if (_currentPos<_buffer.size()) ++_currentPos; }
114 void operator += (
size_type n) {
if ((_currentPos+n)<_buffer.size()) _currentPos+=n;
else _currentPos = _buffer.size(); }
118 std::string
substr(
size_type pos,
size_type n=std::string::npos) {
return (_currentPos<_buffer.size()) ? _buffer.substr(_currentPos+pos,n) : std::string(); }
122 if (_currentPos<_buffer.size())
124 size_type pos = _buffer.find(str, _currentPos);
125 if (pos==std::string::npos)
return std::string::npos;
126 else return pos-_currentPos;
127 }
else return std::string::npos;
130 bool match(
const std::string& str) {
return (_currentPos<_buffer.size()) ? _buffer.compare(_currentPos, str.size(), str)==0 :
false; }
143 if (_currentPos>=_buffer.size())
return;
148 int char0 =
static_cast<unsigned char>(_buffer[_currentPos]); ++_currentPos;
149 str.push_back(char0);
151 if (char0 < 0x80 || _currentPos>=_buffer.size())
break;
153 str.push_back(_buffer[_currentPos]); ++_currentPos;
154 if (char0<0xe0 || _currentPos<_buffer.size())
break;
156 str.push_back(_buffer[_currentPos]); ++_currentPos;
157 if (char0<0xf0 || _currentPos>=_buffer.size())
break;
159 str.push_back(_buffer[_currentPos]); ++_currentPos;
160 if (char0<0xf8 || _currentPos>=_buffer.size())
break;
162 if (_currentPos>=_buffer.size())
break;
163 str.push_back(_buffer[_currentPos]); ++_currentPos;
169 str.push_back(_buffer[_currentPos]);
177 size_type _currentPos;
186 bool write(std::ostream& fout,
const std::string& indent =
"")
const;
188 bool write(
const ControlMap& controlMap, std::ostream& fout,
const std::string& indent =
"")
const;
The osgDB library provides support for reading and writing scene graphs, providing a plugin framework...
Definition Archive:24
OSGDB_EXPORT XmlNode * readXmlFile(const std::string &filename, const Options *options)
read an Xml file, find the file in Options DataFilePathList.
OSGDB_EXPORT XmlNode * readXmlStream(std::istream &fin)
read an Xml from from an istream.
OSGDB_EXPORT std::string trimEnclosingSpaces(const std::string &str)
Base class for providing reference counted objects.
Definition Referenced:44
Options base class used for passing options into plugins to control their operation.
Definition Options:30
static Registry * instance(bool erase=false)
XmlNode class for very basic reading and writing of xml files.
Definition XmlParser:40
NodeType type
Definition XmlParser:59
bool writeProperties(const ControlMap &controlMap, std::ostream &fout) const
bool writeChildren(const ControlMap &controlMap, std::ostream &fout, const std::string &indent) const
std::string contents
Definition XmlParser:61
bool write(const ControlMap &controlMap, std::ostream &fout, const std::string &indent="") const
NodeType
Definition XmlParser:46
@ GROUP
Definition XmlParser:50
@ ATOM
Definition XmlParser:48
@ ROOT
Definition XmlParser:51
@ UNASSIGNED
Definition XmlParser:47
@ COMMENT
Definition XmlParser:52
@ NODE
Definition XmlParser:49
@ INFORMATION
Definition XmlParser:53
bool readAndReplaceControl(std::string &in_contents, Input &input) const
bool write(std::ostream &fout, const std::string &indent="") const
std::vector< osg::ref_ptr< XmlNode > > Children
Definition XmlParser:57
std::string name
Definition XmlParser:60
bool writeString(const ControlMap &controlMap, std::ostream &fout, const std::string &str) const
std::map< std::string, std::string > Properties
Definition XmlParser:56
std::string getTrimmedContents() const
Definition XmlParser:65
Properties properties
Definition XmlParser:62
Children children
Definition XmlParser:63
void addControlToCharacter(const std::string &control, int c)
ControlToCharacterMap _controlToCharacterMap
Definition XmlParser:79
std::map< int, std::string > CharacterToControlMap
Definition XmlParser:75
CharacterToControlMap _characterToControlMap
Definition XmlParser:80
std::map< std::string, int > ControlToCharacterMap
Definition XmlParser:74
void open(const std::string &filename)
void attach(std::istream &istream)
Encoding getEncoding() const
Definition XmlParser:139
bool match(const std::string &str)
Definition XmlParser:130
void setEncoding(Encoding encoding)
Definition XmlParser:138
void readAllDataIntoBuffer()
size_type find(const std::string &str)
Definition XmlParser:120
Encoding
Definition XmlParser:133
@ ENCODING_ASCII
Definition XmlParser:134
@ ENCODING_UTF8
Definition XmlParser:135
int get()
Definition XmlParser:108
size_type currentPosition() const
Definition XmlParser:106
std::string::size_type size_type
Definition XmlParser:97
std::string substr(size_type pos, size_type n=std::string::npos)
Definition XmlParser:118
void copyCharacterToString(std::string &str)
Definition XmlParser:141
#define OSGDB_EXPORT
Definition Export:39