CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUWidgetValue.h
1 //
2 // CUJsonValue.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module a modern C++ alternative to the cJSON interface for reading
6 // JSON files. In particular, this gives us better type-checking and memory
7 // management. With that said, it still uses cJSON as the underlying parsing
8 // engine.
9 //
10 // This class uses our standard shared-pointer architecture.
11 //
12 // 1. The constructor does not perform any initialization; it just sets all
13 // attributes to their defaults.
14 //
15 // 2. All initialization takes place via init methods, which can fail if an
16 // object is initialized more than once.
17 //
18 // 3. All allocation takes place via static constructors which return a shared
19 // pointer.
20 //
21 //
22 // CUGL MIT License:
23 // This software is provided 'as-is', without any express or implied
24 // warranty. In no event will the authors be held liable for any damages
25 // arising from the use of this software.
26 //
27 // Permission is granted to anyone to use this software for any purpose,
28 // including commercial applications, and to alter it and redistribute it
29 // freely, subject to the following restrictions:
30 //
31 // 1. The origin of this software must not be misrepresented; you must not
32 // claim that you wrote the original software. If you use this software
33 // in a product, an acknowledgment in the product documentation would be
34 // appreciated but is not required.
35 //
36 // 2. Altered source versions must be plainly marked as such, and must not
37 // be misrepresented as being the original software.
38 //
39 // 3. This notice may not be removed or altered from any source distribution.
40 //
41 // Author: Graham Rutledge
42 // Version: 5/20/19
43 //
44 #ifndef __CU_WIDGET_VALUE_H__
45 #define __CU_WIDGET_VALUE_H__
46 #include <cugl/base/CUBase.h>
47 #include <cugl/assets/CUJsonValue.h>
48 #include <memory>
49 
50 namespace cugl {
51 
58 class WidgetValue {
59 protected:
61  std::shared_ptr<JsonValue> json;
62 
63 public:
64 #pragma mark -
65 #pragma mark Constructors
66 
73 
81 
91  bool init(const std::shared_ptr<JsonValue> json) {
92  if (json == nullptr) {
93  return false;
94  }
95 
96  this->json = json;
97  return true;
98  }
99 
100 #pragma mark -
101 #pragma mark Static Constructors
102 
109  static std::shared_ptr<WidgetValue> alloc(std::shared_ptr<JsonValue> json) {
110  std::shared_ptr<WidgetValue> result = std::make_shared<WidgetValue>();
111  return (result->init(json) ? result : nullptr);
112  }
113 
114 #pragma mark -
115 #pragma mark Value Access
116 
122  const std::shared_ptr<JsonValue> getJson() const {
123  return json;
124  }
125 };
126 
127 }
128 #endif /* __CU_JSON_VALUE_H__ */
cugl::WidgetValue
Definition: CUWidgetValue.h:58
cugl::WidgetValue::getJson
const std::shared_ptr< JsonValue > getJson() const
Definition: CUWidgetValue.h:122
cugl::WidgetValue::json
std::shared_ptr< JsonValue > json
Definition: CUWidgetValue.h:61
cugl::WidgetValue::init
bool init(const std::shared_ptr< JsonValue > json)
Definition: CUWidgetValue.h:91
cugl::WidgetValue::alloc
static std::shared_ptr< WidgetValue > alloc(std::shared_ptr< JsonValue > json)
Definition: CUWidgetValue.h:109
cugl::WidgetValue::WidgetValue
WidgetValue()
Definition: CUWidgetValue.h:72
cugl::WidgetValue::~WidgetValue
~WidgetValue()
Definition: CUWidgetValue.h:80