source: icGREP/icgrep-devel/icgrep/re/re_re.h @ 4199

Last change on this file since 4199 was 4199, checked in by nmedfort, 5 years ago

First stage of refactoring PabloE classes.

File size: 2.8 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef RE_H
8#define RE_H
9
10#include <vector>
11#include <assert.h>
12
13namespace re {
14
15class Vector;
16class Pair;
17
18class Alt;
19class CC;
20class Diff;
21class End;
22class Intersect;
23class Name;
24class Permute;
25class Rep;
26class Seq;
27class Start;
28class SymDiff;
29class Union;
30
31class RE {
32public:
33    enum class ClassTypeId : unsigned {
34        Alt
35        , CC
36        , Diff
37        , End
38        , Intersect
39        , Name
40        , Permute
41        , Rep
42        , Seq
43        , Start
44        , SymDiff
45        , Union
46    };
47    inline ClassTypeId getClassTypeId() const {
48        return mClassTypeId;
49    }
50    virtual RE * clone() const = 0;
51    virtual ~RE() = 0;
52protected:
53    inline RE(const ClassTypeId id)
54    : mClassTypeId(id) {
55
56    }
57    const ClassTypeId mClassTypeId;
58};
59
60template <typename To, typename From>
61inline static bool isa(const From * object) {
62    return To::classof(object);
63}
64
65template <typename To, typename From>
66inline static To * dyn_cast(From * object) {
67    if (isa<To, From>(object)) {
68        return reinterpret_cast<To *>(object);
69    }
70    return nullptr;
71}
72
73class Vector : public RE, public std::vector<RE*> {
74public:
75    virtual ~Vector() {
76        for (RE * re : *this) {
77            delete re;
78        }
79    }
80protected:
81    inline Vector(const ClassTypeId id)
82    : RE(id)
83    , std::vector<RE*>()
84    {
85
86    }
87    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
88    : RE(id)
89    , std::vector<RE*>(begin, end) {
90
91    }
92    inline Vector(const ClassTypeId id, const const_iterator begin, const const_iterator end, const bool deep_copy)
93    : RE(id) {
94        assert (deep_copy && "Not intended as a shallow copy constructor.");
95        this->resize(std::distance(begin, end));
96        for (auto i = begin; i != end; ++i) {
97            this->assign(std::distance(begin, i), (*i)->clone());
98        }
99    }
100};
101
102//class Pair : public RE {
103//protected:
104//    inline Pair(const ClassTypeId id)
105//    : RE(id)
106//    , _lh(nullptr)
107//    , _rh(nullptr)
108//    {
109
110//    }
111//    inline Pair(const ClassTypeId id, const RE * lh, const RE * rh)
112//    : RE(id)
113//    , _lh(lh)
114//    , _rh(rh)
115//    {
116
117//    }
118//    virtual ~Pair() {
119//        delete _lh;
120//        delete _rh;
121//    }
122//protected:
123//    const RE * _lh;
124//    const RE * _rh;
125//};
126
127//static Diff * makeDiff(const RE * lh, const RE * rh);
128
129//static Intersect * makeIntersect(const RE * lh, const RE * rh);
130
131//static Permute * makePermute();
132//static Permute * makePermute(Vector::iterator begin, Vector::iterator end);
133
134//static SymDiff * makeSymDiff(const RE * lh, const RE * rh);
135
136//static Union * makeUnion(const RE * lh, const RE * rh);
137
138}
139
140#endif // RE_H
141
142
Note: See TracBrowser for help on using the repository browser.