19 #include <AIDA/IAnnotation.h>
29 bool addItem(
const std::string&
key,
const std::string&
value,
bool sticky =
false )
override;
35 std::string
value(
const std::string&
key )
const override;
41 void setSticky(
const std::string&
key,
bool sticky )
override;
44 int size()
const override;
47 std::string
key(
int index )
const override;
51 void reset()
override;
84 auto iKey = m_identifiers.find(
key );
85 if ( iKey == m_identifiers.end() )
return false;
87 unsigned int indexToBeRemoved = iKey->second;
90 if ( m_annotationItems[indexToBeRemoved].m_sticky )
return false;
94 m_identifiers.clear();
95 std::vector<AnnotationItem> annotationItemsNew;
96 if ( m_annotationItems.size() > 1 ) annotationItemsNew.reserve( m_annotationItems.size() - 1 );
97 for (
unsigned int iItem = 0; iItem < m_annotationItems.size(); ++iItem ) {
98 if ( iItem == indexToBeRemoved )
continue;
99 const auto& item = m_annotationItems[iItem];
100 annotationItemsNew.emplace_back( item.m_key, item.m_value, item.m_sticky );
101 m_identifiers.emplace( item.m_key, annotationItemsNew.size() - 1 );
103 m_annotationItems = std::move( annotationItemsNew );
108 auto iKey = m_identifiers.find(
key );
109 return iKey != m_identifiers.end() ? m_annotationItems[iKey->second].m_value : emptyString;
113 auto iKey = m_identifiers.find(
key );
114 if ( iKey == m_identifiers.end() )
116 addItem(
key, value );
118 m_annotationItems[iKey->second].m_value = value;
122 auto iKey = m_identifiers.find(
key );
123 if ( iKey != m_identifiers.end() ) m_annotationItems[iKey->second].m_sticky = sticky;
129 if ( index < 0 || index >=
static_cast<int>( m_annotationItems.size() ) )
return emptyString;
130 return m_annotationItems[
index].m_key;
134 if ( index < 0 || index >=
static_cast<int>( m_annotationItems.size() ) )
return emptyString;
135 return m_annotationItems[
index].m_value;
140 std::vector<std::string> itemsToRemove;
141 itemsToRemove.reserve(
size() );
142 for (
const auto& item : m_annotationItems ) {
143 if ( !item.m_sticky ) itemsToRemove.push_back( item.m_key );
145 for (
const auto& i : itemsToRemove ) removeItem( i );