summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/BooleanLogic.h
blob: 03551345fabd2a0c28e66ddc67c7ea123ba586ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 *  Copyright (C) 2012-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "utils/IXmlDeserializable.h"

#include <memory>
#include <string>
#include <vector>

typedef enum {
  BooleanLogicOperationOr = 0,
  BooleanLogicOperationAnd
} BooleanLogicOperation;

class CBooleanLogicValue : public IXmlDeserializable
{
public:
  CBooleanLogicValue(const std::string &value = "", bool negated = false)
    : m_value(value), m_negated(negated)
  { }
  ~CBooleanLogicValue() override = default;

  bool Deserialize(const TiXmlNode *node) override;

  virtual const std::string& GetValue() const { return m_value; }
  virtual bool IsNegated() const { return m_negated; }
  virtual const char* GetTag() const { return "value"; }

  virtual void SetValue(const std::string &value) { m_value = value; }
  virtual void SetNegated(bool negated) { m_negated = negated; }

protected:
  std::string m_value;
  bool m_negated;
};

typedef std::shared_ptr<CBooleanLogicValue> CBooleanLogicValuePtr;
typedef std::vector<CBooleanLogicValuePtr> CBooleanLogicValues;

class CBooleanLogicOperation;
typedef std::shared_ptr<CBooleanLogicOperation> CBooleanLogicOperationPtr;
typedef std::vector<CBooleanLogicOperationPtr> CBooleanLogicOperations;

class CBooleanLogicOperation : public IXmlDeserializable
{
public:
  explicit CBooleanLogicOperation(BooleanLogicOperation op = BooleanLogicOperationAnd)
    : m_operation(op)
  { }
  ~CBooleanLogicOperation() override = default;

  bool Deserialize(const TiXmlNode *node) override;

  virtual BooleanLogicOperation GetOperation() const { return m_operation; }
  virtual const CBooleanLogicOperations& GetOperations() const { return m_operations; }
  virtual const CBooleanLogicValues& GetValues() const { return m_values; }

  virtual void SetOperation(BooleanLogicOperation op) { m_operation = op; }

protected:
  virtual CBooleanLogicOperation* newOperation() { return new CBooleanLogicOperation(); }
  virtual CBooleanLogicValue* newValue() { return new CBooleanLogicValue(); }

  BooleanLogicOperation m_operation;
  CBooleanLogicOperations m_operations;
  CBooleanLogicValues m_values;
};

class CBooleanLogic : public IXmlDeserializable
{
protected:
  /* make sure nobody deletes a pointer to this class */
  ~CBooleanLogic() override = default;

public:
  bool Deserialize(const TiXmlNode *node) override;

  const CBooleanLogicOperationPtr& Get() const { return m_operation; }
  CBooleanLogicOperationPtr Get() { return m_operation; }

protected:
  CBooleanLogicOperationPtr m_operation;
};