KiCad PCB EDA Suite
Loading...
Searching...
No Matches
std_optional_variants.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef STD_OPTIONAL_VARIANT_H
21#define STD_OPTIONAL_VARIANT_H
22
23#include <optional>
24#include <wx/variant.h>
25
26/*
27 * Wrappers to allow use of std::optional<int> and std::optional<double> with the wxVariant
28 * system.
29 */
30
31class STD_OPTIONAL_INT_VARIANT_DATA : public wxVariantData
32{
33public:
35
36 STD_OPTIONAL_INT_VARIANT_DATA( std::optional<int> aValue );
37
38 bool Eq( wxVariantData& aOther ) const override;
39
40 wxString GetType() const override { return wxT( "std::optional<int>" ); }
41
42 bool GetAsAny( wxAny* aAny ) const override
43 {
44 *aAny = m_value;
45 return true;
46 }
47
48 std::optional<int> Value() const
49 {
50 return m_value;
51 }
52
53 static wxVariantData* VariantDataFactory( const wxAny& aAny )
54 {
55 return new STD_OPTIONAL_INT_VARIANT_DATA( aAny.As<std::optional<int>>() );
56 }
57
58protected:
59 std::optional<int> m_value;
60};
61
62
63class STD_OPTIONAL_DOUBLE_VARIANT_DATA : public wxVariantData
64{
65public:
67
68 STD_OPTIONAL_DOUBLE_VARIANT_DATA( std::optional<double> aValue );
69
70 bool Eq( wxVariantData& aOther ) const override;
71
72 wxString GetType() const override { return wxT( "std::optional<double>" ); }
73
74 bool GetAsAny( wxAny* aAny ) const override
75 {
76 *aAny = m_value;
77 return true;
78 }
79
80 std::optional<double> Value() const
81 {
82 return m_value;
83 }
84
85 static wxVariantData* VariantDataFactory( const wxAny& aAny )
86 {
87 return new STD_OPTIONAL_DOUBLE_VARIANT_DATA( aAny.As<std::optional<double>>() );
88 }
89
90protected:
91 std::optional<double> m_value;
92};
93
94#endif //STD_OPTIONAL_VARIANT_H
std::optional< double > Value() const
bool Eq(wxVariantData &aOther) const override
wxString GetType() const override
bool GetAsAny(wxAny *aAny) const override
static wxVariantData * VariantDataFactory(const wxAny &aAny)
bool Eq(wxVariantData &aOther) const override
std::optional< int > Value() const
wxString GetType() const override
bool GetAsAny(wxAny *aAny) const override
static wxVariantData * VariantDataFactory(const wxAny &aAny)