2 #ifndef GAUDISVC_ANNOTATION_H 
    3 #define GAUDISVC_ANNOTATION_H 1 
   12 #include "AIDA/IAnnotation.h" 
   29                 const std::string & 
value,
 
   30                 bool sticky = 
false) 
override;
 
   33   bool removeItem( 
const std::string & key ) 
override;
 
   36   std::string 
value( 
const std::string & key) 
const override;
 
   39   void setValue( 
const std::string & key,
 
   40                  const std::string& value) 
override;
 
   44                   bool sticky) 
override;
 
   47   int size() 
const override;
 
   50   std::string  
key(
int index) 
const override;
 
   51   std::string  
value(
int index) 
const override;
 
   54   void reset() 
override;
 
   81                               const std::string & 
value,
 
   91   auto iKey = m_identifiers.find( key );
 
   92   if ( iKey == m_identifiers.end() ) 
return false;
 
   94   unsigned int indexToBeRemoved = iKey->second;
 
   97   if (  m_annotationItems[indexToBeRemoved].m_sticky ) 
return false;
 
  101   m_identifiers.clear();
 
  102   std::vector< AnnotationItem > annotationItemsNew;
 
  103   if ( m_annotationItems.size() > 1 ) annotationItemsNew.reserve( m_annotationItems.size() - 1 );
 
  104   for ( 
unsigned int iItem = 0; iItem < m_annotationItems.size(); ++iItem ) {
 
  105     if ( iItem == indexToBeRemoved ) 
continue;
 
  106     const auto& 
item = m_annotationItems[ iItem ];
 
  107     annotationItemsNew.emplace_back( 
item.m_key, 
item.m_value, 
item.m_sticky );
 
  108     m_identifiers.emplace( 
item.m_key, annotationItemsNew.size() - 1 );
 
  110   m_annotationItems = std::move(annotationItemsNew);
 
  116   auto iKey = m_identifiers.find( key );
 
  117   return iKey != m_identifiers.end() ? m_annotationItems[ iKey->second ].m_value 
 
  123   auto iKey = m_identifiers.find( key );
 
  124   if ( iKey == m_identifiers.end() )
 
  128     m_annotationItems[ iKey->second ].m_value = 
value;
 
  133   auto iKey = m_identifiers.find( key );
 
  134   if ( iKey != m_identifiers.end() ) m_annotationItems[ iKey->second ].m_sticky = sticky;
 
  138   return m_annotationItems.size();
 
  143   if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) 
return emptyString;
 
  144   return m_annotationItems[ index ].m_key;
 
  149   if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) 
return emptyString;
 
  150   return m_annotationItems[ index ].m_value;
 
  156   std::vector< std::string > itemsToRemove;
 
  157   itemsToRemove.reserve( size() );
 
  158   for ( 
const auto& 
item : m_annotationItems ) {
 
  159     if ( !
item.m_sticky ) itemsToRemove.push_back( 
item.m_key );
 
  161   for ( 
const auto& 
i : itemsToRemove ) removeItem(
i);
 
void setSticky(const std::string &key, bool sticky) override
Set sticky for a given key. 
 
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers. 
 
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. 
 
~Annotation() override=default
Destructor. 
 
bool addItem(const std::string &key, const std::string &value, bool sticky=false) override
Add a key/value pair with a given sticky. 
 
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. 
 
Annotation()=default
Constructor. 
 
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. 
 
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.