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

Last change on this file since 5037 was 5037, checked in by nmedfort, 3 years ago

UnicodeSet? bug fix and compile warning clean-up.

File size: 1.9 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#include <llvm/Support/Casting.h>
13#include <util/slab_allocator.h>
14
15using namespace llvm;
16
17namespace re {
18
19class Vector;
20class Pair;
21
22class Alt;
23class Any;
24class Assertion;
25class CC;
26class Diff;
27class End;
28class Intersect;
29class Name;
30class Permute;
31class Rep;
32class Seq;
33class Start;
34class SymDiff;
35class Union;
36class GraphemeBoundary;
37
38class RE {
39public:
40    using Allocator = SlabAllocator<u_int8_t>;
41    using VectorAllocator = SlabAllocator<RE *>;
42    enum class ClassTypeId : unsigned {
43        Alt
44        , Any
45        , Assertion
46        , CC
47        , Diff
48        , End
49        , Intersect
50        , Name
51        , Permute
52        , Rep
53        , Seq
54        , Start
55        , SymDiff
56        , Union
57        , GraphemeBoundary
58    };
59    inline ClassTypeId getClassTypeId() const {
60        return mClassTypeId;
61    }
62    typedef std::initializer_list<RE *> InitializerList;
63protected:
64    inline RE(const ClassTypeId id)
65    : mClassTypeId(id) {
66
67    }
68    void* operator new (std::size_t size) noexcept {
69        return mAllocator.allocate(size);
70    }
71    const ClassTypeId mClassTypeId;
72
73    static Allocator mAllocator;
74    static VectorAllocator mVectorAllocator;
75};
76
77class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
78public:
79
80    virtual ~Vector() {
81    }
82protected:
83    inline Vector(const ClassTypeId id)
84    : RE(id)
85    , std::vector<RE*, RE::VectorAllocator>(mVectorAllocator)
86    {
87
88    }
89    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
90    : RE(id)
91    , std::vector<RE*, RE::VectorAllocator>(begin, end, mVectorAllocator) {
92
93    }
94};
95
96}
97
98#endif // RE_H
99
100
Note: See TracBrowser for help on using the repository browser.