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