freIDPath.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freIDPath.h,v $
00007   Language:  C++
00008 
00009 
00010   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00011   Institute for Medical Biometry and Informatics, University of Heidelberg,
00012   Germany). All rights reserved.
00013   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00014   for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even 
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00018      PURPOSE.  See the above copyright notices for more information.
00019 
00020 =========================================================================*/
00021 #ifndef __freIDPath_h
00022 #define __freIDPath_h
00023 
00024 #include "freElementals.h"
00025 #include "freXMLStreamObject.h"
00026 #include "freComponentID.h"
00027 
00028 namespace FREE
00029 {
00030 
00048 class IDPath : public XMLStreamObject
00049 {
00050 public:  
00052   enum PathElementType
00053   {
00054     PTNULL = 0,          //*< Element is non existant or invalid.
00055     PTSelf = 1,          //*< Selects itself as actual node (".").
00056     PTParent = 2,        //*< Selects parent as actual node ("..").
00057     PTAnyChild = 3,      //*< Selects any component that is a child of the actual node ("*").
00058     PTAnyDescendant = 4, //*< Selects any descendant compnent of the actual node ("//").
00059     PTComponent = 5,     //*< Selects components with the specified ID (any legal component id).
00060     PTParameter = 6,      //*< Selects an attribute/parameter of the actual component (any parameter name with a @ as prefix).
00061     PTMedia = 7          //*< Selects a media component of the actual component (any parameter name with a # as prefix).
00062   };
00063 
00065   bool IsEmpty() const {return m_ElementTypes.size()==0;};
00067   bool IsAbsolute() const { return m_bAbsolute; };
00069   bool IsRoot() const { return IsAbsolute() && IsEmpty(); };
00070 
00071   void SetAbsolute(const bool& bAbsolute) { this->m_bAbsolute = bAbsolute; };
00072 
00074   bool IsParameterSelection() const;
00075 
00077   bool IsMediaSelection() const;
00078 
00080   bool IsComponentSelection() const;
00081 
00083   inline unsigned int Size() const;
00084 
00086   unsigned int AddComponent(const PathElementType& elementType, const std::string& sTag);
00087 
00093   PathElementType GetComponent(const unsigned int& index, std::string& sTag) const;
00094 
00099   PathElementType GetFirstComponent(std::string& sTag) const;
00100 
00104   IDPath GetSubIDPath() const;
00105 
00108   IDPath GetParentIDPath() const;
00109 
00112   IDPath GetParentComponentIDPath() const;
00113 
00119   IDPath GetParameterIDPath() const;
00120 
00124   std::string GetParameterName() const;
00125 
00129   std::string GetMediaID() const;
00130 
00135   std::string GetComponentID() const;
00136 
00144   IDPath TransformIDPath(const IDPath& origin) const;
00145 
00146   inline operator std::string() const {return this->ToStr();};
00147 
00148   std::string ToStr() const;
00149 
00152   bool operator == (const IDPath& path) const;
00153 
00155   bool Equals(const IDPath& path) const;
00156 
00158   bool ChildOf(const IDPath& path) const;
00159 
00160         IDPath& operator = (const IDPath& path);
00161   IDPath& operator = (const std::string& path);
00162   IDPath& operator = (const char* path);
00163 
00174   IDPath operator + (const IDPath& modPath) const;
00175 
00177   static IDPath Concat(const IDPath& path1, const IDPath& path2);
00178 
00179   IDPath();
00180   IDPath(const IDPath& path);
00181   IDPath(const std::string& path);
00182   IDPath(const char* path);
00183 
00184   ~IDPath();
00185 
00186   virtual void Reset();
00187 
00195   static IDPath Parameter(const std::string& sParameterName, unsigned long lValueID = 0, unsigned long lLayerID = 0);
00200   static IDPath Media(const std::string& sMediaName);
00201 
00202 protected:
00204   virtual void SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData);
00206   virtual std::string SaveData(const unsigned int& iDepth, bool& bHasSubElements) const;
00207 
00213   IDPath AssembleIDPath(const unsigned int& iFirstID, const unsigned int& iLastID) const;
00214 
00215   static bool IDPathesMatch(const IDPath& left, const IDPath& right);
00216 
00219   enum TokenType
00220   {
00221     TTSlash = 0,    // : /
00222     TTDot = 1,      // : .
00223     TTDDot = 2,     // : ..
00224     TTWildcard = 3, // : *
00225     TTDSlash = 4,   // : //
00226     TTComponent = 5 // : anything else
00227   };
00228 
00238   static bool GetFirstToken(const std::string& sIDPath, TokenType& token, std::string& sFirstTag, std::string& sSubPath );
00239 
00245   static PathElementType GetComponentType(const std::string& sTokenTag, std::string& sComponentID);
00246 
00247   typedef std::vector<PathElementType> PathElementTypeVector;
00248 
00249   PathElementTypeVector m_ElementTypes;
00250   STLStringVector m_ElementTags;
00251 
00253   bool m_bAbsolute;
00254 };
00255 
00256 static bool operator == (const std::string& left, const IDPath& right)
00257 {
00258   return IDPath(left) == right;
00259 };
00260 
00261 static bool operator == (const IDPath& left, const std::string& right)
00262 {
00263   return  left == IDPath(right);
00264 };
00265 
00266 void DispatchParameterIDPath(const IDPath& parameterID, std::string& sParameterName, unsigned long& riItemPos, unsigned long& riLayer);
00267 
00268 //default ID pathes
00269 static const IDPath cIDPSelf(".");
00270 static const IDPath cIDPParent("..");
00271 static const IDPath cIDPRoot("/");
00272 static const IDPath cIDPEveryone("//*");
00273 
00274 static const IDPath cIDPMediaMoving(std::string("/")+cComp_MediaMoving);
00275 static const IDPath cIDPMediaFixed(std::string("/")+cComp_MediaFixed);
00276 static const IDPath cIDPMediaFinal(std::string("/")+cComp_MediaFinal);
00277 static const IDPath cIDPMediaInterim(std::string("/")+cComp_MediaInterim);
00278 
00279 typedef std::vector<IDPath> IDPathVectorType;
00280 } //end of namespace FREE
00281 
00282 #endif

Generated at Sat Oct 13 16:02:18 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000