Gaudi Framework, version v20r2

Generated: 18 Jul 2008

AIDA::Annotation Class Reference

#include <Annotation.h>

Collaboration diagram for AIDA::Annotation:

Collaboration graph
[legend]
List of all members.

Detailed Description

Implementation of the AIDA IAnnotation interface class.

Definition at line 16 of file Annotation.h.

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


Constructor & Destructor Documentation

AIDA::Annotation::Annotation (  )  [inline]

Constructor.

Definition at line 20 of file Annotation.h.

00020 { /* nop */ }

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

Destructor.

Definition at line 23 of file Annotation.h.

00023 { /* 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 81 of file Annotation.h.

References key(), m_annotationItems, m_identifiers, std::make_pair(), and value().

Referenced by setValue().

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

bool AIDA::Annotation::removeItem ( const std::string key  )  [inline]

Remove the item indicated by a given key.

Definition at line 91 of file Annotation.h.

References key(), m_annotationItems, m_identifiers, AIDA::Annotation::AnnotationItem::m_key, AIDA::Annotation::AnnotationItem::m_sticky, AIDA::Annotation::AnnotationItem::m_value, std::make_pair(), std::vector< _Tp, _Alloc >::push_back(), std::vector< _Tp, _Alloc >::reserve(), and std::vector< _Tp, _Alloc >::size().

Referenced by reset().

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

std::string AIDA::Annotation::value ( const std::string key  )  const [inline]

Retrieve the value for a given key.

Definition at line 115 of file Annotation.h.

References emptyString, key(), m_annotationItems, and m_identifiers.

Referenced by addItem(), Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::name(), Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::name(), Gaudi::Generic1D< AIDA::IHistogram1D, TH1D >::name(), setValue(), Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::title(), Gaudi::Generic2D< AIDA::IProfile2D, TProfile2D >::title(), and Gaudi::Generic1D< AIDA::IHistogram1D, TH1D >::title().

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

void AIDA::Annotation::setValue ( const std::string key,
const std::string value 
) [inline]

Set value for a given key.

Definition at line 122 of file Annotation.h.

References addItem(), key(), m_annotationItems, m_identifiers, and value().

Referenced by Gaudi::Generic3D< INTERFACE, IMPLEMENTATION >::setName(), Gaudi::Generic2D< INTERFACE, IMPLEMENTATION >::setName(), Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >::setName(), Gaudi::Generic3D< INTERFACE, IMPLEMENTATION >::setTitle(), Gaudi::Generic2D< INTERFACE, IMPLEMENTATION >::setTitle(), and Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >::setTitle().

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

void AIDA::Annotation::setSticky ( const std::string key,
bool  sticky 
) [inline]

Set sticky for a given key.

Definition at line 132 of file Annotation.h.

References key(), m_annotationItems, and m_identifiers.

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

int AIDA::Annotation::size (  )  const [inline]

Get the number of items in the Annotation.

Definition at line 139 of file Annotation.h.

References m_annotationItems.

Referenced by reset().

00139                                        {
00140   return m_annotationItems.size();
00141 }

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

Individual access to the Annotation-items.

Definition at line 143 of file Annotation.h.

References emptyString, and m_annotationItems.

Referenced by addItem(), removeItem(), setSticky(), setValue(), and value().

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

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

Definition at line 149 of file Annotation.h.

References emptyString, and m_annotationItems.

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

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

Remove all the non-sticky items.

Definition at line 155 of file Annotation.h.

References m_annotationItems, std::vector< _Tp, _Alloc >::push_back(), removeItem(), std::vector< _Tp, _Alloc >::reserve(), std::vector< _Tp, _Alloc >::size(), and size().

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


Member Data Documentation

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

The vector of the annotation items.

Definition at line 72 of file Annotation.h.

Referenced by addItem(), key(), removeItem(), reset(), setSticky(), setValue(), size(), and value().

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

The map of strings to identifiers.

Definition at line 75 of file Annotation.h.

Referenced by addItem(), removeItem(), setSticky(), setValue(), and value().

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

Definition at line 77 of file Annotation.h.

Referenced by key(), and value().


The documentation for this class was generated from the following file:
Generated at Fri Jul 18 12:10:11 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004