XMLTree Class Reference

#include <XMLTree.hpp>

List of all members.

Public Types

typedef std::multimap
< std::string,
ReferenceCounting< XMLTag > > 
TagList
typedef std::pair
< TagList::iterator,
TagList::iterator > 
range
typedef std::pair
< TagList::const_iterator,
TagList::const_iterator > 
const_range

Public Member Functions

void setHead (const std::string &xml, const std::string &version, const std::string &versionNumber)
void check () const
void checkRange (const std::string &pathName, const_range r) const
void addTag (ReferenceCounting< XMLTag > tag)
void closeTag (const std::string &tagName)
TagList::const_iterator end () const
bool hasOpenTag () const
ReferenceCounting< XMLTaggetCurrentTag ()
ConstReferenceCounting< XMLTaggetCurrentTag () const
bool hasTag (const std::string &pathName) const
ReferenceCounting< XMLTagfindTag (const std::string &pathName)
ReferenceCounting< XMLTagfindTag (const std::string &pathName) const
range findTagRange (const std::string &pathName)
const_range findTagRange (const std::string &pathName) const
 XMLTree ()
 ~XMLTree ()

Private Member Functions

 XMLTree (const XMLTree &)
std::string __getFullTagName () const
std::string __tagFromPath (const std::string &pathName) const

Private Attributes

TagList __tagList
std::vector< ReferenceCounting
< XMLTag > > 
__openTags


Detailed Description

Definition at line 39 of file XMLTree.hpp.


Member Typedef Documentation

typedef std::multimap<std::string, ReferenceCounting<XMLTag> > XMLTree::TagList

Definition at line 43 of file XMLTree.hpp.

typedef std::pair<TagList::iterator,TagList::iterator> XMLTree::range

Definition at line 45 of file XMLTree.hpp.

typedef std::pair<TagList::const_iterator,TagList::const_iterator> XMLTree::const_range

Definition at line 46 of file XMLTree.hpp.


Constructor & Destructor Documentation

XMLTree::XMLTree ( const XMLTree  )  [private]

forbidden copy constructor

XMLTree::XMLTree (  )  [inline]

Constructor

Definition at line 269 of file XMLTree.hpp.

00270   {
00271     ;
00272   }

XMLTree::~XMLTree (  )  [inline]

Destructor

Definition at line 278 of file XMLTree.hpp.

00279   {
00280     ;
00281   }


Member Function Documentation

std::string XMLTree::__getFullTagName (  )  const [inline, private]

Gets the tag "full name" (ie: including the path to the tag)

Returns:
full tag name '>' is the separator

Definition at line 66 of file XMLTree.hpp.

References __openTags.

Referenced by addTag().

00067   {
00068     std::string path;
00069     for (std::vector<ReferenceCounting<XMLTag> >::const_iterator i=__openTags.begin();
00070          i != __openTags.end(); ++i) {
00071       path += '>'+(*i)->name();
00072     }
00073     return path;
00074   }

std::string XMLTree::__tagFromPath ( const std::string &  pathName  )  const [private]

Gets standard xml path name from local description

Parameters:
pathName given local description
Returns:
xml path

Definition at line 38 of file XMLTree.cpp.

Referenced by checkRange(), and findTag().

00039 {
00040   std::string tagName = "<";
00041   for (size_t i=1; i<pathName.size(); ++i) {
00042     if (pathName[i] == '>') {
00043       tagName += "><";
00044     } else {
00045       tagName += pathName[i];
00046     }
00047   }
00048   tagName += '>';
00049   return tagName;
00050 }

void XMLTree::setHead ( const std::string &  xml,
const std::string &  version,
const std::string &  versionNumber 
) [inline]

Sets file description

Parameters:
xml xml tag
version version attribute
versionNumber version number

Definition at line 94 of file XMLTree.hpp.

References ErrorHandler::normal.

00097   {
00098     if ((xml != "xml")or(version != "version")or(versionNumber != "1.0"))
00099       {
00100       throw ErrorHandler(__FILE__,__LINE__,
00101                          "cannot read file format: <?"+xml+" "+version+"=\""+versionNumber+"\"?>",
00102                          ErrorHandler::normal);
00103     }
00104   }

void XMLTree::check (  )  const

Checks that xml tree is correct

Definition at line 64 of file XMLTree.cpp.

References __openTags, and ErrorHandler::normal.

Referenced by ScalarFunctionReaderVTK::getFunction(), and MeshReaderVTKFormat::MeshReaderVTKFormat().

00065 {
00066   if (__openTags.size() != 0) {
00067     std::string path;
00068     for (std::vector<ReferenceCounting<XMLTag> >::const_iterator i=__openTags.begin();
00069          i != __openTags.end(); ++i) {
00070       path += '<'+(*i)->name()+'>';
00071     }
00072 
00073     throw ErrorHandler(__FILE__,__LINE__,
00074                        "tag "+path+" not closed",
00075                        ErrorHandler::normal);
00076   }
00077 }

void XMLTree::checkRange ( const std::string &  pathName,
const_range  r 
) const

Checks that a given path exists or throw an exception

Parameters:
pathName pathName for error message
r range to check

Definition at line 53 of file XMLTree.cpp.

References __tagFromPath(), and ErrorHandler::normal.

Referenced by findTag(), and findTagRange().

00055 {
00056   if (distance(r.first, r.second) == 0) {
00057     throw ErrorHandler(__FILE__,__LINE__,
00058                        "cannot find tag "+this->__tagFromPath(pathName),
00059                        ErrorHandler::normal);
00060   }
00061 }

Here is the call graph for this function:

void XMLTree::addTag ( ReferenceCounting< XMLTag tag  ) 

