diff --git a/include/osgDB/XmlParser b/include/osgDB/XmlParser
index fc6b5bf82..012127ff3 100644
--- a/include/osgDB/XmlParser
+++ b/include/osgDB/XmlParser
@@ -66,7 +66,26 @@ class OSGDB_EXPORT XmlNode : public osg::Referenced
public:
- class OSGDB_EXPORT Input
+ class OSGDB_EXPORT ControlMap
+ {
+ public:
+ ControlMap();
+
+ typedef std::map< std::string, int > ControlToCharacterMap;
+ typedef std::map< int, std::string> CharacterToControlMap;
+
+ void addControlToCharacter(const std::string& control, int c);
+
+ ControlToCharacterMap _controlToCharacterMap;
+ CharacterToControlMap _characterToControlMap;
+
+ private:
+
+ void setUpControlMappings();
+
+ };
+
+ class OSGDB_EXPORT Input : public ControlMap
{
public:
@@ -110,19 +129,8 @@ class OSGDB_EXPORT XmlNode : public osg::Referenced
bool match(const std::string& str) { return (_currentPos<_buffer.size()) ? _buffer.compare(_currentPos, str.size(), str)==0 : false; }
-
- typedef std::map< std::string, int > ControlToCharacterMap;
- typedef std::map< int, std::string> CharacterToControlMap;
-
- void addControlToCharacter(const std::string& control, int c);
-
- ControlToCharacterMap _controlToCharacterMap;
- CharacterToControlMap _characterToControlMap;
-
private:
- void setUpControlMappings();
-
size_type _currentPos;
std::ifstream _fin;
@@ -131,14 +139,15 @@ class OSGDB_EXPORT XmlNode : public osg::Referenced
};
bool read(Input& input);
-
bool write(std::ostream& fout, const std::string& indent = "") const;
- bool writeString(std::ostream& fout, const std::string& str) const;
+
+ bool write(const ControlMap& controlMap, std::ostream& fout, const std::string& indent = "") const;
+ bool writeString(const ControlMap& controlMap, std::ostream& fout, const std::string& str) const;
protected:
- bool writeChildren(std::ostream& fout, const std::string& indent) const;
- bool writeProperties(std::ostream& fout) const;
+ bool writeChildren(const ControlMap& controlMap, std::ostream& fout, const std::string& indent) const;
+ bool writeProperties(const ControlMap& controlMap, std::ostream& fout) const;
};
}
diff --git a/src/osgDB/XmlParser.cpp b/src/osgDB/XmlParser.cpp
index ebad4413f..5b87c2ec7 100644
--- a/src/osgDB/XmlParser.cpp
+++ b/src/osgDB/XmlParser.cpp
@@ -77,24 +77,18 @@ XmlNode* osgDB::readXmlStream(std::istream& fin)
return root.release();
}
-
-XmlNode::Input::Input():
- _currentPos(0)
+XmlNode::ControlMap::ControlMap()
{
setUpControlMappings();
}
-XmlNode::Input::Input(const Input&):
- _currentPos(0)
+void XmlNode::ControlMap::addControlToCharacter(const std::string& control, int c)
{
- setUpControlMappings();
+ _controlToCharacterMap[control] = c;
+ _characterToControlMap[c] = control;
}
-XmlNode::Input::~Input()
-{
-}
-
-void XmlNode::Input::setUpControlMappings()
+void XmlNode::ControlMap::setUpControlMappings()
{
addControlToCharacter("&",'&');
addControlToCharacter("<",'<');
@@ -103,12 +97,20 @@ void XmlNode::Input::setUpControlMappings()
addControlToCharacter("'",'\'');
}
-void XmlNode::Input::addControlToCharacter(const std::string& control, int c)
+XmlNode::Input::Input():
+ _currentPos(0)
{
- _controlToCharacterMap[control] = c;
- _characterToControlMap[c] = control;
}
+XmlNode::Input::Input(const Input&):
+ ControlMap(),
+ _currentPos(0)
+{
+}
+
+XmlNode::Input::~Input()
+{
+}
void XmlNode::Input::open(const std::string& filename)
{
_fin.open(filename.c_str());
@@ -362,31 +364,42 @@ bool XmlNode::read(Input& input)
}
bool XmlNode::write(std::ostream& fout, const std::string& indent) const
+{
+ ControlMap controlMap;
+ return write(controlMap, fout, indent);
+}
+
+bool XmlNode::write(const ControlMap& controlMap, std::ostream& fout, const std::string& indent) const
{
switch(type)
{
case(UNASSIGNED):
+ OSG_NOTICE<<"UNASSIGNED"<"<"; writeString(controlMap, fout, contents); fout<<""<"<"<"<second;
+ else fout.put(c);
+ }
return true;
}
-bool XmlNode::writeChildren(std::ostream& fout, const std::string& indent) const
+bool XmlNode::writeChildren(const ControlMap& controlMap, std::ostream& fout, const std::string& indent) const
{
for(Children::const_iterator citr = children.begin();
citr != children.end();
@@ -424,14 +445,14 @@ bool XmlNode::writeChildren(std::ostream& fout, const std::string& indent) const
return true;
}
-bool XmlNode::writeProperties(std::ostream& fout) const
+bool XmlNode::writeProperties(const ControlMap& controlMap, std::ostream& fout) const
{
for(Properties::const_iterator oitr = properties.begin();
oitr != properties.end();
++oitr)
{
fout<<" "<first<<"=\"";
- if (!writeString(fout,oitr->second))
+ if (!writeString(controlMap,fout,oitr->second))
return false;
fout<<"\"";
}