libsidplayfp 3.0.0
properties.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2025 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
28#include <optional>
29
30template <typename T>
31using Property = std::optional<T>;
32
33#else
34
35#include <type_traits>
36
37template <typename T>
38class Property
39{
40 static_assert(std::is_scalar<T>(), "T must be a scalar type");
41
42private:
43 T m_val;
44 bool m_isSet;
45
46public:
47 Property() :
48 m_isSet(false) {}
49
50 inline bool has_value() const { return m_isSet; }
51 inline T value() const { return m_val; }
52 inline Property<T>& operator =(const T& val) { m_val = val; m_isSet = true; return *this; }
53};
54
55#endif // HAVE_CXX17
56
57#endif // PROPERTIES_H
Definition properties.h:39