|
7 | 7 | #include "cppast/defs.h" |
8 | 8 |
|
9 | 9 | #include <memory> |
| 10 | +#include <optional> |
10 | 11 | #include <string> |
| 12 | +#include <variant> |
11 | 13 |
|
12 | 14 | namespace cppast { |
13 | 15 |
|
14 | 16 | class CppEntity; |
15 | 17 | class CppVarType; |
16 | 18 | class CppFunctionPointer; |
| 19 | +class CppExpression; |
17 | 20 |
|
18 | 21 | /** |
19 | 22 | * Parameter types that are used to define a templated C++ entity. |
20 | 23 | */ |
21 | 24 | class CppTemplateParam |
22 | 25 | { |
23 | 26 | public: |
24 | | - CppTemplateParam(std::string paramName, std::unique_ptr<const CppEntity> defArg = nullptr); |
25 | | - CppTemplateParam(std::unique_ptr<const CppVarType> paramType, |
26 | | - std::string paramName, |
27 | | - std::unique_ptr<const CppEntity> defArg = nullptr); |
28 | | - CppTemplateParam(std::unique_ptr<const CppFunctionPointer> paramType, |
29 | | - std::string paramName, |
30 | | - std::unique_ptr<const CppEntity> defArg = nullptr); |
| 27 | + using ParamType = std::variant<std::unique_ptr<const CppVarType>, std::unique_ptr<const CppFunctionPointer>>; |
| 28 | + using ArgType = std::variant<std::unique_ptr<const CppVarType>, std::unique_ptr<const CppExpression>>; |
| 29 | + |
| 30 | +public: |
| 31 | + CppTemplateParam(std::string paramName, ArgType defArg = ArgType()); |
| 32 | + CppTemplateParam(ParamType paramType, std::string paramName, ArgType defArg = ArgType()); |
31 | 33 |
|
32 | 34 | CppTemplateParam(CppTemplateParam&& rval) = default; |
33 | 35 |
|
34 | 36 | ~CppTemplateParam(); |
35 | 37 |
|
36 | 38 | public: |
37 | | - const CppEntity* paramType() const |
| 39 | + const std::optional<ParamType>& paramType() const |
38 | 40 | { |
39 | | - return paramType_.get(); |
| 41 | + return paramType_; |
40 | 42 | } |
41 | 43 |
|
42 | 44 | const std::string& paramName() const |
43 | 45 | { |
44 | 46 | return paramName_; |
45 | 47 | } |
46 | 48 |
|
47 | | - const CppEntity* defaultArg() const |
| 49 | + const ArgType& defaultArg() const |
48 | 50 | { |
49 | | - return defaultArg_.get(); |
| 51 | + return defaultArg_; |
50 | 52 | } |
51 | 53 |
|
52 | 54 | private: |
53 | | - // If not nullptr then template param is not of type typename/class |
54 | | - std::unique_ptr<const CppEntity> paramType_; |
55 | | - std::string paramName_; |
56 | | - std::unique_ptr<const CppEntity> defaultArg_; //< Can be CppVarType or CppExpression |
| 55 | + // If initialized then template param is not of type typename/class |
| 56 | + std::optional<ParamType> paramType_; |
| 57 | + std::string paramName_; |
| 58 | + ArgType defaultArg_; |
57 | 59 | }; |
58 | 60 |
|
59 | 61 | } // namespace cppast |
60 | 62 |
|
| 63 | +#include "cppast/cpp_expression.h" |
| 64 | +#include "cppast/cpp_function.h" |
| 65 | +#include "cppast/cpp_var_type.h" |
| 66 | + |
61 | 67 | #endif /* A6947342_A917_4B84_B327_5878ACC690B3 */ |
0 commit comments