forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_file.hpp
More file actions
99 lines (80 loc) · 2.86 KB
/
Copy pathcpp_file.hpp
File metadata and controls
99 lines (80 loc) · 2.86 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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_FILE_HPP_INCLUDED
#define CPPAST_CPP_FILE_HPP_INCLUDED
#include <vector>
#include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_ref.hpp>
namespace cppast
{
/// An unmatched documentation comment.
struct cpp_doc_comment
{
std::string content;
unsigned line;
cpp_doc_comment(std::string content, unsigned line) : content(std::move(content)), line(line) {}
};
/// 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:
static cpp_entity_kind kind() noexcept;
/// 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 Adds an unmatched documentation comment.
void add_unmatched_comment(cpp_doc_comment comment)
{
file_->comments_.push_back(std::move(comment));
}
/// \returns The not yet finished file.
cpp_file& get() noexcept
{
return *file_;
}
/// \effects Registers the file in the [cppast::cpp_entity_index]().
/// It will use the file name as identifier.
/// \returns The finished file, or `nullptr`, if that file was already registered.
std::unique_ptr<cpp_file> finish(const cpp_entity_index& idx) noexcept
{
auto res = idx.register_file(cpp_entity_id(file_->name()), type_safe::ref(*file_));
return res ? std::move(file_) : nullptr;
}
private:
std::unique_ptr<cpp_file> file_;
};
/// \returns The unmatched documentation comments.
type_safe::array_ref<const cpp_doc_comment> unmatched_comments() const noexcept
{
return type_safe::ref(comments_.data(), comments_.size());
}
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;
std::vector<cpp_doc_comment> comments_;
};
/// \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