forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_friend.hpp
More file actions
70 lines (56 loc) · 2.29 KB
/
Copy pathcpp_friend.hpp
File metadata and controls
70 lines (56 loc) · 2.29 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
// Copyright (C) 2017-2019 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_FRIEND_HPP_INCLUDED
#define CPPAST_CPP_FRIEND_HPP_INCLUDED
#include <type_safe/optional.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_type.hpp>
namespace cppast
{
/// A [cppast::cpp_entity]() representing a friend declaration.
///
/// It can either declare or define a `friend` function (template), declare a `friend` class,
/// or refer to an existing type.
class cpp_friend : public cpp_entity, private cpp_entity_container<cpp_friend, cpp_entity>
{
public:
static cpp_entity_kind kind() noexcept;
/// \returns A newly created friend declaring the given entity as `friend`.
/// \notes The friend declaration itself will not be registered,
/// but the referring entity is.
static std::unique_ptr<cpp_friend> build(std::unique_ptr<cpp_entity> e)
{
return std::unique_ptr<cpp_friend>(new cpp_friend(std::move(e)));
}
/// \returns A newly created friend declaring the given type as `friend`.
/// \notes It will not be registered.
static std::unique_ptr<cpp_friend> build(std::unique_ptr<cpp_type> type)
{
return std::unique_ptr<cpp_friend>(new cpp_friend(std::move(type)));
}
/// \returns An optional reference to the entity it declares as friend, or `nullptr`.
type_safe::optional_ref<const cpp_entity> entity() const noexcept
{
if (begin() == end())
return nullptr;
return type_safe::ref(*begin());
}
/// \returns An optional reference to the type it declares as friend, or `nullptr`.
type_safe::optional_ref<const cpp_type> type() const noexcept
{
return type_safe::opt_ref(type_.get());
}
private:
cpp_friend(std::unique_ptr<cpp_entity> e) : cpp_entity("")
{
add_child(std::move(e));
}
cpp_friend(std::unique_ptr<cpp_type> type) : cpp_entity(""), type_(std::move(type)) {}
cpp_entity_kind do_get_entity_kind() const noexcept override;
std::unique_ptr<cpp_type> type_;
friend cpp_entity_container<cpp_friend, cpp_entity>;
};
} // namespace cppast
#endif // CPPAST_CPP_FRIEND_HPP_INCLUDED