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 <nx/kit/debug.h>
6
7 #include <nx/sdk/i_list.h>
8
9 #include <nx/sdk/helpers/list.h>
10
11 namespace nx {
12 namespace 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(IItem* item)
24 {
25 if (!NX_KIT_ASSERT(item))
26 return;
27
28 item->addRef();
29 m_items.push_back(nx::sdk::toPtr(item));
30 }
31
32 void clear()
33 {
34 m_items.clear();
35 }
36
37 protected:
38 virtual IItem* getAt(int index) const override
39 {
40 if (!NX_KIT_ASSERT(index >= 0 && index < (int) m_items.size()))
41 return nullptr;
42
43 if (!NX_KIT_ASSERT(m_items[index]))
44 return nullptr;
45
46 m_items[index]->addRef();
47 return m_items[index].get();
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:38
nx
Definition: apple_utils.h:6
nx::sdk::List
Definition: list.h:15
nx::sdk::RefCountable
Definition: ref_countable.h:84