libsidplayfp 3.0.2
properties.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2025-2026 Leandro Nini <drfiemost@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef PROPERTIES_H
22#define PROPERTIES_H
23
24#include "sidcxx11.h"
25
26#ifdef HAVE_CXX17
27# if __has_include(<optional>)
28# define HAS_OPTIONAL 1
29# endif
30#endif
31
32#ifdef HAS_OPTIONAL
33
34#include <optional>
35
36template <typename T>
37using Property = std::optional<T>;
38
39#else
40
41#include <type_traits>
42
43template <typename T>
44class Property
45{
46 static_assert(std::is_scalar<T>(), "T must be a scalar type");
47
48private:
49 T m_val;
50 bool m_isSet;
51
52public:
53 Property() :
54 m_isSet(false) {}
55
56 inline bool has_value() const { return m_isSet; }
57 inline T value() const { return m_val; }
58 inline Property<T>& operator =(const T& val) { m_val = val; m_isSet = true; return *this; }
59};
60
61#endif // HAVE_CXX17
62
63#endif // PROPERTIES_H
Definition properties.h:45