00001 #include "AIDA_BaseHistogram.h"
00002 #include "AIDA/IAnnotation.h"
00003 #include "AnnotationNumberFormater.h"
00004
00005
00006 static const std::string nameKey = "Name";
00007 static const std::string entriesKey = "Entries";
00008 static const std::string emptyString = "";
00009
00010 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::AIDA_BaseHistogram( const std::string& title,
00011 const std::string& classType,
00012 int dimension ):
00013 m_annotation( createAnnotation() ),
00014 m_classType( classType ),
00015 m_dimension( dimension ),
00016 m_upToDate( true )
00017 {
00018 m_annotation->addItem( titleKey, title, true );
00019 m_annotation->addItem( nameKey, emptyString, true );
00020 m_annotation->addItem( entriesKey, emptyString, false );
00021 }
00022
00023 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::~AIDA_BaseHistogram()
00024 {
00025 if ( m_annotation ) delete m_annotation;
00026 }
00027
00028
00029 const std::string&
00030 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::title() const
00031 {
00032 return m_annotation->value( titleKey );
00033 }
00034
00035 bool
00036 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::setTitle( const std::string& title )
00037 {
00038 m_annotation->setValue( titleKey, title );
00039 return true;
00040 }
00041
00042 const std::string&
00043 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::name() const
00044 {
00045 return m_annotation->value( nameKey );
00046 }
00047
00048 bool
00049 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::setName( const std::string& name )
00050 {
00051 m_annotation->setValue( nameKey, name );
00052 return true;
00053 }
00054
00055 AIDA::IAnnotation&
00056 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::annotation()
00057 {
00058 updateAnnotation();
00059 return *m_annotation;
00060 }
00061
00062 const
00063 AIDA::IAnnotation&
00064 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::annotation() const
00065 {
00066 updateAnnotation();
00067 return *m_annotation;
00068 }
00069
00070
00071 void
00072 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::updateAnnotation() const
00073 {
00074 AIDA::IAnnotation& anno = const_cast< AIDA::IAnnotation& >( *m_annotation );
00075 anno.setValue( entriesKey, anaphe_annotationNumberFormater.formatInteger( entries() ) );
00076 }
00077
00078
00079 AIDA::IAnnotation&
00080 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::annotationNoUpdate()
00081 {
00082 return *m_annotation;
00083 }
00084
00085
00086 const AIDA::IAnnotation&
00087 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::annotationNoUpdate() const
00088 {
00089 return *m_annotation;
00090 }
00091
00092 #include <memory>
00093 #include <stdexcept>
00094 #include "AIDA_Dev/IDevAnalysisFactory.h"
00095 #include "AIDA_Dev/IAnnotationFactory.h"
00096
00097 AIDA::IAnnotation*
00098 Anaphe::AIDA_Histogram_native::AIDA_BaseHistogram::createAnnotation()
00099 {
00100 std::auto_ptr<AIDA::Dev::IDevAnalysisFactory> af(dynamic_cast<AIDA::Dev::IDevAnalysisFactory*>(AIDA_createAnalysisFactory() ));
00101 if ( ! af.get() ) throw std::runtime_error( "Could not create an analysis factory" );
00102 AIDA::Dev::IAnnotationFactory* anf = af->annotationFactory();
00103 if ( ! anf ) throw std::runtime_error( "Could not find an annotation factory" );
00104 return anf->createAnnotation();
00105 }