CAcHierarchy Class Reference

#include <CAcHierarchy.h>

Inheritance diagram for CAcHierarchy:

CAccessorImplementation CAccessor

List of all members.

Public Member Functions

 CAcHierarchy (const CXMLElement &inConfiguration)
CIDRelevanceLevelPairListgetChildren (const CPath &inID) const
void addElement (TID inID, string inLocation, string inThumbnail)
void push (TID inNode)
void popNodeAndRegisterEdge ()
 operator bool () const

Protected Types

typedef list< TIDCPath
typedef list< TIDCChildren
typedef map< CPath, CChildrenCGraph

Protected Member Functions

void init (string inFileName)
void addEdge (const CPath &inFather, TID inSon)

Protected Attributes

CMutex mMutexHierarchy
bool isOK
CPath mNodeStack
CGraph mEdges


Detailed Description

A very simple accessor for hierarchies of images Stored in an XML file.

This was intended as the ultra simple example system for the browser benchmarking paper. It performed too bad in our benchmark to be taken seriously.

Currently I see the use of this as the base for systems, where the author knows how to generate a hierarchy of images, but the author fears the overhead needed for including his/her system into the gift.

Please note that IDs must start at 1 (ONE!!!).

Author:
Wolfgang Müller

Definition at line 52 of file CAcHierarchy.h.


Member Typedef Documentation

typedef list<TID> CAcHierarchy::CPath [protected]

In fact, because images can arise multiple times in the hierarchy, it is necessary to store the full path for each time the image arises in the tree.

We base this on the idea that in each selection, each image will arise at most once. As a consequence, lists of selected images must be sufficient to define the path from the hierarchy's root to a given node or leaf of the hierarchy.

Definition at line 69 of file CAcHierarchy.h.

typedef list<TID> CAcHierarchy::CChildren [protected]

This class is there for mnemonic reasons only. Evidently it has the same type as CPath, however it designates a list of children.

Definition at line 74 of file CAcHierarchy.h.

typedef map<CPath,CChildren> CAcHierarchy::CGraph [protected]

The graph is represented as a map from path to children.

See also:
CPath for an explanation

Definition at line 83 of file CAcHierarchy.h.


Constructor & Destructor Documentation

CAcHierarchy::CAcHierarchy ( const CXMLElement inConfiguration  ) 

constructor opens a hierarchy file and reads it.

Like every accessor, this accessor takes a <collection> MRML element as input (

See also:
CXMLElement for how to access the attributes of this element). Currently this accessor understands the following attributes:
cui-base-dir: the base directory containing the following file: cui-hierarchy-file-location: an xml file containing the hierarchy that you can browse using this accessor.

Definition at line 111 of file CAcHierarchy.cc.

References mrml_const::cui_base_dir, mrml_const::cui_hierarchy_file_location, init(), CMutex::lock(), mMutexHierarchy, and CMutex::unlock().

00111                                                                 {
00112   mMutexHierarchy.lock();
00113   init(inCollectionElement
00114        .stringReadAttribute(mrml_const::cui_base_dir).second
00115        +inCollectionElement
00116        .stringReadAttribute(mrml_const::cui_hierarchy_file_location).second);
00117   mMutexHierarchy.unlock();
00118 }


Member Function Documentation

void CAcHierarchy::init ( string  inFileName  )  [protected]

called immediately by the constructor, this function does the main construction work. Starts the xml parser for reading the hierarchy file etc.

Definition at line 120 of file CAcHierarchy.cc.

References endHierarchyElement(), CMutex::lock(), mMutexHierarchy, my_throw, startHierarchyElement(), and CMutex::unlock().

Referenced by CAcHierarchy().

00120                                         {
00121   mMutexHierarchy.lock();
00122 
00123   ifstream lHierarchyFile(inFileName.c_str());
00124   if(lHierarchyFile){
00125       lHierarchyFile.seekg(0,ios::end);
00126       int lSize=lHierarchyFile.tellg();
00127       char lHierarchyFileContent[lSize+1];
00128       
00129       lHierarchyFile.seekg(0,ios::beg);
00130       lHierarchyFile.read(lHierarchyFileContent,
00131         lSize);
00132       
00133       lHierarchyFileContent[lSize]=0;
00134       
00135       cout << "I did it: I read the HIERARCHY file "
00136      << inFileName
00137      << ": "
00138      << lHierarchyFileContent
00139      << endl
00140      << flush;
00141 
00142       XML_Parser lParser = XML_ParserCreate(NULL);//default encoding
00143       XML_SetUserData(lParser,
00144           this);
00145       XML_SetElementHandler(lParser, 
00146           startHierarchyElement, 
00147           endHierarchyElement);
00148       int lDone=true;
00149 
00150       do {
00151   if (!XML_Parse(lParser, 
00152            lHierarchyFileContent, 
00153            lSize, 
00154            lDone)) {
00155     cerr << "XML ERROR: "
00156          << XML_ErrorString(XML_GetErrorCode(lParser))
00157          << " at line "
00158          << XML_GetCurrentLineNumber(lParser)
00159          << endl;
00160     my_throw(VEConfigurationError("could not find requested tree"));
00161   }
00162       } while (!lDone);
00163 
00164       XML_ParserFree(lParser);  
00165       mMutexHierarchy.unlock();
00166   }else{
00167     mMutexHierarchy.unlock();
00168     my_throw(string(string("could not open config file_")+inFileName+string("_")).c_str());
00169   }
00170 };

