CAccessorAdmin Class Reference

#include <CAccessorAdmin.h>

List of all members.

Public Member Functions

CAccessoropenAccessor (string inType)
void closeAccessor (string inType)
void setCollectionElement (CXMLElement *)
const CXMLElementgetCollectionElement () const
const CXMLElementgetQueryParadigmList () const
list< string > * getAvailableIndices () const
string toXML (bool isPrivate=false) const
CXMLElementtoXMLElement () const
 CAccessorAdmin (CAccessorFactoryContainer &inFactoryContainer)
 ~CAccessorAdmin ()
string getAlgorithmIDListID () const
string getName () const
string getID () const

Protected Types

typedef map< string,
CContentElement
CContent

Protected Attributes

CAccessorFactoryContainermFactoryContainer
CSelfDestroyPointer< CXMLElementmCollectionElement
CContent mContent

Friends

class CSortByName_pAP

Classes

class  CContentElement


Detailed Description

CAccessorAdmin: The goal of this is to make it possible to have a list containing accessors to all possible collections, without really opening the accessors.

The accessor proxy is in fact an open/close counter for accessors. This permits multiple query structures to share just one accessor, and it avoids having to open all kinds of accessors when starting the program.

Definition at line 45 of file CAccessorAdmin.h.


Member Typedef Documentation

typedef map<string,CContentElement> CAccessorAdmin::CContent [protected]

Typedef: The content is a map of string to content element In this map is noted, which accessors are open for the collection with the given ID.

Definition at line 72 of file CAccessorAdmin.h.


Constructor & Destructor Documentation

CAccessorAdmin::CAccessorAdmin ( CAccessorFactoryContainer inFactoryContainer  ) 

Constructor

Definition at line 42 of file CAccessorAdmin.cc.

00042                                                                            :
00043   mFactoryContainer(inFactoryContainer),
00044   mContent()
00045 {
00046 };

CAccessorAdmin::~CAccessorAdmin (  ) 

destructor

Definition at line 152 of file CAccessorAdmin.cc.

References mContent.

00152                                {
00153   for(CContent::const_iterator i=mContent.begin();
00154       i!=mContent.end();
00155       i++){
00156     printf("%s:%d:%s,%p\n",__FILE__,__LINE__,"DELETING",i->second.mAccessor);
00157     delete i->second.mAccessor;
00158   }
00159 }


Member Function Documentation

CAccessor * CAccessorAdmin::openAccessor ( string  inType  ) 

open an accessor.

This is the important part for the outside: Open or close inverted file accessors. Several queries can share one accessor, the accessor will be constructed when the first CQuery needs it, and it will be deleted, when the last one does not need it any more:

Definition at line 48 of file CAccessorAdmin.cc.

References mCollectionElement, mContent, mFactoryContainer, and CAccessorFactoryContainer::openAccessor().

Referenced by CQHierarchy::CQHierarchy(), CQInvertedFile::CQInvertedFile(), CQMultiple::CQMultiple(), CQMultiple::setAlgorithm(), CQInvertedFile::setAlgorithm(), and CQHierarchy::setAlgorithm().

00048                                                     {  
00049   CContent::const_iterator lFound=mContent.find(inName);
00050   if(lFound==mContent.end()){
00051     mContent[inName].mOpenCloseCounter=0;
00052     mContent[inName].mAccessor=0;
00053   }
00054   {
00055     if(!(mContent[inName].mOpenCloseCounter)){
00056       mContent[inName].mAccessor=mFactoryContainer.openAccessor(inName,
00057                 *mCollectionElement);
00058       mContent[inName].mOpenCloseCounter++;
00059       cerr << endl
00060      << "CAccessorAdmin::openAccessor:"
00061      << inName << endl
00062      << " NEWLY GENERATED." << endl;
00063     }else{
00064       mContent[inName].mOpenCloseCounter++;
00065       cerr << endl
00066      << "CAccessorAdmin::openAccessor:"
00067      << inName << endl
00068      << " REUSED. (" << mContent[inName].mOpenCloseCounter++ << " times in use)"<< endl;
00069     }
00070     return mContent[inName].mAccessor;
00071   }
00072   assert(!"Execution should never arive here");
00073 };

void CAccessorAdmin::closeAccessor ( string  inType  ) 

closing an accessor.

See also:
openAccessor

Definition at line 75 of file CAccessorAdmin.cc.

References CAccessorFactoryContainer::closeAccessor(), CMutex::lock(), mContent, mFactoryContainer, and CMutex::unlock().

Referenced by CQMultiple::setAlgorithm(), CQInvertedFile::setAlgorithm(), CQHierarchy::setAlgorithm(), and CQInvertedFile::~CQInvertedFile().

