summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/BooleanLogic.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/BooleanLogic.cpp
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/BooleanLogic.cpp')
-rw-r--r--xbmc/utils/BooleanLogic.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/xbmc/utils/BooleanLogic.cpp b/xbmc/utils/BooleanLogic.cpp
new file mode 100644
index 0000000..c6be261
--- /dev/null
+++ b/xbmc/utils/BooleanLogic.cpp
@@ -0,0 +1,122 @@
1/*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#include "BooleanLogic.h"
10
11#include "utils/StringUtils.h"
12#include "utils/XBMCTinyXML.h"
13#include "utils/log.h"
14
15bool CBooleanLogicValue::Deserialize(const TiXmlNode *node)
16{
17 if (node == NULL)
18 return false;
19
20 const TiXmlElement *elem = node->ToElement();
21 if (elem == NULL)
22 return false;
23
24 if (node->FirstChild() != NULL && node->FirstChild()->Type() == TiXmlNode::TINYXML_TEXT)
25 m_value = node->FirstChild()->ValueStr();
26
27 m_negated = false;
28 const char *strNegated = elem->Attribute("negated");
29 if (strNegated != NULL)
30 {
31 if (StringUtils::EqualsNoCase(strNegated, "true"))
32 m_negated = true;
33 else if (!StringUtils::EqualsNoCase(strNegated, "false"))
34 {
35 CLog::Log(LOGDEBUG, "CBooleanLogicValue: invalid negated value \"%s\"", strNegated);
36 return false;
37 }
38 }
39
40 return true;
41}
42
43bool CBooleanLogicOperation::Deserialize(const TiXmlNode *node)
44{
45 if (node == NULL)
46 return false;
47
48 // check if this is a simple operation with a single value directly expressed
49 // in the parent tag
50 if (node->FirstChild() == NULL || node->FirstChild()->Type() == TiXmlNode::TINYXML_TEXT)
51 {
52 CBooleanLogicValuePtr value = CBooleanLogicValuePtr(newValue());
53 if (value == NULL || !value->Deserialize(node))
54 {
55 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize implicit boolean value definition");
56 return false;
57 }
58
59 m_values.push_back(value);
60 return true;
61 }
62
63 const TiXmlNode *operationNode = node->FirstChild();
64 while (operationNode != NULL)
65 {
66 std::string tag = operationNode->ValueStr();
67 if (StringUtils::EqualsNoCase(tag, "and") || StringUtils::EqualsNoCase(tag, "or"))
68 {
69 CBooleanLogicOperationPtr operation = CBooleanLogicOperationPtr(newOperation());
70 if (operation == NULL)
71 return false;
72
73 operation->SetOperation(StringUtils::EqualsNoCase(tag, "and") ? BooleanLogicOperationAnd : BooleanLogicOperationOr);
74 if (!operation->Deserialize(operationNode))
75 {
76 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize <%s> definition", tag.c_str());
77 return false;
78 }
79
80 m_operations.push_back(operation);
81 }
82 else
83 {
84 CBooleanLogicValuePtr value = CBooleanLogicValuePtr(newValue());
85 if (value == NULL)
86 return false;
87
88 if (StringUtils::EqualsNoCase(tag, value->GetTag()))
89 {
90 if (!value->Deserialize(operationNode))
91 {
92 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize <%s> definition", tag.c_str());
93 return false;
94 }
95
96 m_values.push_back(value);
97 }
98 else if (operationNode->Type() == TiXmlNode::TINYXML_ELEMENT)
99 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: unknown <%s> definition encountered", tag.c_str());
100 }
101
102 operationNode = operationNode->NextSibling();
103 }
104
105 return true;
106}
107
108bool CBooleanLogic::Deserialize(const TiXmlNode *node)
109{
110 if (node == NULL)
111 return false;
112
113 if (m_operation == NULL)
114 {
115 m_operation = CBooleanLogicOperationPtr(new CBooleanLogicOperation());
116
117 if (m_operation == NULL)
118 return false;
119 }
120
121 return m_operation->Deserialize(node);
122}