summary refs log tree commit diff stats
path: root/lib/selrestr.h
blob: 9f82e3e09bcd3b976c29910df91a6a9985df55fd (plain) (blame)
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
#ifndef SELRESTR_H_50652FB7
#define SELRESTR_H_50652FB7

#include <list>
#include <string>
#include "../vendor/json/json.hpp"

namespace verbly {
  
  class selrestr {
  public:
    enum class type {
      empty,
      singleton,
      group
    };
    
    // Construct from json
    
    explicit selrestr(nlohmann::json json);
    
    // Copy and move constructors
    
    selrestr(const selrestr& other);
    selrestr(selrestr&& other);
    
    // Assignment
    
    selrestr& operator=(selrestr other);
    
    // Swap
    
    friend void swap(selrestr& first, selrestr& second);
    
    // Destructor
    
    ~selrestr();
    
    // Generic accessors
    
    type getType() const
    {
      return type_;
    }
    
    // Empty
    
    selrestr();
    
    // Singleton
    
    selrestr(std::string restriction, bool pos);
    
    std::string getRestriction() const;
    
    bool getPos() const;
    
    // Group
    
    selrestr(std::list<selrestr> children, bool orlogic);
    
    std::list<selrestr> getChildren() const;
    
    std::list<selrestr>::const_iterator begin() const;
    
    std::list<selrestr>::const_iterator end() const;
    
    bool getOrlogic() const;
    
    // Helpers
    
    nlohmann::json toJson() const;
    
  private:
    union {
      struct {
        bool pos;
        std::string restriction;
      } singleton_;
      struct {
        std::list<selrestr> children;
        bool orlogic;
      } group_;
    };
    type type_;
  };

};

#endif /* end of include guard: SELRESTR_H_50652FB7 */