2 #ifndef GAUDISVC_ANNOTATION_H 3 #define GAUDISVC_ANNOTATION_H 1 10 #include "AIDA/IAnnotation.h" 35 int size()
const override;
42 void reset()
override;
75 auto iKey = m_identifiers.find( key );
76 if ( iKey == m_identifiers.end() )
return false;
78 unsigned int indexToBeRemoved = iKey->second;
81 if ( m_annotationItems[indexToBeRemoved].m_sticky )
return false;
85 m_identifiers.clear();
87 if ( m_annotationItems.size() > 1 ) annotationItemsNew.
reserve( m_annotationItems.size() - 1 );
88 for (
unsigned int iItem = 0; iItem < m_annotationItems.size(); ++iItem ) {
89 if ( iItem == indexToBeRemoved )
continue;
90 const auto& item = m_annotationItems[iItem];
91 annotationItemsNew.
emplace_back( item.m_key, item.m_value, item.m_sticky );
92 m_identifiers.emplace( item.m_key, annotationItemsNew.
size() - 1 );
94 m_annotationItems =
std::move( annotationItemsNew );
99 auto iKey = m_identifiers.
find( key );
100 return iKey != m_identifiers.end() ? m_annotationItems[iKey->second].m_value : emptyString;
104 auto iKey = m_identifiers.find( key );
105 if ( iKey == m_identifiers.end() )
107 addItem( key, value );
109 m_annotationItems[iKey->second].m_value = value;
113 auto iKey = m_identifiers.find( key );
114 if ( iKey != m_identifiers.end() ) m_annotationItems[iKey->second].m_sticky = sticky;
120 if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) )
return emptyString;
121 return m_annotationItems[index].m_key;
125 if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) )
return emptyString;
126 return m_annotationItems[index].m_value;
133 for (
const auto& item : m_annotationItems ) {
134 if ( !item.m_sticky ) itemsToRemove.
push_back( item.m_key );
136 for (
const auto& i : itemsToRemove ) removeItem( i );
constexpr auto size(const T &, Args &&...) noexcept
void setSticky(const std::string &key, bool sticky) override
Set sticky for a given key.
void setValue(const std::string &key, const std::string &value) override
Set value for a given key.
Internal private annotation item class.
std::string key(int index) const override
Individual access to the Annotation-items.
bool addItem(const std::string &key, const std::string &value, bool sticky=false) override
Add a key/value pair with a given sticky.
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
int size() const override
Get the number of items in the Annotation.
AnnotationItem(std::string k="", std::string v="", bool vis=true)
Implementation of the AIDA IAnnotation interface class.
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
std::string value(const std::string &key) const override
Retrieve the value for a given key.
void reset() override
Remove all the non-sticky items.
~AnnotationItem()=default
bool removeItem(const std::string &key) override
Remove the item indicated by a given key.
T emplace_back(T... args)