Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 COMMON_WEB_OPTIONALITEM_H_
22 #define COMMON_WEB_OPTIONALITEM_H_
23 
24 #include <ola/base/Macro.h>
25 #include <string>
26 
27 namespace ola {
28 namespace web {
29 
30 template <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  DISALLOW_COPY_AND_ASSIGN(OptionalItem);
50 };
51 
52 template <>
54  : m_is_set(false) {
55 }
56 
57 template <typename T>
58 OptionalItem<T>::OptionalItem()
59  : m_is_set(false),
60  m_value(0) {
61 }
62 
63 
64 } // namespace web
65 } // namespace ola
66 #endif // COMMON_WEB_OPTIONALITEM_H_