Open Lighting Architecture  0.9.2
 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 
26 namespace ola {
27 namespace web {
28 
29 template <typename T>
30 class OptionalItem {
31  public:
32  OptionalItem() : m_is_set(false) {}
33 
34  void Reset() { m_is_set = false; }
35 
36  void Set(const T &value) {
37  m_is_set = true;
38  m_value = value;
39  }
40 
41  bool IsSet() const { return m_is_set; }
42  const T& Value() const { return m_value; }
43 
44  private:
45  bool m_is_set;
46  T m_value;
47 
48  DISALLOW_COPY_AND_ASSIGN(OptionalItem);
49 };
50 
51 } // namespace web
52 } // namespace ola
53 #endif // COMMON_WEB_OPTIONALITEM_H_