| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# AIDA::Annotation Class Reference

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

`#include <Annotation.h>`

Inheritance diagram for AIDA::Annotation:

[legend]
Collaboration diagram for AIDA::Annotation:

[legend]

List of all members.

## Public Member Functions
| Annotation ()
| Constructor.
| ~Annotation ()
| Destructor.
bool | addItem (const std::string &key, const std::string &value, bool sticky=false)
| Add a key/value pair with a given sticky.
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.
void | setValue (const std::string &key, const std::string &value)
| Set value for a given key.
void | setSticky (const std::string &key, bool sticky)
| Set sticky for a given key.
int | size () const
| Get the number of items in the Annotation.
std::string | key (int index) const
| Individual access to the Annotation-items.
std::string | value (int index) const
void | reset ()
| Remove all the non-sticky items.
## Private Attributes
std::vector< AnnotationItem > | m_annotationItems
| The vector of the annotation items.
std::map< std::string, unsigned int > | m_identifiers
| The map of strings to identifiers.
std::string | emptyString
## Classes
class | AnnotationItem
| Internal private annotation item class. More...

## 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.

    00022 { /* nop */ }

AIDA::Annotation::~Annotation | ( |  | ) | `[inline]`

Destructor.

Definition at line 25 of file Annotation.h.

    00025 { /* 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.

    00086 {
    00087   if ( m_identifiers.find( key ) != m_identifiers.end() ) return false;
    00088   m_annotationItems.push_back( AnnotationItem( key, value, sticky ) );
    00089   m_identifiers.insert( std::make_pair( key, m_annotationItems.size() - 1 ) );
    00090   return true;
    00091 }

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.

    00093                                                                {
    00094   std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
    00095   if ( iKey == m_identifiers.end() ) return false;
    00096
    00097   unsigned int indexToBeRemoved = iKey->second;
    00098   // check stickness
    00099
    00100   if (  m_annotationItems[indexToBeRemoved].m_sticky ) return false;
    00101
    00102   // why rebuilding ?
    00103
    00104   m_identifiers.clear();
    00105   std::vector< AnnotationItem > m_annotationItemsNew;
    00106   if ( m_annotationItems.size() > 1 ) m_annotationItemsNew.reserve( m_annotationItems.size() - 1 );
    00107   for ( unsigned int iItem = 0; iItem < m_annotationItems.size(); ++iItem ) {
    00108     if ( iItem == indexToBeRemoved ) continue;
    00109     const AnnotationItem& item = m_annotationItems[ iItem ];
    00110     m_annotationItemsNew.push_back( AnnotationItem( item.m_key, item.m_value, item.m_sticky ) );
    00111     m_identifiers.insert( std::make_pair( item.m_key, m_annotationItemsNew.size() - 1 ) );
    00112   }
    00113   m_annotationItems = m_annotationItemsNew;
    00114   return true;
    00115 }

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.

    00118 {
    00119   std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
    00120   if ( iKey == m_identifiers.end() ) return emptyString;
    00121   return ( m_annotationItems[ iKey->second ] ).m_value;
    00122 }

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.

    00125 {
    00126   std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
    00127   if ( iKey == m_identifiers.end() )
    00128     // not found then add it
    00129     addItem(key,value);
    00130   else
    00131     ( m_annotationItems[ iKey->second ] ).m_value = value;
    00132 }

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.

    00135 {
    00136   std::map< std::string, unsigned int >::const_iterator iKey = m_identifiers.find( key );
    00137   if ( iKey == m_identifiers.end() ) return;
    00138   ( m_annotationItems[ iKey->second ] ).m_sticky = sticky;
    00139 }

int AIDA::Annotation::size | ( | void |  | ) | const`[inline]`

Get the number of items in the Annotation.

Definition at line 141 of file Annotation.h.

    00141                                        {
    00142   return m_annotationItems.size();
    00143 }

std::string AIDA::Annotation::key | ( | int | index | ) | const`[inline]`

Individual access to the Annotation-items.

Definition at line 145 of file Annotation.h.

    00146 {
    00147   if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) return emptyString;
    00148   return ( m_annotationItems[ index ] ).m_key;
    00149 }

std::string AIDA::Annotation::value | ( | int | index | ) | const`[inline]`

Definition at line 151 of file Annotation.h.

    00152 {
    00153   if ( index < 0 || index >= static_cast<int>(m_annotationItems.size()) ) return emptyString;
    00154   return ( m_annotationItems[ index ] ).m_value;
    00155 }

void AIDA::Annotation::reset | ( |  | ) | `[inline]`

Remove all the non-sticky items.

Definition at line 157 of file Annotation.h.

    00158 {
    00159   // Collect the non-sticky items
    00160   std::vector< std::string > itemsToRemove;
    00161   itemsToRemove.reserve( size() );
    00162   for ( int item = 0; item < size(); ++item ) {
    00163     if ( ! ( m_annotationItems[ item ] ).m_sticky ) {
    00164       itemsToRemove.push_back( ( m_annotationItems[ item ] ).m_key );
    00165     }
    00166   }
    00167
    00168   for ( unsigned int i = 0; i < itemsToRemove.size(); ++i ) removeItem( itemsToRemove[i] );
    00169 }

## Member Data Documentation

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.

std::string AIDA::Annotation::emptyString`[private]`

Definition at line 79 of file Annotation.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r8/GaudiSvc/src/HistogramSvc/Annotation.h