Merge pull request #26148 from ksooo/fix-secondstotimestring-warning
[xbmc.git] / xbmc / utils / BooleanLogic.h
blobb9da7294f6ec514c8d40216b5adca54e450e72b1
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 #pragma once
11 #include "utils/IXmlDeserializable.h"
13 #include <memory>
14 #include <string>
15 #include <vector>
17 typedef enum {
18 BooleanLogicOperationOr = 0,
19 BooleanLogicOperationAnd
20 } BooleanLogicOperation;
22 class TiXmlNode;
24 class CBooleanLogicValue : public IXmlDeserializable
26 public:
27 CBooleanLogicValue(const std::string &value = "", bool negated = false)
28 : m_value(value), m_negated(negated)
29 { }
30 ~CBooleanLogicValue() override = default;
32 bool Deserialize(const TiXmlNode *node) override;
34 virtual const std::string& GetValue() const { return m_value; }
35 virtual bool IsNegated() const { return m_negated; }
36 virtual const char* GetTag() const { return "value"; }
38 virtual void SetValue(const std::string &value) { m_value = value; }
39 virtual void SetNegated(bool negated) { m_negated = negated; }
41 protected:
42 std::string m_value;
43 bool m_negated;
46 typedef std::shared_ptr<CBooleanLogicValue> CBooleanLogicValuePtr;
47 typedef std::vector<CBooleanLogicValuePtr> CBooleanLogicValues;
49 class CBooleanLogicOperation;
50 typedef std::shared_ptr<CBooleanLogicOperation> CBooleanLogicOperationPtr;
51 typedef std::vector<CBooleanLogicOperationPtr> CBooleanLogicOperations;
53 class CBooleanLogicOperation : public IXmlDeserializable
55 public:
56 explicit CBooleanLogicOperation(BooleanLogicOperation op = BooleanLogicOperationAnd)
57 : m_operation(op)
58 { }
59 ~CBooleanLogicOperation() override = default;
61 bool Deserialize(const TiXmlNode *node) override;
63 virtual BooleanLogicOperation GetOperation() const { return m_operation; }
64 virtual const CBooleanLogicOperations& GetOperations() const { return m_operations; }
65 virtual const CBooleanLogicValues& GetValues() const { return m_values; }
67 virtual void SetOperation(BooleanLogicOperation op) { m_operation = op; }
69 protected:
70 virtual CBooleanLogicOperation* newOperation() { return new CBooleanLogicOperation(); }
71 virtual CBooleanLogicValue* newValue() { return new CBooleanLogicValue(); }
73 BooleanLogicOperation m_operation;
74 CBooleanLogicOperations m_operations;
75 CBooleanLogicValues m_values;
78 class CBooleanLogic : public IXmlDeserializable
80 protected:
81 /* make sure nobody deletes a pointer to this class */
82 ~CBooleanLogic() override = default;
84 public:
85 bool Deserialize(const TiXmlNode *node) override;
87 const CBooleanLogicOperationPtr& Get() const { return m_operation; }
88 CBooleanLogicOperationPtr Get() { return m_operation; }
90 protected:
91 CBooleanLogicOperationPtr m_operation;