forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_variable_base.hpp
More file actions
45 lines (37 loc) · 1.39 KB
/
Copy pathcpp_variable_base.hpp
File metadata and controls
45 lines (37 loc) · 1.39 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
// 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_VARIABLE_BASE_HPP_INCLUDED
#define CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED
#include <cppast/cpp_expression.hpp>
#include <cppast/cpp_type.hpp>
namespace cppast
{
/// Additional base class for all [cppast::cpp_entity]() modelling some kind of variable.
///
/// Examples are [cppast::cpp_variable]() or [cppast::cpp_function_parameter](),
/// or anything that is name/type/default-value triple.
class cpp_variable_base
{
public:
/// \returns A reference to the [cppast::cpp_type]() of the variable.
const cpp_type& type() const noexcept
{
return *type_;
}
/// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the default value.
type_safe::optional_ref<const cpp_expression> default_value() const noexcept
{
return type_safe::opt_ref(default_.get());
}
protected:
cpp_variable_base(std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> def)
: type_(std::move(type)), default_(std::move(def))
{}
~cpp_variable_base() noexcept = default;
private:
std::unique_ptr<cpp_type> type_;
std::unique_ptr<cpp_expression> default_;
};
} // namespace cppast
#endif // CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED