nx_server_plugin_sdk 1.0 Server Plugin SDK

list.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 <vector>
6
7 #include <nx/kit/debug.h>
8 #include <nx/sdk/helpers/ref_countable.h>
9 #include <nx/sdk/i_list.h>
10 #include <nx/sdk/ptr.h>
11
12 namespace nx::sdk {
13
14 template<typename IItem>
15 class List: public RefCountable<IList<IItem>>
16 {
17 public:
18 virtual int count() const override
19 {
20 return (int) m_items.size();
21 }
22
23 void addItem(Ptr<IItem> item)
24 {
25 if (!NX_KIT_ASSERT(item))
26 return;
27
28 m_items.push_back(item);
29 }
30
31 void clear()
32 {
33 m_items.clear();
34 }
35
36 protected:
37 virtual IItem* getAt(int index) const override
38 {
39 if (!NX_KIT_ASSERT(index >= 0 && index < (int) m_items.size()))
40 return nullptr;
41
42 if (!NX_KIT_ASSERT(m_items[index]))
43 return nullptr;
44
45 return shareToPtr(m_items[index]).releasePtr();
46 }
47
48 private:
49 std::vector<Ptr<IItem>> m_items;
50 };
51
52 } // namespace nx::sdk
NX_KIT_ASSERT
#define NX_KIT_ASSERT(...)
Definition: debug.h:122
debug.h
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::List::getAt
virtual IItem * getAt(int index) const override
Definition: list.h:37
nx::sdk
Definition: device_agent.h:12
nx::sdk::List
Definition: list.h:15
nx::sdk::RefCountable
Definition: ref_countable.h:83