[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / utils / BooleanLogic.cpp
blob7ccc54750cadbe36a9ce8dae37611eceb3529017
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "BooleanLogic.h"
11 #include "utils/StringUtils.h"
12 #include "utils/XBMCTinyXML.h"
13 #include "utils/log.h"
15 bool CBooleanLogicValue::Deserialize(const TiXmlNode *node)
17 if (node == NULL)
18 return false;
20 const TiXmlElement *elem = node->ToElement();
21 if (elem == NULL)
22 return false;
24 if (node->FirstChild() != NULL && node->FirstChild()->Type() == TiXmlNode::TINYXML_TEXT)
25 m_value = node->FirstChild()->ValueStr();
27 m_negated = false;
28 const char *strNegated = elem->Attribute("negated");
29 if (strNegated != NULL)
31 if (StringUtils::EqualsNoCase(strNegated, "true"))
32 m_negated = true;
33 else if (!StringUtils::EqualsNoCase(strNegated, "false"))
35 CLog::Log(LOGDEBUG, "CBooleanLogicValue: invalid negated value \"{}\"", strNegated);
36 return false;
40 return true;
43 bool CBooleanLogicOperation::Deserialize(const TiXmlNode *node)
45 if (node == NULL)
46 return false;
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)
52 CBooleanLogicValuePtr value = CBooleanLogicValuePtr(newValue());
53 if (value == NULL || !value->Deserialize(node))
55 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize implicit boolean value definition");
56 return false;
59 m_values.push_back(value);
60 return true;
63 const TiXmlNode *operationNode = node->FirstChild();
64 while (operationNode != NULL)
66 std::string tag = operationNode->ValueStr();
67 if (StringUtils::EqualsNoCase(tag, "and") || StringUtils::EqualsNoCase(tag, "or"))
69 CBooleanLogicOperationPtr operation = CBooleanLogicOperationPtr(newOperation());
70 if (operation == NULL)
71 return false;
73 operation->SetOperation(StringUtils::EqualsNoCase(tag, "and") ? BooleanLogicOperationAnd : BooleanLogicOperationOr);
74 if (!operation->Deserialize(operationNode))
76 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize <{}> definition", tag);
77 return false;
80 m_operations.push_back(operation);
82 else
84 CBooleanLogicValuePtr value = CBooleanLogicValuePtr(newValue());
85 if (value == NULL)
86 return false;
88 if (StringUtils::EqualsNoCase(tag, value->GetTag()))
90 if (!value->Deserialize(operationNode))
92 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: failed to deserialize <{}> definition", tag);
93 return false;
96 m_values.push_back(value);
98 else if (operationNode->Type() == TiXmlNode::TINYXML_ELEMENT)
99 CLog::Log(LOGDEBUG, "CBooleanLogicOperation: unknown <{}> definition encountered", tag);
102 operationNode = operationNode->NextSibling();
105 return true;
108 bool CBooleanLogic::Deserialize(const TiXmlNode *node)
110 if (node == NULL)
111 return false;
113 if (m_operation == NULL)
115 m_operation = CBooleanLogicOperationPtr(new CBooleanLogicOperation());
117 if (m_operation == NULL)
118 return false;
121 return m_operation->Deserialize(node);