void CAcHierarchy::addEdge ( const CPath inFather,
TID  inSon 
) [protected]

adds an edge from father to son and an edge from son to father

Definition at line 214 of file CAcHierarchy.cc.

References CMutex::lock(), mEdges, mMutexHierarchy, and CMutex::unlock().

Referenced by popNodeAndRegisterEdge().

00215                    {
00216   mMutexHierarchy.lock();
00217 
00218   mEdges[inPath].push_back(inSon);
00219   cout << "SIZE addBackForthEdge: ("
00220        << inSon
00221        << ") "
00222        << mEdges[inPath].size()
00223        << " "
00224        << inPath.size()
00225        << " "
00226        << mEdges.size()
00227        << endl;
00228   mMutexHierarchy.unlock();
00229 }

CIDRelevanceLevelPairList * CAcHierarchy::getChildren ( const CPath inID  )  const

Gets a list of all children of an element. As it was said before, an element of the hierarchy is well described by a path in the tree, from the root to this element.

Definition at line 231 of file CAcHierarchy.cc.

References CMutex::lock(), mEdges, mMutexHierarchy, and CMutex::unlock().

00231                                                                             {
00232   mMutexHierarchy.lock();
00233 
00234   CGraph::const_iterator lFound(mEdges.find(inPath));
00235   
00236   if(lFound!=mEdges.end()){
00237     CIDRelevanceLevelPairList* lList(new CIDRelevanceLevelPairList());
00238     
00239     for(list<TID>::const_iterator i=lFound->second.begin();
00240   i!=lFound->second.end();
00241   i++){
00242       lList->push_back(CIDRelevanceLevelPair(*i,1.0));
00243     }
00244     return lList;
00245   }
00246 
00247   cout << "NOTFOUND" << endl;
00248 
00249   mMutexHierarchy.unlock();
00250   return 0;
00251 }

void CAcHierarchy::addElement ( TID  inID,
string  inLocation,
string  inThumbnail 
)

Adds an element to the collection

Definition at line 172 of file CAcHierarchy.cc.

References CMutex::lock(), CAccessorImplementation::mIDToAccessorElement, mMutexHierarchy, CAccessorImplementation::mURLToID, and CMutex::unlock().

Referenced by startHierarchyElement().

00174                                {
00175   mMutexHierarchy.lock();
00176 
00177   mIDToAccessorElement.insert(make_pair(inID,
00178           CAccessorElement(inID,
00179                inLocation,
00180                inThumbnail,
00181                string(""))));
00182   
00183   mURLToID[inLocation]=inID;
00184   mMutexHierarchy.unlock();
00185 }

void CAcHierarchy::push ( TID  inNode  ) 

pushes the node onto the stack

pushes the node onto the stack

Definition at line 191 of file CAcHierarchy.cc.

References CMutex::lock(), mMutexHierarchy, mNodeStack, and CMutex::unlock().

Referenced by startHierarchyElement().

00191                                  {
00192   mMutexHierarchy.lock();
00193   mNodeStack.push_back(inNode);
00194   mMutexHierarchy.unlock();
00195 };

void CAcHierarchy::popNodeAndRegisterEdge (  ) 

pops the node and registers the edge from new top to old top and back

pops the node and registers the edge from new top to old top and back

Definition at line 202 of file CAcHierarchy.cc.

References addEdge(), CMutex::lock(), mMutexHierarchy, mNodeStack, and CMutex::unlock().

Referenced by endHierarchyElement().

00202                                          {
00203   mMutexHierarchy.lock();
00204 
00205   if(mNodeStack.size()){
00206     TID lExTop=mNodeStack.back();
00207     
00208     mNodeStack.pop_back();
00209     
00210     addEdge(mNodeStack,lExTop);
00211   }
00212   mMutexHierarchy.unlock();
00213 };

CAcHierarchy::operator bool (  )  const [virtual]

has this been successfully read?

Implements CAccessorImplementation.

Definition at line 253 of file CAcHierarchy.cc.

00253                                 {
00254   return true;
00255 }


Member Data Documentation

mutual exclude for multithreading

Definition at line 55 of file CAcHierarchy.h.

Referenced by addEdge(), addElement(), CAcHierarchy(), getChildren(), init(), popNodeAndRegisterEdge(), and push().

bool CAcHierarchy::isOK [protected]

is this well constructed ?

Definition at line 57 of file CAcHierarchy.h.

A stack of the nodes visited when building the hierarchy

Definition at line 78 of file CAcHierarchy.h.

Referenced by popNodeAndRegisterEdge(), and push().

Edges: The edges from father to son. The edges from son to father are not needed, because it means simply popping from the path.

Definition at line 89 of file CAcHierarchy.h.

Referenced by addEdge(), and getChildren().


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

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