-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcpp_compound_utility.h
More file actions
64 lines (54 loc) · 1.5 KB
/
Copy pathcpp_compound_utility.h
File metadata and controls
64 lines (54 loc) · 1.5 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
// Copyright (C) 2022 Satya Das and CppParser contributors
// SPDX-License-Identifier: MIT
#ifndef A00E589B_6B8A_49DC_8718_C511FCDE46CB
#define A00E589B_6B8A_49DC_8718_C511FCDE46CB
#include "cppast/cpp_compound.h"
#include "cppast/cpp_entity_info_accessor.h"
#include "defs.h"
namespace cppast {
/**
* @brief Get the vector of specific type of owned entities.
*
* @tparam _EntityClass Class type of owned entities.
* @return std::vector of owned entities.
*/
template <typename _EntityClass>
inline std::vector<const _EntityClass*> GetOwnedEntities(const CppCompound& owner)
{
std::vector<const _EntityClass*> result;
owner.visit([&result](const _EntityClass& entity) {
result.push_back(&entity);
return true;
});
return result;
}
/**
* @brief Get all the owned entities.
*
* @return std::vector of owned entities.
*/
inline std::vector<const CppEntity*> GetAllOwnedEntities(const CppCompound& owner)
{
std::vector<const CppEntity*> result;
owner.visitAll([&result](const CppEntity& entity) {
result.push_back(&entity);
return true;
});
return result;
}
/**
* @brief Get full name of a compound.
*
* @return full name of compound type.
*/
inline std::string FullName(const CppCompound& compound)
{
if (!IsNamespaceLike(compound))
return "";
if (compound.owner() && IsNamespaceLike(*compound.owner()))
return FullName(*compound.owner()) + "::" + compound.name();
else
return compound.name();
}
} // namespace cppast
#endif /* A00E589B_6B8A_49DC_8718_C511FCDE46CB */