The Gaudi Framework  v40r0 (475e45c1)
AIDA::Annotation Class Reference

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

#include </builds/gaudi/Gaudi/GaudiCommonSvc/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 25 of file Annotation.h.

Member Function Documentation

◆ addItem()

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 76 of file Annotation.h.

76  {
77  if ( m_identifiers.find( key ) != m_identifiers.end() ) return false;
78  m_annotationItems.emplace_back( key, value, sticky );
79  m_identifiers.emplace( key, m_annotationItems.size() - 1 );
80  return true;
81 }

◆ key()

std::string AIDA::Annotation::key ( int  index) const
inlineoverride

Individual access to the Annotation-items.

Definition at line 128 of file Annotation.h.

128  {
129  if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) ) return emptyString;
130  return m_annotationItems[index].m_key;
131 }

◆ removeItem()

bool AIDA::Annotation::removeItem ( const std::string &  key)
inlineoverride

Remove the item indicated by a given key.

Definition at line 83 of file Annotation.h.

83  {
84  auto iKey = m_identifiers.find( key );
85  if ( iKey == m_identifiers.end() ) return false;
86 
87  unsigned int indexToBeRemoved = iKey->second;
88  // check stickness
89 
90  if ( m_annotationItems[indexToBeRemoved].m_sticky ) return false;
91 
92  // why rebuilding ?
93 
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 );
102  }
103  m_annotationItems = std::move( annotationItemsNew );
104  return true;
105 }

◆ reset()

void AIDA::Annotation::reset ( )
inlineoverride

Remove all the non-sticky items.

Definition at line 138 of file Annotation.h.

138  {
139  // Collect the non-sticky items
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 );
144  }
145  for ( const auto& i : itemsToRemove ) removeItem( i );
146 }

◆ setSticky()

void AIDA::Annotation::setSticky ( const std::string &  key,
bool  sticky 
)
inlineoverride

Set sticky for a given key.

Definition at line 121 of file Annotation.h.

121  {
122  auto iKey = m_identifiers.find( key );
123  if ( iKey != m_identifiers.end() ) m_annotationItems[iKey->second].m_sticky = sticky;
124 }

◆ setValue()

void AIDA::Annotation::setValue ( const std::string &  key,
const std::string &  value 
)
inlineoverride

Set value 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() )
115  // if not found, then add it
116  addItem( key, value );
117  else
118  m_annotationItems[iKey->second].m_value = value;
119 }

◆ size()

int AIDA::Annotation::size ( ) const
inlineoverride

Get the number of items in the Annotation.

Definition at line 126 of file Annotation.h.

126 { return m_annotationItems.size(); }

◆ value() [1/2]

std::string AIDA::Annotation::value ( const std::string &  key) const
inlineoverride

Retrieve the value for a given key.

Definition at line 107 of file Annotation.h.

107  {
108  auto iKey = m_identifiers.find( key );
109  return iKey != m_identifiers.end() ? m_annotationItems[iKey->second].m_value : emptyString;
110 }

◆ value() [2/2]

std::string AIDA::Annotation::value ( int  index) const
inlineoverride

Definition at line 133 of file Annotation.h.

133  {
134  if ( index < 0 || index >= static_cast<int>( m_annotationItems.size() ) ) return emptyString;
135  return m_annotationItems[index].m_value;
136 }

Member Data Documentation

◆ emptyString

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

Definition at line 72 of file Annotation.h.

◆ m_annotationItems

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

The vector of the annotation items.

Definition at line 67 of file Annotation.h.

◆ m_identifiers

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

The map of strings to identifiers.

Definition at line 70 of file Annotation.h.


The documentation for this class was generated from the following file:
AIDA::Annotation::addItem
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:76
AIDA::Annotation::key
std::string key(int index) const override
Individual access to the Annotation-items.
Definition: Annotation.h:128
AIDA::Annotation::removeItem
bool removeItem(const std::string &key) override
Remove the item indicated by a given key.
Definition: Annotation.h:83
AIDA::Annotation::emptyString
std::string emptyString
Definition: Annotation.h:72
AIDA::Annotation::value
std::string value(const std::string &key) const override
Retrieve the value for a given key.
Definition: Annotation.h:107
AIDA::Annotation::m_annotationItems
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:67
AIDA::Annotation::size
int size() const override
Get the number of items in the Annotation.
Definition: Annotation.h:126
AIDA::Annotation::m_identifiers
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:70
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39