NDEVR
API Documentation
IconManager.h
1#pragma once
2#include <NDEVR/Dictionary.h>
3#include <NDEVR/JSONNode.h>
4#include <NDEVR/String.h>
5namespace NDEVR
6{
12 {
18 : icon_id(def)
20 {}
21
27 IconDefinition(const StringView& id, const StringView& def)
28 : icon_id(id)
30 {}
31
37 {
38 fromJSON(node);
39 }
40
44 void toJSON(JSONNode& node) const
45 {
46 node["icon_id"] = icon_id;
47 node["default_draw_operation"] = default_draw_operation;
48 }
49
53 void fromJSON(const JSONNode& node)
54 {
55 icon_id = node["icon_id"].getAs<String>();
56 default_draw_operation = node["default_draw_operation"].getAs<String>();
57 }
60 };
61
67 {
68 public:
73 void toJSON(JSONNode& node) const
74 {
75 for (auto& def : m_icons)
76 {
77 def.second.toJSON(node[def.first]);
78 }
79 }
80
84 void fromJSON(const JSONNode& node)
85 {
86 for (const JSONNode* def : node.children())
87 {
89 }
90 }
91
95 void addIcon(const IconDefinition& definition)
96 {
97 m_icons.add(definition.icon_id, definition);
98 }
99 protected:
101 };
102 #define _i(id, def) (IconDefinition(id, def))
103}
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Stores information about many different icons.
Definition IconManager.h:67
void addIcon(const IconDefinition &definition)
Adds an icon definition to the manager, indexed by its icon ID.
Definition IconManager.h:95
Dictionary< String, IconDefinition > m_icons
Maps icon ID strings to their corresponding IconDefinition objects.
void fromJSON(const JSONNode &node)
Deserializes icon definitions from a JSON node and adds them to this manager.
Definition IconManager.h:84
void toJSON(JSONNode &node) const
Serializes all stored icon definitions to a JSON node.
Definition IconManager.h:73
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:149
decltype(auto) getAs() const
Definition JSONParser.h:315
const Buffer< JSONNode * > & children() const
Returns the ordered list of child node pointers.
Definition JSONParser.h:392
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
The primary namespace for the NDEVR SDK.
Information for displaying a particular icon.
Definition IconManager.h:12
IconDefinition(const StringView &def)
Constructs an IconDefinition using the same value for both the icon ID and default draw operation.
Definition IconManager.h:17
String icon_id
The unique identifier string for this icon.
Definition IconManager.h:58
String default_draw_operation
The default draw operation used to render this icon.
Definition IconManager.h:59
void fromJSON(const JSONNode &node)
Deserializes this icon definition from a JSON node.
Definition IconManager.h:53
IconDefinition(const StringView &id, const StringView &def)
Constructs an IconDefinition with separate icon ID and default draw operation.
Definition IconManager.h:27
IconDefinition(const JSONNode &node)
Constructs an IconDefinition by deserializing from a JSON node.
Definition IconManager.h:36
void toJSON(JSONNode &node) const
Serializes this icon definition to a JSON node.
Definition IconManager.h:44