diff options
author | George Hazan <george.hazan@gmail.com> | 2015-01-25 17:45:10 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-01-25 17:45:10 +0000 |
commit | dac1f42ef81ac1119430fd294a6b35b0b8cd6837 (patch) | |
tree | e3b972fc4bb56a3158e57adc70df6655f6a34dcf /protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | |
parent | 357ae09c7eba86e783583566816285750933beaa (diff) |
- class KeyStream extracted to the separate module;
- xml attributes redesigned to produce efficient code;
- many small improvements
git-svn-id: http://svn.miranda-ng.org/main/trunk@11905 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp')
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | 74 |
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;
}
|