cppast/include/cppast/cpp_file.hpp
2017-02-10 19:47:39 +01:00

70 lines
2.1 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_FILE_HPP_INCLUDED
#define CPPAST_CPP_FILE_HPP_INCLUDED
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_entity_ref.hpp>
namespace cppast
{
/// A [cppast::cpp_entity]() modelling a file.
///
/// This is the top-level entity of the AST.
class cpp_file final : public cpp_entity, public cpp_entity_container<cpp_file, cpp_entity>
{
public:
/// Builds a [cppast::cpp_file]().
class builder
{
public:
/// \effects Sets the file name.
explicit builder(std::string name) : file_(new cpp_file(std::move(name)))
{
}
/// \effects Adds an entity.
void add_child(std::unique_ptr<cpp_entity> child) noexcept
{
file_->add_child(std::move(child));
}
/// \effects Registers the file in the [cppast::cpp_entity_index]().
/// It will use the file name as identifier.
/// \returns The finished file.
std::unique_ptr<cpp_file> finish(const cpp_entity_index& idx) noexcept
{
idx.register_entity(cpp_entity_id(file_->name()), type_safe::ref(*file_));
return std::move(file_);
}
private:
std::unique_ptr<cpp_file> file_;
};
private:
cpp_file(std::string name) : cpp_entity(std::move(name))
{
}
/// \returns [cpp_entity_type::file_t]().
cpp_entity_kind do_get_entity_kind() const noexcept override;
};
/// \exclude
namespace detail
{
struct cpp_file_ref_predicate
{
bool operator()(const cpp_entity& e);
};
} // namespace detail
/// A reference to a [cppast::cpp_file]().
using cpp_file_ref = basic_cpp_entity_ref<cpp_file, detail::cpp_file_ref_predicate>;
} // namespace cppast
#endif // CPPAST_CPP_FILE_HPP_INCLUDED