2 #ifndef GAUDISVC_ANNOTATION_H
3 #define GAUDISVC_ANNOTATION_H 1
12 #include "AIDA/IAnnotation.h"
29 const std::string &
value,
36 std::string
value(
const std::string &
key)
const;
40 const std::string&
value);
50 std::string
key(
int index)
const;
51 std::string
value(
int index)
const;
84 const std::string &
value,
94 std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
95 if ( iKey == m_identifiers.end() )
return false;
97 unsigned int indexToBeRemoved = iKey->second;
100 if ( m_annotationItems[indexToBeRemoved].m_sticky )
return false;
104 m_identifiers.clear();
105 std::vector< AnnotationItem > m_annotationItemsNew;
106 if ( m_annotationItems.size() > 1 ) m_annotationItemsNew.reserve( m_annotationItems.size() - 1 );
107 for (
unsigned int iItem = 0; iItem < m_annotationItems.size(); ++iItem ) {
108 if ( iItem == indexToBeRemoved )
continue;
111 m_identifiers.insert( std::make_pair( item.
m_key, m_annotationItemsNew.size() - 1 ) );
113 m_annotationItems = m_annotationItemsNew;
119 std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
120 if ( iKey == m_identifiers.end() )
return emptyString;
121 return ( m_annotationItems[ iKey->second ] ).m_value;
126 std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
127 if ( iKey == m_identifiers.end() )
131 ( m_annotationItems[ iKey->second ] ).m_value =
value;
136 std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
137 if ( iKey == m_identifiers.end() )
return;
138 ( m_annotationItems[ iKey->second ] ).m_sticky = sticky;
142 return m_annotationItems.size();
147 if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) )
return emptyString;
148 return ( m_annotationItems[ index ] ).m_key;
153 if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) )
return emptyString;
154 return ( m_annotationItems[ index ] ).m_value;
160 std::vector< std::string > itemsToRemove;
161 itemsToRemove.reserve( size() );
163 if ( ! ( m_annotationItems[
item ] ).m_sticky ) {
164 itemsToRemove.push_back( ( m_annotationItems[ item ] ).m_key );
168 for (
unsigned int i = 0;
i < itemsToRemove.size(); ++
i ) removeItem( itemsToRemove[
i] );
virtual ~Annotation()
Destructor.
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
AnnotationItem(std::string k="", std::string v="", bool vis=true)
bool removeItem(const std::string &key)
Remove the item indicated by a given key.
std::string value(const std::string &key) const
Retrieve the value for a given key.
Implementation of the AIDA IAnnotation interface class.
bool addItem(const std::string &key, const std::string &value, bool sticky=false)
Add a key/value pair with a given sticky.
void reset()
Remove all the non-sticky items.
std::string key(int index) const
Individual access to the Annotation-items.
int size() const
Get the number of items in the Annotation.
void setSticky(const std::string &key, bool sticky)
Set sticky for a given key.
Internal private annotation item class.
void setValue(const std::string &key, const std::string &value)
Set value for a given key.
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.