cppast/include/cppast/cpp_entity_container.hpp
Jonathan Müller 023ce3e87c Remove cpp_scope
2017-01-21 22:30:51 +01:00

59 lines
1.7 KiB
C++

// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
// 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