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

Last change on this file since 5812 was 5765, checked in by cameron, 19 months ago

Regular expression group nodes; case-insensitive logic

File size: 1.8 KB
RevLine 
[3850]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
[5267]10#include <util/slab_allocator.h>
[4182]11#include <vector>
12
[4194]13namespace re {
14
15class RE {
[3850]16public:
[5240]17    using Allocator = SlabAllocator<RE *>;
18    using VectorAllocator = ProxyAllocator<RE *>;
[4194]19    enum class ClassTypeId : unsigned {
20        Alt
[4245]21        , Any
[4405]22        , Assertion
[4194]23        , CC
[5763]24        , Range
[4194]25        , Diff
26        , End
27        , Intersect
28        , Name
[5765]29        , Group
[4194]30        , Rep
31        , Seq
32        , Start
33    };
[4199]34    inline ClassTypeId getClassTypeId() const {
[4194]35        return mClassTypeId;
36    }
[5742]37    inline static void Reset() {
38        mAllocator.Reset();
39    }
[4203]40    typedef std::initializer_list<RE *> InitializerList;
[5748]41
[3850]42protected:
[4194]43    inline RE(const ClassTypeId id)
44    : mClassTypeId(id) {
45
46    }
[4516]47    void* operator new (std::size_t size) noexcept {
[5240]48        return mAllocator.allocate<uint8_t>(size);
[4516]49    }
[4194]50    const ClassTypeId mClassTypeId;
[4272]51    static Allocator mAllocator;
[3850]52};
53
[4510]54class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
[4194]55public:
[5630]56    static inline bool classof(const RE * re) {
57        const auto typeId = re->getClassTypeId();
58        return typeId == ClassTypeId::Alt || typeId == ClassTypeId::Seq;
59    }
60    static inline bool classof(const void *) {
61        return false;
62    }
[5240]63    virtual ~Vector() {}
[4194]64protected:
65    inline Vector(const ClassTypeId id)
66    : RE(id)
[5240]67    , std::vector<RE*, RE::VectorAllocator>(mAllocator)
[4194]68    {
69
70    }
71    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
72    : RE(id)
[5240]73    , std::vector<RE*, RE::VectorAllocator>(begin, end, mAllocator) {
[4194]74
75    }
76};
77
78}
79
[3850]80#endif // RE_H
81
82
Note: See TracBrowser for help on using the repository browser.