freProfileOption.cxx

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: freProfileOption.h,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 "freProfileOption.h"
00023 
00024 namespace FREE
00025 {
00026 namespace CtrlProfile
00027 {
00028 
00029 bool
00030 ProfileOption::
00031 ProfileMatchesOption(const ControllerProfileBase& profile) const
00032 {
00033   bool bTempResult;
00034   if (m_bControllerID)
00035   { //the class of the component must realy equal
00036     if (m_sControllerID != profile.ControllerID()) return false;
00037   }
00038 
00039   if (m_bInheritance)
00040   { //ID or an ancestor of the profile must be within the inharitance of the option
00041     bTempResult = false;
00042 
00043     if(m_Inheritance.IsChildOf(profile.ControllerID())) bTempResult = true;
00044 
00045     if(!bTempResult)
00046     { //check the inharitances
00047       for (ProfileInheritance::ElementIndexType i = 0; i<m_Inheritance.Size(); i++)
00048       {
00049         if(profile.Inheritance().IsChildOf(m_Inheritance.GetAncestor(0))) bTempResult = true;
00050       }
00051     }
00052 
00053     if (!bTempResult) return false; //there was no match in the inheritances
00054   }
00055 
00056   if (m_bDescription)
00057   { //the class of the component must realy equal
00058     if (m_sDescription != profile.Description()) return false;
00059   }
00060 
00061   if (m_bParameters)
00062   { //check if all parameters of the option are present in the passed profile
00063     for (ProfileParameters::ElementsCountType i = 0; i<m_Parameters.Size(); i++)
00064     {
00065       Parameter* pParam = m_Parameters.GetElement(i);
00066       if (!profile.Parameters().ParameterExists(pParam->GetParameterName())) return false;
00067     }
00068   }
00069 
00070   if (m_bSubComponents)
00071   { //check if all subcomponents of the option are present in the passed profile
00072     for (ProfileSubComponents::ElementsCountType i = 0; i<m_SubComponents.Size(); i++)
00073     {
00074       SubComponent* pComp = m_SubComponents.GetElement(i);
00075       if (!profile.SubComponents().GetElement(pComp->GetComponentID())) return false;
00076     }
00077   }
00078 
00079   if (m_bIO)
00080   { 
00081     //check if all streams of the option are present in the passed profile
00082     for (ProfileMediaMap::ElementsCountType i = 0; i<m_MediaMap.Size(); i++)
00083     {
00084       bTempResult = true;
00085 
00086       Media* pMedia = m_MediaMap.GetElement(i);
00087 
00088       if (pMedia->GetDimension()!=Media::DT_AllDimensions)
00089       { //if the option would allow all dimension we must not check, so we must
00090         bTempResult = false;
00091 
00092         for (ProfileMediaMap::ElementsCountType j = 0; j<profile.MediaMap().Size(); j++)
00093         { //check every stream if he has the right dimension or is suitabe for any
00094           Media* pProfileMedia = profile.MediaMap().GetElement(j);
00095           if ((pMedia->GetDimension()==pProfileMedia->GetDimension())||
00096               (Media::DT_AllDimensions==pProfileMedia->GetDimension())) bTempResult = true;
00097         }
00098       }
00099       if (!bTempResult) return false; //the stream given in the option was not found
00100     }
00101   }
00102 
00103   //made it so far this profile realy matches the option
00104   return true;
00105 };
00106 
00107 ProfileOption::
00108 ProfileOption()
00109 {
00110   SetXMLTag(cXML_CP_ProfileOption);
00111         Reset();
00112 };
00113 
00114 ProfileOption&
00115 ProfileOption::
00116 operator = (const ProfileOption& rProfile)
00117 {
00118         m_sControllerID = rProfile.ControllerID();
00119         m_Inheritance = rProfile.Inheritance();
00120         m_sDescription = rProfile.Description();
00121         m_Parameters = rProfile.Parameters();
00122         m_SubComponents = rProfile.SubComponents();
00123         m_MediaMap = rProfile.MediaMap();
00124 
00125         m_bControllerID = rProfile.m_bControllerID;
00126         m_bInheritance = rProfile.m_bInheritance;
00127         m_bDescription = rProfile.m_bDescription;
00128         m_bParameters = rProfile.m_bParameters;
00129         m_bSubComponents = rProfile.m_bSubComponents;
00130         m_bIO = rProfile.m_bIO;
00131 
00132   return *this;
00133 };
00134 
00135 void
00136 ProfileOption::
00137 Reset()
00138 {
00139   ControllerProfileBase::Reset();
00140 
00141         m_bControllerID = false;
00142         m_bInheritance = false;
00143         m_bDescription = false;
00144         m_bParameters = false;
00145         m_bSubComponents = false;
00146         m_bIO = false;
00147 };
00148 
00149 ProfileOption::
00150 ~ProfileOption()
00151 {
00152   Reset();
00153 };
00154 
00155 void
00156 ProfileOption::
00157 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00158 {
00159   if (rsXMLSubTag==cXML_CP_ControllerID)
00160   {
00161     m_sControllerID = rsXMLSubData;
00162     m_bControllerID = true;
00163   }
00164   else if (rsXMLSubTag==cXML_CP_Inheritance)
00165   {
00166     m_Inheritance.LoadFromString(rsXMLSubElement);
00167     m_bInheritance = true;
00168   }
00169   else if (rsXMLSubTag==cXML_CP_Description)
00170   {
00171     m_sDescription = rsXMLSubData;
00172     m_bDescription = true;
00173   }
00174   else if (rsXMLSubTag==cXML_CP_Parameters)
00175   {
00176     m_Parameters.LoadFromString(rsXMLSubElement);
00177     m_bParameters = true;
00178   }
00179   else if (rsXMLSubTag==cXML_CP_SubComponents)
00180   {
00181     m_SubComponents.LoadFromString(rsXMLSubElement);
00182     m_bSubComponents = true;
00183   }
00184   else if (rsXMLSubTag==cXML_CP_MediaMap)
00185   {
00186     m_MediaMap.LoadFromString(rsXMLSubElement);
00187     m_bIO = true;
00188   }
00189 };
00190 
00191 std::string
00192 ProfileOption::
00193 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00194 {
00195   std::string result;
00196 
00197   if (m_bControllerID) AddSubElement(result,cXML_CP_ControllerID,m_sControllerID,iDepth);
00198   if (m_bInheritance) AddSubElement(result,&m_Inheritance,iDepth);
00199   if (m_bDescription) AddSubElement(result,cXML_CP_Description,m_sDescription,iDepth);
00200   if (m_bParameters) AddSubElement(result,&m_Parameters,iDepth);
00201   if (m_bSubComponents) AddSubElement(result,&m_SubComponents,iDepth);
00202   if (m_bIO) AddSubElement(result,&m_MediaMap,iDepth);
00203   return result;
00204 };
00205 }//end of namespace CtrlProfile
00206 }//end of namespace FREE

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