Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AIDA_Evaluator.cpp

Go to the documentation of this file.
00001 #include "AIDA_Evaluator.h"
00002 #include "CompiledExpressionManager.h"
00003 #include "AIDA_Dev/IDevTuple.h"
00004 #include "AIDA_Dev/ITupleHeader.h"
00005 #include "AIDA_Dev/ITupleVariableDescription.h"
00006 #include <typeinfo>
00007 
00008 Anaphe::AIDA_Tuple_native::AIDA_Evaluator::AIDA_Evaluator( CompiledExpressionManager& manager,
00009                                                            const std::string& expression ):
00010   m_manager( manager ),
00011   m_expression( expression ),
00012   m_evaluator( 0 )
00013 {}
00014 
00015 
00016 bool
00017 Anaphe::AIDA_Tuple_native::AIDA_Evaluator::initialize( AIDA::ITuple & tuple )
00018 {
00019   try{
00020     AIDA::Dev::IDevTuple& tp = dynamic_cast<AIDA::Dev::IDevTuple&>( tuple );
00021     AIDA::Dev::ITupleHeader& header = tp.header(); // Fetch the variables and their types
00022     std::map<std::string, std::string> variableTypes;
00023     int numberOfVariables = header.numberOfVariables();
00024     for ( int i = 0; i < numberOfVariables; ++i ) {
00025       const std::string& variableName = header.variableDescription(i)->variableName();
00026       const std::string& variableType = header.variableDescription(i)->variableType();
00027       variableTypes.insert( std::make_pair( variableName, variableType ) );
00028     }
00029 
00030     // Create the object
00031     std::set<std::string> variablesUsed;
00032     std::auto_ptr<Anaphe::AIDA_Tuple_native::IEvaluatorExpressionBase> evaluator = m_manager.createEvaluatorExpression( m_expression,
00033                                                                                                                         variableTypes,
00034                                                                                                                         variablesUsed );
00035     if ( ! evaluator.get() ) return false;
00036     m_evaluator = evaluator;
00037 
00038     // Bind the variables
00039     std::map<std::string, void*> variableAddresses;
00040     for ( std::set<std::string>::const_iterator iVariable = variablesUsed.begin();
00041           iVariable != variablesUsed.end(); ++iVariable ) {
00042       void* p = tp.variableAddress( *iVariable );
00043       if ( !p ) return false;
00044       variableAddresses.insert( std::make_pair( *iVariable, p ) );
00045     }
00046     m_evaluator->bind( variableAddresses );
00047 
00048     return true;
00049   }
00050   catch( std::bad_cast ) {
00051     return false;
00052   }
00053 }
00054 
00055 
00056 double
00057 Anaphe::AIDA_Tuple_native::AIDA_Evaluator::evaluateDouble() const
00058 {
00059   if ( m_evaluator.get() ) return m_evaluator->evaluate();
00060   else return false;
00061 }
00062 
00063 
00064 const std::string&
00065 Anaphe::AIDA_Tuple_native::AIDA_Evaluator::expression() const
00066 {
00067   return m_expression;
00068 }

Generated on Tue Feb 18 17:51:19 2003 for AIDA_Tuple_native by doxygen1.2.16