hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCECommonList.hpp
Go to the documentation of this file.
1 
14 #ifndef DRCE_COMMON_LIST_HPP
15 #define DRCE_COMMON_LIST_HPP
16 
17 #include <iostream>
18 #include <vector>
19 
20 namespace HCE
21 {
22 namespace drce
23 {
24 //-----------------------------------------------------------------------------
25 template <typename _Item>
27 {
28 public:
29  DRCECommonList(void) : items() {}
30  DRCECommonList(const DRCECommonList& rhs);
32  virtual ~DRCECommonList(void) {}
33 
36 
37  void addItem(const _Item& item);
38  void addItem(_Item&& item);
39 
40  const std::vector<_Item>& getItems(void) const {return items;}
41 
42  size_t getItemsCount(void) const;
43  const _Item& getItem(size_t index) const;
44  void setItem(size_t index, const _Item& item);
45  void setItem(size_t index, _Item&& item);
46 
47  void clear(void);
48 protected:
49  std::vector<_Item> items;
50 };
51 //-----------------------------------------------------------------------------
52 template <class _Item> DRCECommonList<_Item>::DRCECommonList(const DRCECommonList& rhs)
53 : items()
54 {
55  (*this) = rhs;
56 }
57 //-----------------------------------------------------------------------------
59 : items()
60 {
61  (*this) = std::forward<DRCECommonList>(rhs);
62 }
63 //-----------------------------------------------------------------------------
65 {
66  if (this!=&rhs)
67  {
68  items = rhs.getItems();
69  }
70  return *this;
71 }
72 //-----------------------------------------------------------------------------
74 {
75  if (this!=&rhs)
76  {
77  items = std::move(rhs.getItems());
78  }
79  return *this;
80 }
81 //-----------------------------------------------------------------------------
82 template <class _Item> void DRCECommonList<_Item>::addItem(const _Item& item)
83 {
84  items.push_back(item);
85 }
86 //-----------------------------------------------------------------------------
87 template <class _Item> void DRCECommonList<_Item>::addItem(_Item&& item)
88 {
89  items.push_back(std::move(std::forward<_Item>(item)));
90 }
91 //-----------------------------------------------------------------------------
92 template <class _Item> size_t DRCECommonList<_Item>::getItemsCount(void) const
93 {
94  return items.size();
95 }
96 //-----------------------------------------------------------------------------
97 template <class _Item> const _Item& DRCECommonList<_Item>::getItem(size_t index) const
98 {
99  return items[index];
100 }
101 //-----------------------------------------------------------------------------
102 template <class _Item> void DRCECommonList<_Item>::setItem(size_t index, const _Item& item)
103 {
104  if (items.size() > index)
105  items[index] = item;
106 }
107 //-----------------------------------------------------------------------------
108 template <class _Item> void DRCECommonList<_Item>::setItem(size_t index, _Item&& item)
109 {
110  if (items.size() > index)
111  items[index] = std::forward<_Item>(item);
112 }
113 //-----------------------------------------------------------------------------
114 template <class _Item> void DRCECommonList<_Item>::clear(void)
115 {
116  items.clear();
117 }
118 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
120 } // end namespace drce
121 } // end namespace HCE
122 
123 #endif // DRCE_COMMON_LIST_HPP