51Degrees Device Detection C/C++  4.4

A device detection library that is used natively or by 51Degrees products

FiftyoneDegrees::Common::Collection< K, V > Class Template Reference abstract

Detailed Description

template<class K, class V>
class FiftyoneDegrees::Common::Collection< K, V >

A group of items accessible by index or key.

A Collection instance hands out new instances of any item requested so once they are finished with, they must be deleted. A static object is not returned, as this would require any type V to declare a default constructor in the case that the caller declares a variable before calling a get method.

Usage Example

// Iterate over all indexes
for (int i = 0; i < collection->getSize(); i++) {
// Get the value for the current index
string *value = collection->getByIndex(i);
// Do something with the value
// ...
// Delete the value instance
delete value;
// Or get a value using it's key of type <T>
string *value = collection->getByKey("string type key");
// Do something with the value
// ...
// Delete the value instance
delete value;
Template Parameters
K - key type for the items in the collection which must be unique e.g. string is used for property meta data where the unique key is the name of the property. The type K must implement the '<' and '==' operators
V - value type for the items stored in the collection. These must be instantiatable by the collection, and should implement a public destructor as their lifetimes are not handled by the collection instance

Inheritance diagram for FiftyoneDegrees::Common::Collection< K, V >:


Public Member Functions


virtual  ~Collection ()
Dispose of any internal data.


virtual V *  getByIndex (uint32_t index) const =0
Get the item from the collection at the index provided. More...
virtual V *  getByKey (K key) const =0
Get the item for the key from the collection. More...
virtual uint32_t  getSize () const =0
Number of items in the underlying collection. More...

Protected Member Functions

 Collection ()
A collection can't be constructed without an inheriting class.

Member Function Documentation

◆ getByIndex()

◆ getByKey()

◆ getSize()

The documentation for this class was generated from the following file:
  • /home/runner/work/device-detection-cxx/device-detection-cxx/common/device-detection-cxx/src/common-cxx/Collection.hpp