-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp_argument.hpp
More file actions
61 lines (48 loc) · 1.23 KB
/
app_argument.hpp
File metadata and controls
61 lines (48 loc) · 1.23 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
#pragma once
#include <any>
#include <optional>
#include <string>
//------------------------------------------------------------------------------
namespace application
{
//------------------------------------------------------------------------------
class Argument
{
public:
using ValueOpt = std::optional< std::any >;
Argument(
std::string _fullName,
std::string _description,
ValueOpt _defaultValue = std::nullopt );
template< class _Value > void setValue( const _Value & _value )
{
m_value = _value;
}
const std::string & getFullName() const;
const std::string & getDescription() const;
template< class _Value > std::optional< _Value > getValue() const
{
return getValue< _Value >( m_value );
}
template< class _Value > std::optional< _Value > getDefaultValue() const
{
return getValue< _Value >( m_defaultValue );
}
private:
template< class _Value >
std::optional< _Value > getValue( const ValueOpt & _valueOpt ) const
{
if( _valueOpt )
{
return std::any_cast< _Value >( *_valueOpt );
}
return std::nullopt;
}
private:
std::string m_fullName;
std::string m_description;
ValueOpt m_defaultValue;
ValueOpt m_value;
};
//------------------------------------------------------------------------------
}