forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_entity_container.hpp
More file actions
59 lines (48 loc) · 1.58 KB
/
Copy pathcpp_entity_container.hpp
File metadata and controls
59 lines (48 loc) · 1.58 KB
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
59
// Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#ifndef CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED
#define CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED
#include <cppast/cpp_entity.hpp>
namespace cppast
{
/// Helper class for entities that are containers.
///
/// Inherit from it to generate container access.
template <class Derived, typename T>
class cpp_entity_container
{
public:
using iterator = typename detail::intrusive_list<T>::const_iterator;
/// \returns A const iterator to the first child.
iterator begin() const noexcept
{
return children_.begin();
}
/// \returns A const iterator to the last child.
iterator end() const noexcept
{
return children_.end();
}
protected:
/// \effects Adds a new child to the container.
void add_child(std::unique_ptr<T> ptr) noexcept
{
children_.push_back(static_cast<Derived&>(*this), std::move(ptr));
}
/// \returns A non-const iterator to the first child.
typename detail::intrusive_list<T>::iterator mutable_begin() noexcept
{
return children_.begin();
}
/// \returns A non-const iterator one past the last child.
typename detail::intrusive_list<T>::iterator mutable_end() noexcept
{
return children_.begin();
}
~cpp_entity_container() noexcept = default;
private:
detail::intrusive_list<T> children_;
};
} // namespace cppast
#endif // CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED