kodi
BooleanLogic.h
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 #pragma once
10 
11 #include "utils/IXmlDeserializable.h"
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 typedef enum {
18  BooleanLogicOperationOr = 0,
19  BooleanLogicOperationAnd
20 } BooleanLogicOperation;
21 
23 {
24 public:
25  CBooleanLogicValue(const std::string &value = "", bool negated = false)
26  : m_value(value), m_negated(negated)
27  { }
28  ~CBooleanLogicValue() override = default;
29 
30  bool Deserialize(const TiXmlNode *node) override;
31 
32  virtual const std::string& GetValue() const { return m_value; }
33  virtual bool IsNegated() const { return m_negated; }
34  virtual const char* GetTag() const { return "value"; }
35 
36  virtual void SetValue(const std::string &value) { m_value = value; }
37  virtual void SetNegated(bool negated) { m_negated = negated; }
38 
39 protected:
40  std::string m_value;
41  bool m_negated;
42 };
43 
44 typedef std::shared_ptr<CBooleanLogicValue> CBooleanLogicValuePtr;
45 typedef std::vector<CBooleanLogicValuePtr> CBooleanLogicValues;
46 
48 typedef std::shared_ptr<CBooleanLogicOperation> CBooleanLogicOperationPtr;
49 typedef std::vector<CBooleanLogicOperationPtr> CBooleanLogicOperations;
50 
52 {
53 public:
54  explicit CBooleanLogicOperation(BooleanLogicOperation op = BooleanLogicOperationAnd)
55  : m_operation(op)
56  { }
57  ~CBooleanLogicOperation() override = default;
58 
59  bool Deserialize(const TiXmlNode *node) override;
60 
61  virtual BooleanLogicOperation GetOperation() const { return m_operation; }
62  virtual const CBooleanLogicOperations& GetOperations() const { return m_operations; }
63  virtual const CBooleanLogicValues& GetValues() const { return m_values; }
64 
65  virtual void SetOperation(BooleanLogicOperation op) { m_operation = op; }
66 
67 protected:
68  virtual CBooleanLogicOperation* newOperation() { return new CBooleanLogicOperation(); }
69  virtual CBooleanLogicValue* newValue() { return new CBooleanLogicValue(); }
70 
71  BooleanLogicOperation m_operation;
72  CBooleanLogicOperations m_operations;
73  CBooleanLogicValues m_values;
74 };
75 
77 {
78 protected:
79  /* make sure nobody deletes a pointer to this class */
80  ~CBooleanLogic() override = default;
81 
82 public:
83  bool Deserialize(const TiXmlNode *node) override;
84 
85  const CBooleanLogicOperationPtr& Get() const { return m_operation; }
86  CBooleanLogicOperationPtr Get() { return m_operation; }
87 
88 protected:
89  CBooleanLogicOperationPtr m_operation;
90 };
Definition: BooleanLogic.h:22
Definition: IXmlDeserializable.h:13
Definition: BooleanLogic.h:76
Definition: BooleanLogic.h:51