summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp74
1 files changed, 62 insertions, 12 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
index 5ca7bd7f0e..5929d43b20 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
@@ -5,27 +5,32 @@
* Author: Antonio
*/
+#include "../common.h" // #TODO Remove Miranda-dependency
+
#include "WAException.h"
#include "ProtocolTreeNode.h"
static std::string nilstr;
-ProtocolTreeNode::ProtocolTreeNode(const string& tag, map<string, string> *attributes, vector<unsigned char>* data, vector<ProtocolTreeNode*> *children) {
+ProtocolTreeNode::ProtocolTreeNode(const string& tag, vector<unsigned char>* data, vector<ProtocolTreeNode*> *children)
+{
this->tag = tag;
this->data = data;
- this->attributes = attributes;
+ this->attributes = NULL;
this->children = children;
}
-ProtocolTreeNode::ProtocolTreeNode(const string& tag, map<string, string> *attributes, ProtocolTreeNode* child) {
+ProtocolTreeNode::ProtocolTreeNode(const string& tag, ProtocolTreeNode* child)
+{
this->tag = tag;
this->data = NULL;
- this->attributes = attributes;
+ this->attributes = NULL;
this->children = new std::vector<ProtocolTreeNode*>(1);
(*this->children)[0] = child;
}
-ProtocolTreeNode::~ProtocolTreeNode() {
+ProtocolTreeNode::~ProtocolTreeNode()
+{
if (this->attributes != NULL)
delete this->attributes;
if (this->children != NULL) {
@@ -39,11 +44,12 @@ ProtocolTreeNode::~ProtocolTreeNode() {
}
-string ProtocolTreeNode::toString() {
+string ProtocolTreeNode::toString()
+{
string out;
out += "<" + this->tag;
if (this->attributes != NULL) {
- map<string,string>::iterator ii;
+ map<string, string>::iterator ii;
for (ii = attributes->begin(); ii != attributes->end(); ii++)
out += "" + ii->first + "=\"" + ii->second + "\"";
}
@@ -61,7 +67,8 @@ string ProtocolTreeNode::toString() {
return out;
}
-ProtocolTreeNode* ProtocolTreeNode::getChild(const string& id) {
+ProtocolTreeNode* ProtocolTreeNode::getChild(const string& id)
+{
if (this->children == NULL || this->children->size() == 0)
return NULL;
@@ -72,7 +79,8 @@ ProtocolTreeNode* ProtocolTreeNode::getChild(const string& id) {
return NULL;
}
-ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id) {
+ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id)
+{
if (this->children == NULL || this->children->size() == 0)
return NULL;
@@ -87,7 +95,7 @@ const string& ProtocolTreeNode::getAttributeValue(const string& attribute)
if (this->attributes == NULL)
return nilstr;
- map<string,string>::iterator it = attributes->find(attribute);
+ map<string, string>::iterator it = attributes->find(attribute);
if (it == attributes->end())
return nilstr;
@@ -128,6 +136,48 @@ bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag)
void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag)
{
- if (!tagEquals(node, tag))
- throw WAException("failed require. node:" + node->toString() + "tag: " + tag, WAException::CORRUPT_STREAM_EX, 0);
+ if (!tagEquals(node, tag))
+ throw WAException("failed require. node:" + node->toString() + "tag: " + tag, WAException::CORRUPT_STREAM_EX, 0);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTR &attr)
+{
+ if (node.attributes == NULL)
+ node.attributes = new map<string, string>;
+
+ (*node.attributes)[attr.name] = attr.value;
+ return node;
+}
+
+ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTR &attr)
+{
+ if (node->attributes == NULL)
+ node->attributes = new map<string, string>;
+
+ (*node->attributes)[attr.name] = attr.value;
+ return node;
+}
+
+ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTRI &attr)
+{
+ if (node.attributes == NULL)
+ node.attributes = new map<string, string>;
+
+ char szValue[100];
+ _itoa_s(attr.value, szValue, 10);
+ (*node.attributes)[attr.name] = szValue;
+ return node;
+}
+
+ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTRI &attr)
+{
+ if (node->attributes == NULL)
+ node->attributes = new map<string, string>;
+
+ char szValue[100];
+ _itoa_s(attr.value, szValue, 10);
+ (*node->attributes)[attr.name] = szValue;
+ return node;
}