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

TupleVariableCopy.cpp

Go to the documentation of this file.
00001 #include "TupleVariableCopy.h"
00002 #include <vector>
00003 #include <string>
00004 
00005 static const std::string doubleType = "double";
00006 static const std::string floatType = "float";
00007 static const std::string intType = "int";
00008 static const std::string shortType = "short";
00009 static const std::string longType = "long";
00010 static const std::string charType = "char";
00011 static const std::string boolType = "bool";
00012 static const std::string stringType = "std::string";
00013 static const std::string tupleType = "AIDA::ITuple";
00014 
00015 void
00016 Anaphe::AIDA_Tuple_native::TupleVarialbeCopyTuple::copyTupleVariable( const AIDA::ITuple& tupleFrom,
00017                                                                       int columnFrom,
00018                                                                       AIDA::ITuple& tupleTo,
00019                                                                       int columnTo ) const
00020 {
00021   // Get the sub tuples from both objects.
00022   AIDA::ITuple* subTupleFrom = const_cast<AIDA::ITuple*>( tupleFrom.getTuple( columnFrom ) );
00023   AIDA::ITuple* subTupleTo = tupleTo.getTuple( columnTo );
00024   
00025   // Get the descripion. We assume that it is the same...
00026   const int ncolumns = tupleFrom.columns();
00027   std::vector<std::string> names( ncolumns );
00028   std::vector<std::string> types( ncolumns );
00029   std::vector< Anaphe::AIDA_Tuple_native::TupleVariableCopyBase* > copyMethods;
00030   bool typesOK = true;
00031   for ( int i = 0; i < ncolumns; ++i ) {
00032     names[i] = subTupleFrom->columnName( i );
00033     std::string type = subTupleFrom->columnType( i );
00034     types[i] = type;
00035     if ( type == doubleType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyDouble );
00036     else if ( type == floatType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyFloat );
00037     else if ( type == longType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyLong );
00038     else if ( type == intType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyInt );
00039     else if ( type == shortType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyShort );
00040     else if ( type == charType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyChar );
00041     else if ( type == boolType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyBoolean );
00042     else if ( type == stringType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyString );
00043     else if ( type == tupleType ) copyMethods.push_back( new Anaphe::AIDA_Tuple_native::TupleVarialbeCopyTuple );
00044     else {
00045       typesOK = false;
00046       break;
00047     }
00048   }
00049   if ( ! typesOK ) {
00050     for ( unsigned int i = 0; i < copyMethods.size(); ++i ) delete copyMethods[i];
00051     return;
00052   }
00053   
00054   subTupleFrom->start();
00055   subTupleTo->reset();
00056   while( subTupleFrom->next() ) {
00057     subTupleTo->addRow();
00058     // Copy over the values
00059     for ( int i = 0; i < ncolumns; ++i ) {
00060       copyMethods[i]->copyTupleVariable( *subTupleFrom, i, *subTupleTo, i );
00061     }
00062   }
00063   
00064   for ( unsigned int i = 0; i < copyMethods.size(); ++i ) delete copyMethods[i];
00065   subTupleTo->start(); // Trick to flush the last row into the store.
00066 }

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