Skip to content

iox::popo::TypedUniqueId🔗

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>

Public Functions🔗

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

Detailed Description🔗

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

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.

Parameters:

  • T type for which the unique ids should be generated
        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();

Public Functions Documentation🔗

function TypedUniqueId🔗

inline TypedUniqueId()

the constructor creates an id which is greater than the previous created id

function TypedUniqueId🔗

inline TypedUniqueId(
    InvalidId_t 
)

constructor which creates an invalid id

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

function isValid🔗

inline bool isValid() const

Updated on 17 June 2021 at 11:15:27 CEST