CQueryParadigmMatcher Class Reference

#include <CQueryParadigmMatcher.h>

List of all members.

Public Member Functions

bool operator() (const CXMLElement &inQuery, const CXMLElement &inResult) const

Protected Member Functions

bool matches (const CXMLElement &inQuery, const CXMLElement &inResult) const


Detailed Description

A class for checking if the content of two query-paradigm tags matches

Definition at line 35 of file CQueryParadigmMatcher.h.


Member Function Documentation

bool CQueryParadigmMatcher::matches ( const CXMLElement inQuery,
const CXMLElement inResult 
) const [protected]

Two XMLElements of type query-paradigm match, if the intersection of their attribute sets is identical.

I.e.: If inQuery contains <query-paradigm a1="x" a2=y" />, inResult with <query-paradigm a1="x" a3="z" /> would match, because the intersection {a1,a2} {a1,a2} of the attribute sets is <query-paradigm a1="x" /> and <query-paradigm a1="x"/> for both inQuery and inResult.

<query-paradigm a1="x"/> <query-paradigm a2="x"/>

would also match (the intersection of {a1} and {a2} is empty)

<query-paradigm a1="x" a3="x" /> <query-paradigm a1="y" />

would not (the intersection of {a1,a3} and {a1} is non-empty, but the values in the two tags are differen)

Definition at line 26 of file CQueryParadigmMatcher.cc.

References CXMLElement::createNamedValueList(), CXMLElement::getNumberOfAttributes(), and CXMLElement::stringReadAttribute().

Referenced by operator()().

00026                                                                                               {
00027   const CXMLElement* lQuery(&inQuery);
00028   const CXMLElement* lResult(&inResult);
00029   
00030   //as the relation we are describing is symmetric,
00031   //we permit ourselves to swap things in a way, that
00032   //processing time is minimal
00033   if(lQuery->getNumberOfAttributes() > lResult->getNumberOfAttributes()){
00034     swap(lQuery,lResult);
00035   }
00036 
00037   list<pair<string,string> >* lQueryAttributes(lQuery->createNamedValueList());
00038 
00039   bool lMatches(true);
00040 
00041   for(list<pair<string,string> >::const_iterator i=lQueryAttributes->begin();
00042       lMatches && (i!=lQueryAttributes->end());
00043       i++){
00044     // get the query attribute in the result element
00045     pair<bool,string> lAttribute(lResult->stringReadAttribute(i->first));
00046     // they match, unless
00047     // the query attribute exsists in the result element
00048     // and the attribute values differ between query and result
00049     if(lAttribute.first 
00050        && (lAttribute.second != i->second)){
00051       lMatches=false;
00052     }
00053   }
00054 
00055   delete lQueryAttributes;
00056 
00057   return lMatches;
00058 }

bool CQueryParadigmMatcher::operator() ( const CXMLElement inQuery,
const CXMLElement inResult 
) const

This function gives back, if the inQuery matches inResult.

Both parameters are elements of type query-paradigm-list

inQuery matches inResult, if one of the children (a query paradigm) of inQuery matches one of the children (also a query paradigm) of inResult.

Definition at line 60 of file CQueryParadigmMatcher.cc.

References CXMLElement::child_list_begin(), CXMLElement::child_list_end(), CXMLElement::getName(), matches(), and mrml_const::query_paradigm_list.

00060                                                                                                  {
00061   
00062   // nothing matches everything
00063   if(!(&inQuery) || !(&inResult)){
00064     return true;
00065   }
00066   if((inQuery.getName()==mrml_const::query_paradigm_list)
00067      &&
00068      (inQuery.getName()==mrml_const::query_paradigm_list)){
00069     for(list<CXMLElement*>::const_iterator i=inQuery.child_list_begin();
00070   i!=inQuery.child_list_end();
00071   i++){
00072       for(list<CXMLElement*>::const_iterator j=inResult.child_list_begin();
00073   j!=inResult.child_list_end();
00074   j++){
00075   if(matches(**i,**j)){
00076     return true;
00077   }
00078       }
00079     };
00080   }
00081   return false;
00082 };


The documentation for this class was generated from the following files:

Generated on Tue Jan 6 00:31:17 2009 for Gift by  doxygen 1.5.6