iceoryx_doc  1.0.1
Public Member Functions | List of all members
iox::popo::TypedUniqueId< T > Class Template Reference

Unique ID depending on a type. If you would like to assign different types consistent unique ids use this class. Every types gets its own distinct set of ids starting with 0. If the types are the same the ids are the same. More...

#include <typed_unique_id.hpp>

Inheritance diagram for iox::popo::TypedUniqueId< T >:
Inheritance graph
[legend]
Collaboration diagram for iox::popo::TypedUniqueId< T >:
Collaboration graph
[legend]

Public Member Functions

 TypedUniqueId () noexcept
 the constructor creates an id which is greater than the previous created id
 
 TypedUniqueId (InvalidId_t) noexcept
 constructor which creates an invalid id More...
 
bool isValid () const noexcept
 

Detailed Description

template<typename T>
class iox::popo::TypedUniqueId< T >

Unique ID depending on a type. If you would like to assign different types consistent unique ids use this class. Every types gets its own distinct set of ids starting with 0. If the types are the same the ids are the same.

struct MyClass {
// some members;
iox::port::TypedUniqueId<MyClass> id;
};
struct MySecondClass {
// some members;
iox::port::TypedUniqueId<MySecondClass> id;
};
//
std::vector<MyClass> myClassVector;
std::vector<MyClass> mySecondClassVector;
uint64_t AddClass() {
myClassVector.emplace_back();
return myClassVector.back().id.getID();
}
uint64_t AddSecondClass() {
mySecondClassVector.emplace_back();
// we use the uint64_t conversion
return mySecondClassVector.back().id;
}
void RemoveClass(const uint64_t id) {
auto iter = std::find_if(myClassVector.begin(), myClassVector.end(), [&](MyClass & c){ return c.id == id;});
if ( iter != myClassVector.end() ) myClassVector.erase(iter);
}
uint64_t id = AddClass();
RemoveClass(id);
// it can be that id == id2 since the id is unique per type
uint64_t id2 = AddSecondClass();
Parameters
[in]Ttype for which the unique ids should be generated

Constructor & Destructor Documentation

◆ TypedUniqueId()

template<typename T >
iox::popo::TypedUniqueId< T >::TypedUniqueId ( InvalidId_t  )
inlinenoexcept

constructor which creates an invalid id

we have to cast INVALID_UNIQUE_ID with static_cast<uint64_t> otherwise it will not link with gcc-7.x - gcc-10.x. Who knows why?!


The documentation for this class was generated from the following files: