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

TableRowTranslator.cpp

00001                               /* TableRowTranslator.cpp */
00002 
00003 /*
00004  *  Implementation of TableRowTranslator.h
00005  */
00006 
00007 #include "TableRowTranslator.h"
00008 
00009 using namespace LcgInfo;
00010 using namespace std;
00011 
00012 /******************  METHODS FOR CLASS TableRowTranslator  ********************/
00013 
00014 TableRowTranslator::TableRowTranslator():mMap(){
00015    cerr << "WARNING!!: No mapfile provided!";
00016    cerr << "Using \"./mappingGlueRGMA\" as default one" << endl;
00017    try{
00018       mMap->populate_from_config("./mappingGlueRGMA");
00019    }catch(LcgConfigBuffer::CBException& e){
00020        string msg="No valid mapping file. Aborting.";
00021        msg += "\nUnderlying LcgConfigBuffer::CBException message: " + e.what() + " +line: ";
00022        msg += int2str(e.get_line()) + " +file: " + e.get_file();
00023        throw QueryTranslationException(msg,__FILE__,__LINE__);
00024     }
00025    mOurMap=true;
00026 }
00027 
00028 
00029 TableRowTranslator::TableRowTranslator(string const & pMapFile):mMap(){
00030    try{
00031       mMap->populate_from_config(pMapFile);
00032    }catch(LcgConfigBuffer::CBException& e){
00033        string msg="No valid mapping file. Aborting.";
00034        msg += "\nUnderlying LcgConfigBuffer::CBException message: " + e.what() + " +line: ";
00035        msg += int2str(e.get_line()) + " +file: " + e.get_file();
00036        throw QueryTranslationException(msg,__FILE__,__LINE__);
00037     }
00038    mOurMap=true;
00039 }
00040 
00041 
00042 TableRowTranslator::TableRowTranslator(LcgConfigBuffer::ConfigBuffer & pMap):mMap(&pMap){
00043    mOurMap=false;
00044 }
00045 
00046 
00047 TableRowTranslator::~TableRowTranslator(){
00048    if(mOurMap){
00049       delete mMap;
00050       mMap=0;
00051    }
00052 }
00053 
00054 
00055 string TableRowTranslator::mapTableRow(string const & pTableRow){
00056    string msg; // to return errors
00057    string mappedTR;  // the mapped table.row to be returned
00058    unsigned int posPred=0; // to mark where the predicates start ("{...}")
00059    unsigned int posEnd=0; // to use when processing predicates
00060 
00061    mPredicates.clear();   //reset the vector of structural changes
00062 
00063    //If a LcgConfigBuffer::CBException is thrown here, the caller will deal with it
00064    mappedTR=mMap->get_attribute_value(pTableRow);
00065 
00066    //search for structural changes rules
00067    bool found=false;
00068    while(!found){
00069       posPred=mappedTR.find('{',posPred);
00070       if(posPred==string::npos)    return mappedTR; // no "{" was found
00071       
00072       //now deal with escape chars ("\...\{")
00073       int count=0; 
00074       for(int i=posPred-1; mappedTR.at(i)=='\\'; i--, count++); //count escape chars
00075       if(count>0){
00076          mappedTR.erase(posPred-count/2,count/2);  //delete half of the "\"
00077          posPred-=count/2;  // adjust index (elements were eliminated)
00078          if(count%2==0) found=true;   // the "{" was not escaped, the rule applies
00079          else     //the "{" was escaped, search again
00080             mappedTR.erase(posPred-1,1);  //delete one "\" more
00081       }
00082       else found=true;  // the "{" was not escaped, the rule applies
00083    }//end of while
00084 
00085    if(found){ //add rules to the mPredicates vector
00086       vector<string> tokenArray;
00087       posEnd=mappedTR.find('}',posPred); //end of predicates part
00088       if(posEnd!=string::npos) //tokenize it
00089          tokenizeStr(mappedTR.substr(posPred+1, posEnd-posPred-1), tokenArray,";");
00090       else
00091          tokenizeStr(mappedTR.substr(posPred+1), tokenArray,";");
00092       for(vector<string>::iterator i=tokenArray.begin(); i!=tokenArray.end(); i++){
00093          delSurroundingChars(*i);   //remove blanks from the predicate
00094          if(!(*i).empty()) mPredicates.push_back(*i); //store the predicate (if there is something)
00095       }
00096    }
00097    return mappedTR.substr(0,posPred); //return what there was before the rules (or till the end)
00098 } // end of mapTableRow()
00099 
00100 
00101 bool TableRowTranslator::thereIsStructChange(){
00102    return !(mPredicates.empty());
00103 }
00104 
00105 
00106 vector<string>::iterator TableRowTranslator::getPredicatesBegin(){
00107    return mPredicates.begin();
00108 }
00109 
00110 vector<string>::iterator TableRowTranslator::getPredicatesEnd(){
00111    return mPredicates.end();
00112 }

Generated on Tue Oct 5 14:42:45 2004 for LCG Information System Interface by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002