RTI Connext Modern C++ API  Version 6.1.0
dds::core::policy::DataTag Class Reference

Stores name-value (string) pairs that can be used to determine access permissions. More...

#include <dds/core/policy/CorePolicy.hpp>

Public Types

typedef std::pair< std::string, std::string > Entry
 The type of the elements that DataTag contains. More...
 

Public Member Functions

 DataTag ()
 Creates a policy with an empty sequence of tags. More...
 
template<typename EntryIter >
 DataTag (EntryIter begin, EntryIter end)
 Creates a DataTag container with the entries specified by an iterator range. More...
 
 DataTag (std::initializer_list< Entry > entries)
 <<C++11>> Creates a DataTag container with entries from an initializer_list More...
 
void set (std::initializer_list< Entry > entries)
 <<C++11>> Adds tags from an initializer_list More...
 
bool exists (const std::string &key) const
 Returns true if a tag exists. More...
 
std::string get (const std::string &key) const
 Returns the value of a tag identified by a key if it exists. More...
 
rti::core::optional_value< std::string > try_get (const std::string &key) const
 Returns the value of a tag identified by a key or an empty optional_value if it doesn't exist. More...
 
DataTagset (const Entry &tag)
 Adds or assigns a tag from a pair of strings. More...
 
template<typename EntryIter >
DataTagset (EntryIter begin, EntryIter end)
 Adds a range of tags. More...
 
bool remove (const std::string &key)
 Removes the tag identified by a key. More...
 
size_t size () const
 Returns the number of tags. More...
 
std::map< std::string, std::string > get_all () const
 Retrieves a copy of all the entries in a std::map. More...
 

Detailed Description

Stores name-value (string) pairs that can be used to determine access permissions.

Entity:
dds::sub::DataReader dds::pub::DataWriter
Properties:
RxO = N/A;
Changeable = NO

Usage

The DATA_TAG QoS policy can be used to associate a set of tags in the form of (name, value) pairs with a dds::sub::DataReader or dds::pub::DataWriter. This is similar to the rti::core::policy::Property, except for the following differences:

  • Data tags are always propagated. You cannot select whether or not a particular pair should be propagated.
  • Connext passes data tags to the Access Control Security Plugin, which may use them to decide whether to allow or deny the corresponding entities.

There are helper functions to facilitate working with data tags. See the DATA_TAG page.

Member Typedef Documentation

◆ Entry

typedef std::pair<std::string, std::string> dds::core::policy::DataTag::Entry

The type of the elements that DataTag contains.

Key/value string pairs.

Constructor & Destructor Documentation

◆ DataTag() [1/3]

dds::core::policy::DataTag::DataTag ( )
inline

Creates a policy with an empty sequence of tags.

◆ DataTag() [2/3]

template<typename EntryIter >
dds::core::policy::DataTag::DataTag ( EntryIter  begin,
EntryIter  end 
)
inline

Creates a DataTag container with the entries specified by an iterator range.

See also
set(EntryIter, EntryIter)

◆ DataTag() [3/3]

dds::core::policy::DataTag::DataTag ( std::initializer_list< Entry entries)
inline

<<C++11>> Creates a DataTag container with entries from an initializer_list

For example:

DataTag my_tags {{"key 1", "value 1"}, {"key 2", "value 2"}};

If a key is duplicated, only one entry will be inserted, with the value that comes last.

Member Function Documentation

◆ set() [1/3]

void dds::core::policy::DataTag::set ( std::initializer_list< Entry entries)
inline

<<C++11>> Adds tags from an initializer_list

◆ exists()

bool dds::core::policy::DataTag::exists ( const std::string &  key) const
inline

Returns true if a tag exists.

◆ get()

std::string dds::core::policy::DataTag::get ( const std::string &  key) const
inline

Returns the value of a tag identified by a key if it exists.

If the tag doesn't exist it throws dds::core::PreconditionNotMetError.

◆ try_get()

rti::core::optional_value<std::string> dds::core::policy::DataTag::try_get ( const std::string &  key) const
inline

Returns the value of a tag identified by a key or an empty optional_value if it doesn't exist.

◆ set() [2/3]

DataTag& dds::core::policy::DataTag::set ( const Entry tag)
inline

Adds or assigns a tag from a pair of strings.

If the key doesn't exist it adds the new entry. Otherwise it overrides its value with the new one.

Parameters
tagtag.first is the key and tag.second is the value

◆ set() [3/3]

template<typename EntryIter >
DataTag& dds::core::policy::DataTag::set ( EntryIter  begin,
EntryIter  end 
)
inline

Adds a range of tags.

If a key is duplicated, only one entry will remain, with the value that comes last.

Template Parameters
EntryIterA forward iterator whose value type is DataTag::Entry, such as the iterators of a std::map<std::string, std::string>.
Parameters
beginBeginning of a range of Entry
endEnd of that range

◆ remove()

bool dds::core::policy::DataTag::remove ( const std::string &  key)
inline

Removes the tag identified by a key.

Returns
true if the tag was removed or false if it didn't exist.

◆ size()

size_t dds::core::policy::DataTag::size ( ) const
inline

Returns the number of tags.

◆ get_all()

std::map<std::string, std::string> dds::core::policy::DataTag::get_all ( ) const
inline

Retrieves a copy of all the entries in a std::map.