00001 #include "AIDA_Filter.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_Filter::AIDA_Filter( CompiledExpressionManager& manager,
00009 const std::string& expression ):
00010 m_manager( manager ),
00011 m_expression( expression ),
00012 m_filter( 0 )
00013 {}
00014
00015
00016 bool
00017 Anaphe::AIDA_Tuple_native::AIDA_Filter::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();
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
00031 std::set<std::string> variablesUsed;
00032 std::auto_ptr< Anaphe::AIDA_Tuple_native::IFilterExpressionBase > filter = m_manager.createFilterExpression( m_expression,
00033 variableTypes,
00034 variablesUsed );
00035 if ( ! filter.get() ) return false;
00036 m_filter = filter;
00037
00038
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_filter->bind( variableAddresses );
00047
00048 return true;
00049 }
00050 catch( std::bad_cast ) {
00051 return false;
00052 }
00053 }
00054
00055
00056 bool
00057 Anaphe::AIDA_Tuple_native::AIDA_Filter::accept() const
00058 {
00059 if ( m_filter.get() ) return m_filter->accept();
00060 else return false;
00061 }
00062
00063
00064 const std::string&
00065 Anaphe::AIDA_Tuple_native::AIDA_Filter::expression() const
00066 {
00067 return m_expression;
00068 }