The Gaudi Framework  v31r0 (aeb156f0)
AIDA::Annotation Class Reference

Implementation of the AIDA IAnnotation interface class. More...

#include <GaudiCommonSvc/Annotation.h>

Inheritance diagram for AIDA::Annotation:
Collaboration diagram for AIDA::Annotation:

Classes

struct  AnnotationItem
 Internal private annotation item class. More...
 

Public Member Functions

bool addItem (const std::string &key, const std::string &value, bool sticky=false) override
 Add a key/value pair with a given sticky. More...
 
bool removeItem (const std::string &key) override
 Remove the item indicated by a given key. More...
 
std::string value (const std::string &key) const override
 Retrieve the value for a given key. More...
 
void setValue (const std::string &key, const std::string &value) override
 Set value for a given key. More...
 
void setSticky (const std::string &key, bool sticky) override
 Set sticky for a given key. More...
 
int size () const override
 Get the number of items in the Annotation. More...
 
std::string key (int index) const override
 Individual access to the Annotation-items. More...
 
std::string value (int index) const override
 
void reset () override
 Remove all the non-sticky items. More...
 

Private Attributes

std::vector< AnnotationItemm_annotationItems
 The vector of the annotation items. More...
 
std::map< std::string, unsigned int > m_identifiers
 The map of strings to identifiers. More...
 
std::string emptyString
 

Detailed Description

Implementation of the AIDA IAnnotation interface class.

Definition at line 16 of file Annotation.h.

Member Function Documentation

bool AIDA::Annotation::addItem ( const std::string key,
const std::string value,
bool  sticky = false 
)
inlineoverride

Add a key/value pair with a given sticky.

Definition at line 67 of file Annotation.h.

67  {
68  if ( m_identifiers.find( key ) != m_identifiers.end() ) return false;
69  m_annotationItems.emplace_back( key, value, sticky );
70  m_identifiers.emplace( key, m_annotationItems.size() - 1 );
71  return true;
72 }
T end(T...args)
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:61
T find(T...args)
T emplace(T...args)
std::string AIDA::Annotation::key ( int  index) const
inlineoverride

Individual access to the Annotation-items.

Definition at line 119 of file Annotation.h.

119  {
120  if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) ) return emptyString;
121  return m_annotationItems[index].m_key;
122 }
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::string emptyString
Definition: Annotation.h:63
bool AIDA::Annotation::removeItem ( const std::string key)
inlineoverride

Remove the item indicated by a given key.

Definition at line 74 of file Annotation.h.

74  {
75  auto iKey = m_identifiers.find( key );
76  if ( iKey == m_identifiers.end() ) return false;
77 
78  unsigned int indexToBeRemoved = iKey->second;
79  // check stickness
80 
81  if ( m_annotationItems[indexToBeRemoved].m_sticky ) return false;
82 
83  // why rebuilding ?
84 
86  std::vector<AnnotationItem> annotationItemsNew;
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 );
93  }
94  m_annotationItems = std::move( annotationItemsNew );
95  return true;
96 }
T end(T...args)
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
T clear(T...args)
T move(T...args)
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:61
T find(T...args)
T size(T...args)
STL class.
T emplace(T...args)
T reserve(T...args)
T emplace_back(T...args)
void AIDA::Annotation::reset ( )
inlineoverride

Remove all the non-sticky items.

Definition at line 129 of file Annotation.h.

129  {
130  // Collect the non-sticky items
131  std::vector<std::string> itemsToRemove;
132  itemsToRemove.reserve( size() );
133  for ( const auto& item : m_annotationItems ) {
134  if ( !item.m_sticky ) itemsToRemove.push_back( item.m_key );
135  }
136  for ( const auto& i : itemsToRemove ) removeItem( i );
137 }
int size() const override
Get the number of items in the Annotation.
Definition: Annotation.h:117
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
T push_back(T...args)
bool removeItem(const std::string &key) override
Remove the item indicated by a given key.
Definition: Annotation.h:74
T reserve(T...args)
void AIDA::Annotation::setSticky ( const std::string key,
bool  sticky 
)
inlineoverride

Set sticky for a given key.

Definition at line 112 of file Annotation.h.

112  {
113  auto iKey = m_identifiers.find( key );
114  if ( iKey != m_identifiers.end() ) m_annotationItems[iKey->second].m_sticky = sticky;
115 }
T end(T...args)
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:61
T find(T...args)
void AIDA::Annotation::setValue ( const std::string key,
const std::string value 
)
inlineoverride

Set value for a given key.

Definition at line 103 of file Annotation.h.

103  {
104  auto iKey = m_identifiers.find( key );
105  if ( iKey == m_identifiers.end() )
106  // if not found, then add it
107  addItem( key, value );
108  else
109  m_annotationItems[iKey->second].m_value = value;
110 }
T end(T...args)
bool addItem(const std::string &key, const std::string &value, bool sticky=false) override
Add a key/value pair with a given sticky.
Definition: Annotation.h:67
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:61
T find(T...args)
std::string value(const std::string &key) const override
Retrieve the value for a given key.
Definition: Annotation.h:98
int AIDA::Annotation::size ( ) const
inlineoverride

Get the number of items in the Annotation.

Definition at line 117 of file Annotation.h.

117 { return m_annotationItems.size(); }
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::string AIDA::Annotation::value ( const std::string key) const
inlineoverride

Retrieve the value for a given key.

Definition at line 98 of file Annotation.h.

98  {
99  auto iKey = m_identifiers.find( key );
100  return iKey != m_identifiers.end() ? m_annotationItems[iKey->second].m_value : emptyString;
101 }
T end(T...args)
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::string emptyString
Definition: Annotation.h:63
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:61
T find(T...args)
std::string AIDA::Annotation::value ( int  index) const
inlineoverride

Definition at line 124 of file Annotation.h.

124  {
125  if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) ) return emptyString;
126  return m_annotationItems[index].m_value;
127 }
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:58
std::string emptyString
Definition: Annotation.h:63

Member Data Documentation

std::string AIDA::Annotation::emptyString
private

Definition at line 63 of file Annotation.h.

std::vector<AnnotationItem> AIDA::Annotation::m_annotationItems
private

The vector of the annotation items.

Definition at line 58 of file Annotation.h.

std::map<std::string, unsigned int> AIDA::Annotation::m_identifiers
private

The map of strings to identifiers.

Definition at line 61 of file Annotation.h.


The documentation for this class was generated from the following file: