source: icGREP/icgrep-devel/icgrep/re/re_seq.h @ 4588

Last change on this file since 4588 was 4516, checked in by nmedfort, 4 years ago

More memory leak fixes. All known leaks accounted for.

File size: 1.5 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_SEQ_H
8#define RE_SEQ_H
9
10#include "re_re.h"
11#include <string>
12#include <initializer_list>
13
14namespace re {
15
16class Seq : public Vector {
17public:
18    static inline bool classof(const RE * re) {
19        return re->getClassTypeId() == ClassTypeId::Seq;
20    }
21    static inline bool classof(const void *) {
22        return false;
23    }
24    virtual ~Seq() {}
25protected:
26    friend Seq * makeSeq();
27    template<typename iterator> friend RE * makeSeq(iterator, iterator);
28    Seq()
29    : Vector(ClassTypeId::Seq) {
30
31    }
32    Seq(iterator begin, iterator end)
33    : Vector(ClassTypeId::Seq, begin, end) {
34
35    }
36    template<typename itr> void flatten(itr begin, itr end);
37};
38
39inline Seq * makeSeq() {
40    return new Seq();
41}
42
43template<typename itr>
44void Seq::flatten(itr begin, itr end) {
45    for (auto i = begin; i != end; ++i) {
46        if (Seq * seq = dyn_cast<Seq>(*i)) {
47            flatten<Seq::iterator>(seq->begin(), seq->end());
48            continue;
49        }
50        push_back(*i);
51    }
52}
53
54template<typename itr>
55inline RE * makeSeq(itr begin, itr end) {
56    Seq * seq = makeSeq();
57    seq->flatten(begin, end);
58    if (seq->size() == 1) {
59        return seq->back();
60    }
61    return seq;
62}
63
64inline RE * makeSeq(RE::InitializerList list) {
65    return makeSeq(list.begin(), list.end());
66}
67
68}
69
70#endif // JOIN_H
71
72
73
74
Note: See TracBrowser for help on using the repository browser.