Open Lighting Architecture: include/ola/web/OptionalItem.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
OptionalItem.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * OptionalItem.h
17 * A value which may or may not be present.
18 * Copyright (C) 2014 Simon Newton
19 */
20
21#ifndef INCLUDE_OLA_WEB_OPTIONALITEM_H_
22#define INCLUDE_OLA_WEB_OPTIONALITEM_H_
23
24#include <ola/base/Macro.h>
25#include <string>
26
27namespace ola {
28namespace web {
29
30template <typename T>
31 class OptionalItem {
32 public:
33 OptionalItem();
34
35 void Reset() { m_is_set = false; }
36
37 void Set(const T &value) {
38 m_is_set = true;
39 m_value = value;
40 }
41
42 bool IsSet() const { return m_is_set; }
43 const T& Value() const { return m_value; }
44
45 private:
46 bool m_is_set;
47 T m_value;
48
49 OptionalItem(const OptionalItem &) = delete;
50 const OptionalItem &operator=(const OptionalItem &) = delete;
51};
52
53template <>
54inline OptionalItem<std::string>::OptionalItem()
55 : m_is_set(false) {
56}
57
58template <typename T>
59OptionalItem<T>::OptionalItem()
60 : m_is_set(false),
61 m_value(0) {
62}
63
64
65} // namespace web
66} // namespace ola
67#endif // INCLUDE_OLA_WEB_OPTIONALITEM_H_
Macro.h
Helper macros.
ola::web
Classes to deal with web services.
Definition Json.cpp:29
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44