RDK Documentation (Open Sourced RDK Components)
list.hpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /*
22  * @file list.hpp
23  * @brief This file defines List class and implements it.
24  */
25 
26 
27 
28 /**
29 * @defgroup devicesettings
30 * @{
31 * @defgroup ds
32 * @{
33 **/
34 
35 
36 #ifndef _DS_LIST_HPP_
37 #define _DS_LIST_HPP_
38 
39 #include <vector>
40 
41 namespace device {
42 
43 template <class T>
44 
45 /**
46  * @class List
47  * @brief This class is implemented using templates and it is used to maintain
48  * a container with the list of supported ID's.
49  * @ingroup devicesettingsclass
50  */
51 class List {
52  typedef typename std::vector<int>::iterator iterator; //!< An iterator for the container.
53 
54  std::vector <int> _container; //!< Vector container for integers to maintain the id's.
55 
56  public:
57 
58 /**
59  * @fn List::List()
60  * @brief This function is the default constructor of class List.
61  *
62  * @return None
63  */
64  List() {};
65 
66 /**
67  * @fn List::~List()
68  * @brief This function is the default destructor of class List and is a virtual function.
69  */
70  virtual ~List() {};
71 
72 /**
73  * @fn List::at(size_t i)
74  * @brief This is a template function to get the instance of the calling class against
75  * the value at the position i of the container.
76  *
77  * @param[in] i Specifies the container index.
78  *
79  * @return Returns an instance of the class calling this function. The return value is
80  * const and cannot be modified.
81  */
82  const T & at(size_t i) const {
83  return T::getInstance(_container.at(i));
84  }
85 
86 /**
87  * @fn List::at(size_t i)
88  * @brief This is a template function to get the instance of the calling class against
89  * the value at the position i of the container.
90  *
91  * @param[in] i Specifies the container index.
92  *
93  * @return Returns an instance of the class calling this function.
94  */
95  T & at(size_t i) {
96  return T::getInstance(_container.at(i));
97  }
98 
99 /**
100  * @fn List::push_back(const T& x)
101  * @brief This is a template function used to push/store the ID
102  * of an instance x into the container.
103  *
104  * @param[in] x Indicates an instance whose ID needs to be stored.
105  *
106  * @return None
107  */
108  void push_back(const T& x) {
109  _container.push_back(x.getId());
110  }
111 
112 /**
113  * @fn List::size()
114  * @brief This function gets the size of the container.
115  *
116  * @return Returns the size of the container.
117  */
118  size_t size() { return _container.size(); };
119 
120 /**
121  * @fn List::size()
122  * @brief This function gets the size of the container.
123  *
124  * @return Returns the size of the container.
125  */
126  size_t size() const{ return _container.size(); };
127 
128 };
129 
130 }
131 
132 #endif /* LIST_H_ */
133 
134 
135 /** @} */
136 /** @} */
device::List
This class is implemented using templates and it is used to maintain a container with the list of sup...
Definition: list.hpp:51
device::List::iterator
std::vector< int >::iterator iterator
An iterator for the container.
Definition: list.hpp:52
device::List::size
size_t size()
This function gets the size of the container.
Definition: list.hpp:118
device::List::at
T & at(size_t i)
This is a template function to get the instance of the calling class against the value at the positio...
Definition: list.hpp:95
device::List::_container
std::vector< int > _container
Vector container for integers to maintain the id's.
Definition: list.hpp:54
device::List::List
List()
This function is the default constructor of class List.
Definition: list.hpp:64
device::List::push_back
void push_back(const T &x)
This is a template function used to push/store the ID of an instance x into the container.
Definition: list.hpp:108
device::List::~List
virtual ~List()
This function is the default destructor of class List and is a virtual function.
Definition: list.hpp:70