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

Last change on this file since 4885 was 4860, checked in by nmedfort, 4 years ago

Back up check in. Memory leaks should be fixed.

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 <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 = Allocator::rebind<RE *>::other;
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};
75
76class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
77public:
78
79    virtual ~Vector() {
80    }
81protected:
82    inline Vector(const ClassTypeId id)
83    : RE(id)
84    , std::vector<RE*, RE::VectorAllocator>(reinterpret_cast<VectorAllocator &>(mAllocator))
85    {
86
87    }
88    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
89    : RE(id)
90    , std::vector<RE*, RE::VectorAllocator>(begin, end, reinterpret_cast<VectorAllocator &>(mAllocator)) {
91
92    }
93};
94
95}
96
97#endif // RE_H
98
99
Note: See TracBrowser for help on using the repository browser.