blob: a579eb0df1169ec08b9ebcdb94d0c44c9e0f436d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "span.h"
#include <memory>
#include <vector>
namespace document {
class SpanList : public SpanNode {
std::vector<SpanNode *> _span_vector;
public:
using UP = std::unique_ptr<SpanList>;
using const_iterator = std::vector<SpanNode *>::const_iterator;
~SpanList();
template <typename T>
T &add(std::unique_ptr<T> node) {
T *n = node.get();
_span_vector.push_back(node.release());
return *n;
}
size_t size() const { return _span_vector.size(); }
void reserve(size_t sz) { _span_vector.reserve(sz); }
const_iterator begin() const { return _span_vector.begin(); }
const_iterator end() const { return _span_vector.end(); }
void accept(SpanTreeVisitor &visitor) const override;
};
class SimpleSpanList : public SpanNode {
using SpanVector = std::vector<Span>;
SpanVector _span_vector;
public:
using UP = std::unique_ptr<SimpleSpanList>;
using const_iterator = SpanVector::const_iterator;
SimpleSpanList(size_t sz);
~SimpleSpanList();
size_t size() const { return _span_vector.size(); }
Span & operator [] (size_t index) { return _span_vector[index]; }
const Span & operator [] (size_t index) const { return _span_vector[index]; }
const_iterator begin() const { return _span_vector.begin(); }
const_iterator end() const { return _span_vector.end(); }
void accept(SpanTreeVisitor &visitor) const override;
};
} // namespace document
|