Cleanup XML read & write utility functions

This commit is contained in:
Bruno
2021-04-25 00:26:05 +02:00
parent f643e80de7
commit c3a24a6d7f
6 changed files with 35 additions and 37 deletions

View File

@@ -508,23 +508,23 @@ void SessionLoader::applyImageProcessing(const Source &s, const std::string &cli
//// s.processingShader()->accept(loader);
//}
void SessionLoader::XMLToNode(tinyxml2::XMLElement *xml, Node &n)
void SessionLoader::XMLToNode(const tinyxml2::XMLElement *xml, Node &n)
{
if (xml != nullptr){
XMLElement *node = xml->FirstChildElement("Node");
const XMLElement *node = xml->FirstChildElement("Node");
if ( !node || std::string(node->Name()).find("Node") == std::string::npos )
return;
XMLElement *scaleNode = node->FirstChildElement("scale");
const XMLElement *scaleNode = node->FirstChildElement("scale");
if (scaleNode)
tinyxml2::XMLElementToGLM( scaleNode->FirstChildElement("vec3"), n.scale_);
XMLElement *translationNode = node->FirstChildElement("translation");
const XMLElement *translationNode = node->FirstChildElement("translation");
if (translationNode)
tinyxml2::XMLElementToGLM( translationNode->FirstChildElement("vec3"), n.translation_);
XMLElement *rotationNode = node->FirstChildElement("rotation");
const XMLElement *rotationNode = node->FirstChildElement("rotation");
if (rotationNode)
tinyxml2::XMLElementToGLM( rotationNode->FirstChildElement("vec3"), n.rotation_);
XMLElement *cropNode = node->FirstChildElement("crop");
const XMLElement *cropNode = node->FirstChildElement("crop");
if (cropNode)
tinyxml2::XMLElementToGLM( cropNode->FirstChildElement("vec3"), n.crop_);
}
@@ -544,20 +544,20 @@ void SessionLoader::XMLToSourcecore( tinyxml2::XMLElement *xml, SourceCore &s)
}
FrameBufferImage *SessionLoader::XMLToImage(tinyxml2::XMLElement *xml)
FrameBufferImage *SessionLoader::XMLToImage(const XMLElement *xml)
{
FrameBufferImage *i = nullptr;
if (xml != nullptr){
// if there is an Image mask stored
XMLElement* imageNode = xml->FirstChildElement("Image");
const XMLElement* imageNode = xml->FirstChildElement("Image");
if (imageNode) {
// get theoretical image size
int w = 0, h = 0;
imageNode->QueryIntAttribute("width", &w);
imageNode->QueryIntAttribute("height", &h);
// if there is an internal array of data
XMLElement* array = imageNode->FirstChildElement("array");
const XMLElement* array = imageNode->FirstChildElement("array");
if (array) {
// create a temporary jpeg with size of the array
FrameBufferImage::jpegBuffer jpgimg;

View File

@@ -58,9 +58,9 @@ public:
void visit (DeviceSource& s) override;
void visit (NetworkSource& s) override;
static void XMLToNode(tinyxml2::XMLElement *xml, Node &n);
static void XMLToNode(const tinyxml2::XMLElement *xml, Node &n);
static void XMLToSourcecore(tinyxml2::XMLElement *xml, SourceCore &s);
static FrameBufferImage *XMLToImage(tinyxml2::XMLElement *xml);
static FrameBufferImage *XMLToImage(const tinyxml2::XMLElement *xml);
protected:
// result created session
@@ -90,7 +90,6 @@ public:
void load(const std::string& filename);
static std::string info(const std::string& filename);
// static std::string thumbnail(const std::string& filename);
};
#endif // SESSIONCREATOR_H

View File

@@ -127,7 +127,7 @@ SessionVisitor::SessionVisitor(tinyxml2::XMLDocument *doc,
xmlDoc_ = doc;
}
XMLElement *SessionVisitor::NodeToXML(Node &n, XMLDocument *doc)
XMLElement *SessionVisitor::NodeToXML(const Node &n, XMLDocument *doc)
{
XMLElement *newelement = doc->NewElement("Node");
newelement->SetAttribute("visible", n.visible_);
@@ -153,7 +153,7 @@ XMLElement *SessionVisitor::NodeToXML(Node &n, XMLDocument *doc)
}
XMLElement *SessionVisitor::ImageToXML(FrameBufferImage *img, XMLDocument *doc)
XMLElement *SessionVisitor::ImageToXML(const FrameBufferImage *img, XMLDocument *doc)
{
XMLElement *imageelement = nullptr;
if (img != nullptr) {
@@ -590,7 +590,7 @@ void SessionVisitor::visit (MixingGroup& g)
}
}
std::string SessionVisitor::getClipboard(SourceList list)
std::string SessionVisitor::getClipboard(const SourceList &list)
{
std::string x = "";
@@ -627,7 +627,7 @@ std::string SessionVisitor::getClipboard(SourceList list)
return x;
}
std::string SessionVisitor::getClipboard(Source *s)
std::string SessionVisitor::getClipboard(Source * const s)
{
std::string x = "";
@@ -651,7 +651,7 @@ std::string SessionVisitor::getClipboard(Source *s)
return x;
}
std::string SessionVisitor::getClipboard(ImageProcessingShader *s)
std::string SessionVisitor::getClipboard(ImageProcessingShader * const s)
{
std::string x = "";

View File

@@ -23,9 +23,9 @@ public:
static bool saveSession(const std::string& filename, Session *session);
static std::string getClipboard(SourceList list);
static std::string getClipboard(Source *s);
static std::string getClipboard(ImageProcessingShader *s);
static std::string getClipboard(const SourceList &list);
static std::string getClipboard(Source * const s);
static std::string getClipboard(ImageProcessingShader * const s);
// Elements of Scene
void visit(Scene& n) override;
@@ -61,9 +61,8 @@ public:
void visit (NetworkSource& s) override;
void visit (MixingGroup& s) override;
protected:
static tinyxml2::XMLElement *NodeToXML(Node &n, tinyxml2::XMLDocument *doc);
static tinyxml2::XMLElement *ImageToXML(FrameBufferImage *img, tinyxml2::XMLDocument *doc);
static tinyxml2::XMLElement *NodeToXML(const Node &n, tinyxml2::XMLDocument *doc);
static tinyxml2::XMLElement *ImageToXML(const FrameBufferImage *img, tinyxml2::XMLDocument *doc);
};
#endif // XMLVISITOR_H

View File

@@ -62,7 +62,7 @@ XMLElement *tinyxml2::XMLElementFromGLM(XMLDocument *doc, glm::mat4 matrix)
return newelement;
}
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::ivec2 &vector)
void tinyxml2::XMLElementToGLM(const XMLElement *elem, glm::ivec2 &vector)
{
if ( !elem || std::string(elem->Name()).find("ivec2") == std::string::npos )
return;
@@ -70,7 +70,7 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::ivec2 &vector)
elem->QueryIntAttribute("y", &vector.y);
}
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec2 &vector)
void tinyxml2::XMLElementToGLM(const XMLElement *elem, glm::vec2 &vector)
{
if ( !elem || std::string(elem->Name()).find("vec2") == std::string::npos )
return;
@@ -78,7 +78,7 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec2 &vector)
elem->QueryFloatAttribute("y", &vector.y);
}
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec3 &vector)
void tinyxml2::XMLElementToGLM(const XMLElement *elem, glm::vec3 &vector)
{
if ( !elem || std::string(elem->Name()).find("vec3") == std::string::npos )
return;
@@ -87,7 +87,7 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec3 &vector)
elem->QueryFloatAttribute("z", &vector.z);
}
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec4 &vector)
void tinyxml2::XMLElementToGLM(const XMLElement *elem, glm::vec4 &vector)
{
if ( !elem || std::string(elem->Name()).find("vec4") == std::string::npos )
return;
@@ -97,13 +97,13 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec4 &vector)
elem->QueryFloatAttribute("w", &vector.w);
}
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::mat4 &matrix)
void tinyxml2::XMLElementToGLM(const XMLElement *elem, glm::mat4 &matrix)
{
if ( !elem || std::string(elem->Name()).find("mat4") == std::string::npos )
return;
// loop over rows of vec4
XMLElement* row = elem->FirstChildElement("vec4");
const XMLElement* row = elem->FirstChildElement("vec4");
for( ; row ; row = row->NextSiblingElement())
{
int r = 0;
@@ -157,7 +157,7 @@ XMLElement *tinyxml2::XMLElementEncodeArray(XMLDocument *doc, const void *array,
return newelement;
}
bool tinyxml2::XMLElementDecodeArray(XMLElement *elem, void *array, uint arraysize)
bool tinyxml2::XMLElementDecodeArray(const XMLElement *elem, void *array, uint arraysize)
{
bool ret = false;

View File

@@ -19,14 +19,14 @@ XMLElement *XMLElementFromGLM(XMLDocument *doc, glm::vec3 vector);
XMLElement *XMLElementFromGLM(XMLDocument *doc, glm::vec4 vector);
XMLElement *XMLElementFromGLM(XMLDocument *doc, glm::mat4 matrix);
void XMLElementToGLM(XMLElement *elem, glm::ivec2 &vector);
void XMLElementToGLM(XMLElement *elem, glm::vec2 &vector);
void XMLElementToGLM(XMLElement *elem, glm::vec3 &vector);
void XMLElementToGLM(XMLElement *elem, glm::vec4 &vector);
void XMLElementToGLM(XMLElement *elem, glm::mat4 &matrix);
void XMLElementToGLM(const XMLElement *elem, glm::ivec2 &vector);
void XMLElementToGLM(const XMLElement *elem, glm::vec2 &vector);
void XMLElementToGLM(const XMLElement *elem, glm::vec3 &vector);
void XMLElementToGLM(const XMLElement *elem, glm::vec4 &vector);
void XMLElementToGLM(const XMLElement *elem, glm::mat4 &matrix);
XMLElement *XMLElementEncodeArray(XMLDocument *doc, const void *array, uint arraysize);
bool XMLElementDecodeArray(XMLElement *elem, void *array, uint arraysize);
bool XMLElementDecodeArray(const tinyxml2::XMLElement *elem, void *array, uint arraysize);
bool XMLSaveDoc(tinyxml2::XMLDocument * const doc, std::string filename);
bool XMLResultError(int result, bool verbose = true);