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: freComponentSetupBrowser.cxx,v $ 00007 Language: C++ 00008 00009 00010 00011 Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics, 00012 Institute for Medical Biometry and Informatics, University of Heidelberg, 00013 Germany). All rights reserved. 00014 See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm 00015 for details. 00016 00017 This software is distributed WITHOUT ANY WARRANTY; without even 00018 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00019 PURPOSE. See the above copyright notices for more information. 00020 00021 =========================================================================*/ 00022 #include "freComponentSetupBrowser.h" 00023 00024 #include "freComponentSetupCollection.h" 00025 00026 #include "freExceptions.h" 00027 00028 namespace FREE 00029 { 00030 00034 00035 00036 void 00037 ComponentSetupBrowser:: 00038 SetRelativeRoot(ComponentSetup* pRelativeRoot) 00039 { 00040 Reset(); 00041 m_pRelativeRoot = pRelativeRoot; 00042 }; 00043 00044 ComponentSetup* 00045 ComponentSetupBrowser:: 00046 GetRelativeRoot() const 00047 { 00048 return m_pRelativeRoot; 00049 }; 00050 00051 ComponentSetupBrowser::FindingsType& 00052 ComponentSetupBrowser:: 00053 GetFindings() 00054 { 00055 return m_Findings; 00056 }; 00057 00058 const ComponentSetupBrowser::FindingsType& 00059 ComponentSetupBrowser:: 00060 GetFindings() const 00061 { 00062 return m_Findings; 00063 }; 00064 00065 bool 00066 ComponentSetupBrowser:: 00067 SearchForComponents(const IDPath& idPath) 00068 { 00069 if (!m_pRelativeRoot) throwExceptionMacro("Error: cannot search for components no relative root defined. IDPath: " << idPath.ToStr()); 00070 00071 Reset(); 00072 CrawlComponentByIDPath(m_pRelativeRoot, idPath); 00073 return m_Findings.size()!=0; 00074 }; 00075 00076 ComponentSetupBrowser:: 00077 ComponentSetupBrowser(ComponentSetup* pRelativeRoot) 00078 { 00079 SetRelativeRoot(pRelativeRoot); 00080 }; 00081 00082 ComponentSetupBrowser:: 00083 ~ComponentSetupBrowser() {}; 00084 00085 void 00086 ComponentSetupBrowser:: 00087 Reset() 00088 { 00089 m_Findings.clear(); 00090 }; 00091 00092 void 00093 ComponentSetupBrowser:: 00094 CrawlComponentByIDPath(ComponentSetup* pRelativeRoot, const IDPath& idPath) 00095 { 00096 if (idPath.IsEmpty()) 00097 { 00098 m_Findings.push_back(pRelativeRoot); 00099 return; 00100 }; 00101 00102 //if not dispatch passed path 00103 std::string sTag; 00104 IDPath::PathElementType token = idPath.GetFirstComponent(sTag); 00105 00106 //This is like self reference by default, hence it won't be checked in the switch statement 00107 IDPath nextPath = idPath.GetSubIDPath(); 00108 00109 if (idPath.IsAbsolute()) 00110 { 00111 nextPath = idPath; 00112 nextPath.SetAbsolute(false); 00113 CrawlComponentByIDPath(pRelativeRoot->GetRootComponent(),nextPath); 00114 } 00115 else 00116 { 00117 switch(token) 00118 { 00119 case IDPath::PTAnyDescendant: 00120 { 00121 for (unsigned int index = 0; index<pRelativeRoot->Components().Size(); index++) 00122 { 00123 //Allow every child 00124 CrawlComponentByIDPath(pRelativeRoot->Components().GetElement(index),nextPath); 00125 //Also allow any descendant 00126 CrawlComponentByIDPath(pRelativeRoot->Components().GetElement(index),idPath); 00127 }; 00128 break; 00129 } 00130 case IDPath::PTParent: 00131 { 00132 if (pRelativeRoot->GetParentComponent()) 00133 { 00134 CrawlComponentByIDPath(pRelativeRoot->GetParentComponent(),nextPath); 00135 } 00136 break; 00137 } 00138 case IDPath::PTAnyChild: 00139 { 00140 for (unsigned int index = 0; index<pRelativeRoot->Components().Size(); index++) 00141 { 00142 //Allow every child 00143 CrawlComponentByIDPath(pRelativeRoot->Components().GetElement(index),nextPath); 00144 }; 00145 break; 00146 } 00147 case IDPath::PTComponent: 00148 { 00149 ComponentSetup* pNext = pRelativeRoot->Components().GetElement(sTag); 00150 if (pNext) 00151 { 00152 CrawlComponentByIDPath(pNext,nextPath); 00153 } 00154 break; 00155 } 00156 case IDPath::PTMedia: 00157 { //When we reached the media definition in an IDPath, we've found one. 00158 m_Findings.push_back(pRelativeRoot); 00159 break; 00160 } 00161 case IDPath::PTParameter: 00162 { //When we reached the parameter definition in an IDPath, we've found one. 00163 m_Findings.push_back(pRelativeRoot); 00164 break; 00165 } 00166 } 00167 } 00168 }; 00169 00170 }//end of namespace FREE
1.5.3 written by Dimitri van Heesch,
© 1997-2000