00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freComponentSetup.h"
00023
00024 #include "freConvert.h"
00025 #include "freComponentSetupCollection.h"
00026
00027 namespace FREE
00028 {
00029
00033
00034 void
00035 ComponentSetup::
00036 SetControllerID(const std::string& sControllerID)
00037 {
00038 m_sControllerID = sControllerID;
00039 };
00040
00041 void
00042 ComponentSetup::
00043 SetComponentID( const ComponentID& componentID )
00044 {
00045 m_ComponentID = componentID;
00046 };
00047
00048 bool
00049 ComponentSetup::
00050 operator == (const std::string& sControllerID) const
00051 {
00052 return sControllerID == m_sControllerID;
00053 };
00054
00055 ComponentSetup&
00056 ComponentSetup::
00057 operator = (const ComponentSetup& rComponentSetup)
00058 {
00059 if (this == &rComponentSetup) return *this;
00060
00061 Reset();
00062
00063 m_sControllerID = rComponentSetup.GetControllerID();
00064 m_sTemplateID = rComponentSetup.GetTemplateID();
00065 m_sComment = rComponentSetup.GetComment();
00066 m_ComponentID = rComponentSetup.GetComponentID();
00067 m_Parameters = rComponentSetup.Parameters();
00068 m_Links = rComponentSetup.MediaLinks();
00069
00070 delete m_Components;
00071 m_Components = new ComponentSetupCollection(this);
00072 *m_Components = rComponentSetup.Components();
00073
00074 return *this;
00075 };
00076
00077
00078 bool
00079 ComponentSetup::
00080 HasParentComponent() const
00081 {
00082 return m_pParent!=NULL;
00083 };
00084
00085 const ComponentSetup*
00086 ComponentSetup::
00087 GetParentComponent() const
00088 { return m_pParent; };
00089
00090 ComponentSetup*
00091 ComponentSetup::
00092 GetParentComponent()
00093 { return m_pParent; };
00094
00095 const ComponentSetup*
00096 ComponentSetup::
00097 GetRootComponent() const
00098 {
00099 if (m_pParent) return m_pParent->GetRootComponent();
00100 return this;
00101 };
00102
00103 ComponentSetup*
00104 ComponentSetup::
00105 GetRootComponent()
00106 {
00107 if (m_pParent) return m_pParent->GetRootComponent();
00108 return this;
00109 };
00110
00111 ComponentSetup*
00112 ComponentSetup::
00113 GetComponentByIDPath(const IDPath& idPath)
00114 {
00115 if (idPath.IsEmpty()) return this;
00116
00117
00118 std::string sTag;
00119 IDPath::PathElementType token = idPath.GetFirstComponent(sTag);
00120
00121
00122 IDPath nextPath = idPath.GetSubIDPath();
00123 ComponentSetup* pNext = this;
00124
00125 if (idPath.IsAbsolute())
00126 {
00127 pNext = GetRootComponent();
00128 nextPath = idPath;
00129 nextPath.SetAbsolute(false);
00130 }
00131 else
00132 {
00133 switch(token)
00134 {
00135 case IDPath::PTAnyDescendant:
00136 throwExceptionMacro("IDPath must be well defined. No Wildcards of any kind (*, //) are allowed. IDPath: " << idPath.ToStr());
00137 case IDPath::PTParent:
00138 pNext = GetParentComponent(); break;
00139 case IDPath::PTAnyChild:
00140 throwExceptionMacro("IDPath must be well defined. No Wildcards of any kind (*, //) are allowed. IDPath: " << idPath.ToStr());
00141 case IDPath::PTComponent:
00142 pNext = Components().GetElement(sTag); break;
00143 case IDPath::PTNULL:
00144 throwExceptionMacro("IDPath is invalid, contains undefined path element . IDPath: " << idPath.ToStr());
00145 }
00146 }
00147
00148 if (!pNext) return NULL;
00149 return pNext->GetComponentByIDPath(nextPath);
00150 };
00151
00152 IDPath
00153 ComponentSetup::
00154 GetIDPath() const
00155 {
00156 IDPath path;
00157 if (HasParentComponent()) path = m_pParent->GetIDPath();
00158
00159 path = path + IDPath(m_ComponentID);
00160 return path;
00161 };
00162
00163 ComponentSetup::
00164 ComponentSetup( ):XMLStreamObject(cXML_Component)
00165 {
00166 m_Components = new ComponentSetupCollection(this);
00167
00168 Reset();
00169
00170 m_ComponentID = cComp_NotDefined;
00171 m_pParent = 0;
00172 };
00173
00174 ComponentSetup::
00175 ComponentSetup(ComponentSetup* pParentComponent,
00176 const ComponentID& compID):XMLStreamObject(cXML_Component)
00177 {
00178 m_Components = new ComponentSetupCollection(this);
00179
00180 Reset();
00181
00182 SetComponentID(compID);
00183
00184 m_pParent = pParentComponent;
00185 };
00186
00187 ComponentSetup::Pointer
00188 ComponentSetup::
00189 New(ComponentSetup* pParentComponent,
00190 const ComponentID& compID)
00191 {
00192 Pointer smartPtr;
00193 ComponentSetup *rawPtr = ::itk::ObjectFactory<ComponentSetup>::Create();
00194 if(rawPtr == NULL)
00195 {
00196 rawPtr = new ComponentSetup(pParentComponent, compID);
00197 }
00198 smartPtr = rawPtr;
00199 rawPtr->UnRegister();
00200
00201 return smartPtr;
00202 };
00203
00204 ComponentSetup::
00205 ~ComponentSetup()
00206 {
00207 Reset();
00208 delete m_Components;
00209 };
00210
00211 void ComponentSetup::Reset()
00212 {
00213 XMLStreamObject::Reset();
00214 m_ComponentID = "";
00215 m_sControllerID = "";
00216 m_sTemplateID = "";
00217 m_sComment = "";
00218
00219 ResetParameters();
00220 m_Links.Reset();
00221 m_Components->Reset();
00222 };
00223
00224 void ComponentSetup::ResetParameters()
00225 {
00226 m_Parameters.Reset();
00227 };
00228
00229 void
00230 ComponentSetup::
00231 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00232 {
00233 if (rsXMLSubTag==cXML_Components)
00234 {
00235 m_Components->LoadFromString(rsXMLSubElement);
00236 }
00237 else if (rsXMLSubTag==cXML_ComponentComment)
00238 {
00239 m_sComment = rsXMLSubData;
00240 }
00241 else if (rsXMLSubTag==cXML_ComponentParameters)
00242 {
00243 m_Parameters.LoadFromString(rsXMLSubElement);
00244 }
00245 else if (rsXMLSubTag==cXML_MediaLinks)
00246 {
00247 m_Links.LoadFromString(rsXMLSubElement);
00248 }
00249 else if (rsXMLSubTag!=cXML_Text) throwExceptionMacro("Unknown xml tag, unable to load value. Incorrect Tag: "<< rsXMLSubTag);
00250 };
00251
00252 std::string
00253 ComponentSetup::
00254 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00255 {
00256 std::string sResult;
00257 if (m_sComment.size()!=0) AddSubElement(sResult,cXML_ComponentComment,m_sComment,iDepth);
00258 if (m_Parameters.Size()!=0) AddSubElement(sResult,&m_Parameters,iDepth);
00259 if (m_Links.Size()!=0) AddSubElement(sResult,&m_Links,iDepth);
00260 if (m_Components->Size()!=0) AddSubElement(sResult,m_Components,iDepth);
00261
00262 return sResult;
00263 };
00264
00265 void
00266 ComponentSetup::
00267 AttributesLoadProcessing(const AttributesType& rAttributes)
00268 {
00269 for (AttributesType::const_iterator pos = rAttributes.begin(); pos!= rAttributes.end(); pos++)
00270 {
00271 if (pos->first==cXML_ComponentControllerID) m_sControllerID = pos->second;
00272 else if (pos->first==cXML_ComponentID) m_ComponentID = pos->second;
00273 else if (pos->first==cXML_TemplateID) m_sTemplateID = pos->second;
00274 };
00275 };
00276
00277 void
00278 ComponentSetup::
00279 SaveAttributes(AttributesSaveListType& rAttributes) const
00280 {
00281 rAttributes.push_back(AttributesType::value_type(cXML_ComponentID,m_ComponentID));
00282 if (m_sControllerID!=csUndefinedController) rAttributes.push_back(AttributesType::value_type(cXML_ComponentControllerID,m_sControllerID));
00283 if (IsTemplateBased()) rAttributes.push_back(AttributesType::value_type(cXML_TemplateID,m_sTemplateID));
00284 };
00285
00286 }