All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AIDA::Annotation Class Reference

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

#include <src/HistogramSvc/Annotation.h>

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

Classes

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

Public Member Functions

 Annotation ()
 Constructor. More...
 
virtual ~Annotation ()
 Destructor. More...
 
bool addItem (const std::string &key, const std::string &value, bool sticky=false)
 Add a key/value pair with a given sticky. More...
 
bool removeItem (const std::string &key)
 Remove the item indicated by a given key. More...
 
std::string value (const std::string &key) const
 Retrieve the value for a given key. More...
 
void setValue (const std::string &key, const std::string &value)
 Set value for a given key. More...
 
void setSticky (const std::string &key, bool sticky)
 Set sticky for a given key. More...
 
int size () const
 Get the number of items in the Annotation. More...
 
std::string key (int index) const
 Individual access to the Annotation-items. More...
 
std::string value (int index) const
 
void reset ()
 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 18 of file Annotation.h.

Constructor & Destructor Documentation

AIDA::Annotation::Annotation ( )
inline

Constructor.

Definition at line 22 of file Annotation.h.

22 { /* nop */ }
virtual AIDA::Annotation::~Annotation ( )
inlinevirtual

Destructor.

Definition at line 25 of file Annotation.h.

25 { /* nop */ }

Member Function Documentation

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

Add a key/value pair with a given sticky.

Definition at line 83 of file Annotation.h.

86 {
87  if ( m_identifiers.find( key ) != m_identifiers.end() ) return false;
88  m_annotationItems.push_back( AnnotationItem( key, value, sticky ) );
89  m_identifiers.insert( std::make_pair( key, m_annotationItems.size() - 1 ) );
90  return true;
91 }
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:77
std::string value(const std::string &key) const
Retrieve the value for a given key.
Definition: Annotation.h:117
std::string key(int index) const
Individual access to the Annotation-items.
Definition: Annotation.h:145
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
std::string AIDA::Annotation::key ( int  index) const
inline

Individual access to the Annotation-items.

Definition at line 145 of file Annotation.h.

146 {
147  if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) return emptyString;
148  return ( m_annotationItems[ index ] ).m_key;
149 }
std::string emptyString
Definition: Annotation.h:79
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
bool AIDA::Annotation::removeItem ( const std::string &  key)
inline

Remove the item indicated by a given key.

Definition at line 93 of file Annotation.h.

93  {
94  std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
95  if ( iKey == m_identifiers.end() ) return false;
96 
97  unsigned int indexToBeRemoved = iKey->second;
98  // check stickness
99 
100  if ( m_annotationItems[indexToBeRemoved].m_sticky ) return false;
101 
102  // why rebuilding ?
103 
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;
109  const AnnotationItem& item = m_annotationItems[ iItem ];
110  m_annotationItemsNew.push_back( AnnotationItem( item.m_key, item.m_value, item.m_sticky ) );
111  m_identifiers.insert( std::make_pair( item.m_key, m_annotationItemsNew.size() - 1 ) );
112  }
113  m_annotationItems = m_annotationItemsNew;
114  return true;
115 }
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:77
std::string key(int index) const
Individual access to the Annotation-items.
Definition: Annotation.h:145
tuple item
print s1,s2
Definition: ana.py:146
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
void AIDA::Annotation::reset ( )
inline

Remove all the non-sticky items.

Definition at line 157 of file Annotation.h.

158 {
159  // Collect the non-sticky items
160  std::vector< std::string > itemsToRemove;
161  itemsToRemove.reserve( size() );
162  for ( int item = 0; item < size(); ++item ) {
163  if ( ! ( m_annotationItems[ item ] ).m_sticky ) {
164  itemsToRemove.push_back( ( m_annotationItems[ item ] ).m_key );
165  }
166  }
167 
168  for ( unsigned int i = 0; i < itemsToRemove.size(); ++i ) removeItem( itemsToRemove[i] );
169 }
bool removeItem(const std::string &key)
Remove the item indicated by a given key.
Definition: Annotation.h:93
int size() const
Get the number of items in the Annotation.
Definition: Annotation.h:141
tuple item
print s1,s2
Definition: ana.py:146
list i
Definition: ana.py:128
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
void AIDA::Annotation::setSticky ( const std::string &  key,
bool  sticky 
)
inline

Set sticky for a given key.

Definition at line 134 of file Annotation.h.

135 {
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;
139 }
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:77
std::string key(int index) const
Individual access to the Annotation-items.
Definition: Annotation.h:145
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
void AIDA::Annotation::setValue ( const std::string &  key,
const std::string &  value 
)
inline

Set value for a given key.

Definition at line 124 of file Annotation.h.

125 {
126  std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
127  if ( iKey == m_identifiers.end() )
128  // not found then add it
129  addItem(key,value);
130  else
131  ( m_annotationItems[ iKey->second ] ).m_value = value;
132 }
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:77
std::string value(const std::string &key) const
Retrieve the value for a given key.
Definition: Annotation.h:117
bool addItem(const std::string &key, const std::string &value, bool sticky=false)
Add a key/value pair with a given sticky.
Definition: Annotation.h:83
std::string key(int index) const
Individual access to the Annotation-items.
Definition: Annotation.h:145
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
int AIDA::Annotation::size ( ) const
inline

Get the number of items in the Annotation.

Definition at line 141 of file Annotation.h.

141  {
142  return m_annotationItems.size();
143 }
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
std::string AIDA::Annotation::value ( const std::string &  key) const
inline

Retrieve the value for a given key.

Definition at line 117 of file Annotation.h.

118 {
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;
122 }
std::map< std::string, unsigned int > m_identifiers
The map of strings to identifiers.
Definition: Annotation.h:77
std::string emptyString
Definition: Annotation.h:79
std::string key(int index) const
Individual access to the Annotation-items.
Definition: Annotation.h:145
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74
std::string AIDA::Annotation::value ( int  index) const
inline

Definition at line 151 of file Annotation.h.

152 {
153  if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) return emptyString;
154  return ( m_annotationItems[ index ] ).m_value;
155 }
std::string emptyString
Definition: Annotation.h:79
std::vector< AnnotationItem > m_annotationItems
The vector of the annotation items.
Definition: Annotation.h:74

Member Data Documentation

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

Definition at line 79 of file Annotation.h.

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

The vector of the annotation items.

Definition at line 74 of file Annotation.h.

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

The map of strings to identifiers.

Definition at line 77 of file Annotation.h.


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