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  item->addRef();
31  m_items.push_back(nx::sdk::toPtr(item));
32  }
33 
34  void clear()
35  {
36  m_items.clear();
37  }
38 
39 protected:
40  virtual IItem* getAt(int index) const override
41  {
42  if (!NX_KIT_ASSERT(index >= 0 && index < (int) m_items.size()))
43  return nullptr;
44 
45  if (!NX_KIT_ASSERT(m_items[index]))
46  return nullptr;
47 
48  m_items[index]->addRef();
49  return m_items[index].get();
50  }
51 
52 private:
53  std::vector<nx::sdk::Ptr<IItem>> m_items;
54 };
55 
56 } // namespace sdk
57 } // namespace nx
#define NX_KIT_ASSERT(...)
Definition: debug.h:128
virtual IItem * getAt(int index) const override
Definition: list.h:40
Definition: apple_utils.h:6
Definition: list.h:17
Definition: ref_countable.h:84