Adds a tag to the list

Parameters:
tag tag to add

Definition at line 23 of file XMLTree.cpp.

References __getFullTagName(), __openTags, and __tagList.

00024 {
00025   __openTags.push_back(tag);
00026   __tagList.insert(std::make_pair(this->__getFullTagName(),tag));
00027 }

Here is the call graph for this function:

void XMLTree::closeTag ( const std::string &  tagName  ) 

Closes current tag

Parameters:
tagName name of the tag

Definition at line 30 of file XMLTree.cpp.

References __openTags, and getCurrentTag().

00031 {
00032   this->getCurrentTag()->close(tagName);
00033   __openTags.pop_back();
00034 }

Here is the call graph for this function:

TagList::const_iterator XMLTree::end (  )  const [inline]

gets tag list end()

Returns:
__tagList.end();

Definition at line 140 of file XMLTree.hpp.

References __tagList.

00141   {
00142     return __tagList.end();
00143   }

bool XMLTree::hasOpenTag (  )  const [inline]

Checks if some tags are still opened

Returns:
true if there are some

Definition at line 150 of file XMLTree.hpp.

References __openTags.

00151   {
00152     return (__openTags.rbegin() != __openTags.rend());
00153   }

ReferenceCounting<XMLTag> XMLTree::getCurrentTag (  )  [inline]

Access to the current tag

Returns:
the last tag opened

Definition at line 161 of file XMLTree.hpp.

References __openTags.

Referenced by closeTag().

00162   {
00163     return *__openTags.rbegin();
00164   }

ConstReferenceCounting<XMLTag> XMLTree::getCurrentTag (  )  const [inline]

Read-only access to the current tag

Returns:
the last tag opened

Definition at line 172 of file XMLTree.hpp.

References __openTags.

00173   {
00174     return *__openTags.rbegin();
00175   }

bool XMLTree::hasTag ( const std::string &  pathName  )  const [inline]

Checks if a pathName to a tag exists

Parameters:
pathName tag name
Returns:
true if it exists

Definition at line 184 of file XMLTree.hpp.

References __tagList, and ASSERT.

Referenced by ScalarFunctionReaderVTK::getFunction().

00185   {
00186     ASSERT(pathName[0] == '>');
00187     return (__tagList.find(pathName) != __tagList.end());
00188   }

ReferenceCounting<XMLTag> XMLTree::findTag ( const std::string &  pathName  )  [inline]

Searches for a tag according to its path name

Parameters:
pathName tag name
Returns:
the tag if found

Definition at line 198 of file XMLTree.hpp.

References __tagFromPath(), __tagList, ASSERT, checkRange(), and ErrorHandler::normal.

Referenced by ScalarFunctionReaderVTK::getFunction(), and MeshReaderVTKFormat::MeshReaderVTKFormat().

00199   {
00200     ASSERT(pathName[0] == '>');
00201     range r = __tagList.equal_range(pathName);
00202     this->checkRange(pathName,r);
00203     if (distance(r.first, r.second) != 1) {
00204       throw ErrorHandler(__FILE__,__LINE__,
00205                          "tag "+this->__tagFromPath(pathName)+" is not unique!",
00206                          ErrorHandler::normal);
00207     }
00208     
00209     return r.first->second;
00210   }

Here is the call graph for this function:

ReferenceCounting<XMLTag> XMLTree::findTag ( const std::string &  pathName  )  const [inline]

Searches for a tag according to its path name

Parameters:
pathName tag name
Returns:
the tag if found

Definition at line 220 of file XMLTree.hpp.

References __tagFromPath(), __tagList, ASSERT, checkRange(), and ErrorHandler::normal.

00221   {
00222     ASSERT(pathName[0] == '>');
00223     const_range r = __tagList.equal_range(pathName);
00224     this->checkRange(pathName,r);
00225     if (distance(r.first, r.second) != 1) {
00226       throw ErrorHandler(__FILE__,__LINE__,
00227                          "tag "+this->__tagFromPath(pathName)+" is not unique!",
00228                          ErrorHandler::normal);
00229     }
00230     return r.first->second;
00231   }

Here is the call graph for this function:

range XMLTree::findTagRange ( const std::string &  pathName  )  [inline]

Searches for a tag range according to its path name

Parameters:
pathName tag name
Returns:
the range for this pathName

Definition at line 241 of file XMLTree.hpp.

References __tagList, ASSERT, and checkRange().

Referenced by ScalarFunctionReaderVTK::getFunction().

00242   {
00243     ASSERT(pathName[0] == '>');
00244     range r = __tagList.equal_range(pathName);
00245     this->checkRange(pathName,r);
00246     return r;
00247   }

Here is the call graph for this function:

const_range XMLTree::findTagRange ( const std::string &  pathName  )  const [inline]

Searches for a tag range according to its path name

Parameters:
pathName tag name
Returns:
the range for this pathName

Definition at line 257 of file XMLTree.hpp.

References __tagList, ASSERT, and checkRange().

00258   {
00259     ASSERT(pathName[0] == '>');
00260     const_range r = __tagList.equal_range(pathName);
00261     this->checkRange(pathName,r);
00262     return r;
00263   }

Here is the call graph for this function:


Member Data Documentation

tag list

Definition at line 49 of file XMLTree.hpp.

Referenced by addTag(), end(), findTag(), findTagRange(), and hasTag().

std::vector<ReferenceCounting<XMLTag> > XMLTree::__openTags [private]

open tags

Definition at line 52 of file XMLTree.hpp.

Referenced by __getFullTagName(), addTag(), check(), closeTag(), getCurrentTag(), and hasOpenTag().


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

Generated on Wed Nov 19 00:18:18 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6