00075                                                {
00076   if(gMutex){
00077     gMutex->lock();
00078   }
00079   CContent::iterator lFound=mContent.find(inName);
00080 
00081   cout << __FILE__ << ":" << __LINE__ 
00082        << "PID:" << getpid()
00083        << "OpenCloseCounter["
00084        << inName
00085        << "]"
00086        << (mContent[inName].mOpenCloseCounter) << endl;
00087   
00088   //this is a hack. See the changelog for thisx
00089 #ifdef __GIFT_FREE_UNUSED_ACCESSORS
00090   if((lFound!=mContent.end())
00091      &&
00092      !(--(mContent[inName].mOpenCloseCounter))){
00093     delete lFound->second.mAccessor;
00094     mContent.erase(lFound);
00095 
00096     mFactoryContainer.closeAccessor(inName);
00097   }
00098 #endif
00099   if(gMutex){
00100     gMutex->unlock();
00101   }
00102 };

void CAccessorAdmin::setCollectionElement ( CXMLElement inElement  ) 

Once this is working this will replace about every set/get function which follows

Definition at line 34 of file CAccessorAdmin.cc.

References mCollectionElement.

00034                                                                {
00035   mCollectionElement=inElement;
00036 };

const CXMLElement * CAccessorAdmin::getCollectionElement (  )  const

Definition at line 38 of file CAccessorAdmin.cc.

References mCollectionElement.

00038                                                             {
00039   return mCollectionElement;
00040 };

const CXMLElement * CAccessorAdmin::getQueryParadigmList (  )  const

Definition at line 140 of file CAccessorAdmin.cc.

References mCollectionElement.

00140                                                             {
00141   for(list<CXMLElement*>::const_iterator i(mCollectionElement->child_list_begin());
00142       i!=mCollectionElement->child_list_end();
00143       i++){
00144     if((*i)->getName()=="query-paradigm-list"){
00145       return *i;
00146     }
00147   }
00148   return 0;
00149 };

list< string > * CAccessorAdmin::getAvailableIndices (  )  const

Definition at line 162 of file CAccessorAdmin.cc.

00162                                                       {
00163   list<string>* lReturnValue=new list<string>();
00164 
00165   lReturnValue->push_back("inverted_file");
00166 
00167   return lReturnValue;
00168 };

string CAccessorAdmin::toXML ( bool  isPrivate = false  )  const

generate out put for shandshake message

Definition at line 104 of file CAccessorAdmin.cc.

References CXMLHelper::addAttribute(), mrml_const::collection, mrml_const::collection_id, mrml_const::collection_name, mrml_const::cui_algorithm_id_list_id, getAlgorithmIDListID(), mCollectionElement, CXMLHelper::setEmpty(), CXMLHelper::setName(), and CXMLHelper::toString().

00104                                                {
00105 
00106   CXMLHelper lHelper;
00107 
00108   lHelper.setName(mrml_const::collection);
00109   lHelper.setEmpty();
00110   lHelper.addAttribute(mrml_const::collection_id,mCollectionElement->stringReadAttribute(mrml_const::collection_id).second);
00111   lHelper.addAttribute(mrml_const::collection_name,mCollectionElement->stringReadAttribute(mrml_const::collection_name).second);
00112   lHelper.addAttribute(mrml_const::cui_algorithm_id_list_id,getAlgorithmIDListID());
00113   
00114 
00115   string lReturnValue=lHelper.toString();
00116   return lReturnValue;
00117 }

CXMLElement * CAccessorAdmin::toXMLElement (  )  const

pack the content of this into an CXMLElement with elementname "collection"

Definition at line 120 of file CAccessorAdmin.cc.

References mCollectionElement.

00120                                               {
00121   CXMLElement* lReturnValue(0);
00122 
00123   if(mCollectionElement){
00124     lReturnValue=new CXMLElement(*mCollectionElement);
00125   }
00126 
00127   return lReturnValue;
00128 }

string CAccessorAdmin::getAlgorithmIDListID (  )  const

Definition at line 130 of file CAccessorAdmin.cc.

References mrml_const::cui_algorithm_id_list_id, and mCollectionElement.

Referenced by toXML().

00130                                                 {
00131   return mCollectionElement->stringReadAttribute(mrml_const::cui_algorithm_id_list_id).second;
00132 }

string CAccessorAdmin::getName (  )  const

Definition at line 133 of file CAccessorAdmin.cc.

References mrml_const::collection_name, and mCollectionElement.

00133                                    {
00134   return mCollectionElement->stringReadAttribute(mrml_const::collection_name).second;
00135 }

string CAccessorAdmin::getID (  )  const

Definition at line 136 of file CAccessorAdmin.cc.

References mrml_const::collection_id, and mCollectionElement.

00136                                  {
00137   return mCollectionElement->stringReadAttribute(mrml_const::collection_id).second;
00138 }


Friends And Related Function Documentation

friend class CSortByName_pAP [friend]

for sorting

Definition at line 121 of file CAccessorAdmin.h.


Member Data Documentation

Factory for making all kinds of accessors

Definition at line 50 of file CAccessorAdmin.h.

Referenced by closeAccessor(), and openAccessor().

The content is a map of string to content element

Definition at line 74 of file CAccessorAdmin.h.

Referenced by closeAccessor(), openAccessor(), and ~CAccessorAdmin().


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

Generated on Wed Jan 7 00:30:58 2009 for Gift by  doxygen 1.5.6