nx_server_plugin_sdk 1.0 Server Plugin SDK

string_map.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <map>
6 #include <vector>
7
8 #include <nx/sdk/helpers/ref_countable.h>
9 #include <nx/sdk/i_string_map.h>
10
11 namespace nx::sdk {
12
13 class StringMap: public RefCountable<IStringMap>
14 {
15 public:
16 using Map = std::map<std::string, std::string>;
17
18 StringMap() = default;
19
20 StringMap(Map map): m_map(std::move(map)) {}
21
22 void setItem(std::string key, std::string value);
23
24 void clear();
25
26 virtual int count() const override;
27
29 virtual const char* key(int i) const override;
30
32 virtual const char* value(int i) const override;
33
34 virtual const char* value(const char* key) const override;
35
36 private:
37 void initLookupCache() const;
38
39 private:
40 Map m_map;
41
42 // Cache for lookup by index to avoid O(N^2).
43 mutable std::vector<const char*> m_lookupCache;
44 };
45
46 std::map<std::string, std::string> toStdMap(const nx::sdk::Ptr<const nx::sdk::IStringMap>& sdkMap);
47
48 } // namespace nx::sdk
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::StringMap
Definition: string_map.h:13
nx::sdk::StringMap::key
virtual const char * key(int i) const override
Definition: string_map.cpp:29
nx::sdk
Definition: device_agent.h:12
nx::sdk::StringMap::value
virtual const char * value(int i) const override
Definition: string_map.cpp:38
nx::sdk::RefCountable
Definition: ref_countable.h:83