freParameterCollection.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: freParameter.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 "freParameterCollection.h"
00023 
00024 #include "freConvert.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 
00034 Parameter*
00035 ParameterCollection::
00036 AddParameter(const std::string& sParameterName, const ValueCountType iLayerSize, const LayerCountType iLayerCount)
00037 {
00038   Parameter::Pointer smpNewParameter = Parameter::New(sParameterName,iLayerSize,iLayerCount);
00039   m_Parameters.push_back(smpNewParameter);
00040   return smpNewParameter;
00041 };
00042 
00043 void
00044 ParameterCollection::
00045 DeleteParameter(const std::string& sParameterName)
00046 {
00047   ParameterCountType index = GetParameterIndex(sParameterName);
00048   if (index!=-1)
00049   {
00050     DeleteParameter(index);
00051   };
00052 };
00053 
00054 void
00055 ParameterCollection::
00056 DeleteParameter(const ParameterCountType index)
00057 {
00058   if (index<m_Parameters.size())
00059   {
00060     m_Parameters.erase(m_Parameters.begin()+index);
00061   };
00062 };
00063 
00064 void
00065 ParameterCollection::
00066 AddParameterLayer(const std::string& sParameterName, bool bCopyValue)
00067 {
00068   ParameterCountType index = GetParameterIndex(sParameterName);
00069   if (index!=-1)
00070   {
00071     m_Parameters[index]->AddParameterLayer(bCopyValue);
00072   };
00073 };
00074 
00075 void
00076 ParameterCollection::
00077 DeleteParameterLayer(const std::string& sParameterName, const LayerCountType iLayer)
00078 {
00079   ParameterCountType index = GetParameterIndex(sParameterName);
00080   if (index!=-1)
00081   {
00082     m_Parameters[index]->DeleteParameterLayer(iLayer);
00083   };
00084 };
00085 
00086 void
00087 ParameterCollection::
00088 ResetParameters()
00089 {
00090   while (m_Parameters.size()>0)
00091   {
00092     DeleteParameter(0);
00093   };
00094 };
00095 
00096 
00097 void
00098 ParameterCollection::
00099 Reset()
00100 {
00101   XMLStreamObject::Reset();
00102   ResetParameters();
00103 };
00104 
00105 bool
00106 ParameterCollection::
00107 ParameterExists(const std::string& sParameterName) const
00108 {
00109   return GetParameterIndex(sParameterName)!=-1;
00110 };
00111 
00112 ParameterCollection::ParameterCountType
00113 ParameterCollection::
00114 Size() const
00115 {
00116   return m_Parameters.size();
00117 };
00118 
00119 ParameterCollection::ValueCountType
00120 ParameterCollection::
00121 ParameterSize(const std::string& sParameterName) const
00122 {
00123   ParameterCountType index = GetParameterIndex(sParameterName);
00124   if (index==-1) return 0;
00125 
00126   return m_Parameters[index]->ParameterSize();  
00127 };
00128 
00129 ParameterCollection::LayerCountType
00130 ParameterCollection::
00131 ParameterLayerCount(const std::string& sParameterName) const
00132 {
00133   ParameterCountType index = GetParameterIndex(sParameterName);
00134   if (index==-1) return 0;
00135 
00136   return m_Parameters[index]->LayerCount();  
00137 };
00138 
00139 ParameterCollection::ParameterCountType
00140 ParameterCollection::
00141 GetParameterIndex(const std::string& sParameterName) const
00142 {
00143   ParameterCountType index = 0; 
00144   for (ParametersType::const_iterator pos = m_Parameters.begin(); pos!=m_Parameters.end(); pos++)
00145   {
00146     if ((*pos)->GetParameterName()==sParameterName) return index;
00147     index++;
00148   };
00149   return -1;
00150 };
00151 
00152 std::string
00153 ParameterCollection::
00154 GetParameterName(const ParameterCountType& index) const
00155 {
00156   if (index<m_Parameters.size()) return m_Parameters[index]->GetParameterName();
00157 
00158   return "";
00159 };
00160 
00161 bool
00162 ParameterCollection::
00163 GetParameterValue(const std::string& sParameterName, bool& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00164 {  
00165   ParameterCountType index = GetParameterIndex(sParameterName);
00166   if (index==-1) return false;
00167   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00168 };
00169 
00170 bool
00171 ParameterCollection::
00172 GetParameterValue(const std::string& sParameterName, double& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00173 {  
00174   ParameterCountType index = GetParameterIndex(sParameterName);
00175   if (index==-1) return false;
00176   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00177 };
00178   
00179 bool
00180 ParameterCollection::
00181 GetParameterValue(const std::string& sParameterName, int& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00182 {  
00183   ParameterCountType index = GetParameterIndex(sParameterName);
00184   if (index==-1) return false;
00185   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00186 };
00187 
00188 bool
00189 ParameterCollection::
00190 GetParameterValue(const std::string& sParameterName, long& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00191 {  
00192   ParameterCountType index = GetParameterIndex(sParameterName);
00193   if (index==-1) return false;
00194   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00195 };
00196 
00197 bool
00198 ParameterCollection::
00199 GetParameterValue(const std::string& sParameterName, unsigned long& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00200 {  
00201   ParameterCountType index = GetParameterIndex(sParameterName);
00202   if (index==-1) return false;
00203   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00204 };
00205 
00206 bool
00207 ParameterCollection::
00208 GetParameterValue(const std::string& sParameterName, std::string& value, const  ValueCountType iItemPos, const LayerCountType iLayer) const
00209 {  
00210   ParameterCountType index = GetParameterIndex(sParameterName);
00211   if (index==-1) return false;
00212   return m_Parameters[index]->GetParameterValue(value,iItemPos,iLayer);
00213 };
00214 
00215 bool
00216 ParameterCollection::
00217 GetParameterValueByIDPath(const IDPath& parameterID, bool& value) const
00218 {  
00219   std::string sParameterName;
00220   ValueCountType iItemPos = 0;
00221   LayerCountType iLayer = 0;
00222 
00223   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00224   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00225 };
00226 
00227 bool
00228 ParameterCollection::
00229 GetParameterValueByIDPath(const IDPath& parameterID, double& value) const
00230 {  
00231   std::string sParameterName;
00232   ValueCountType iItemPos = 0;
00233   LayerCountType iLayer = 0;
00234 
00235   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00236   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00237 };
00238   
00239 bool
00240 ParameterCollection::
00241 GetParameterValueByIDPath(const IDPath& parameterID, int& value) const
00242 {  
00243   std::string sParameterName;
00244   ValueCountType iItemPos = 0;
00245   LayerCountType iLayer = 0;
00246 
00247   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00248   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00249 };
00250 
00251 bool
00252 ParameterCollection::
00253 GetParameterValueByIDPath(const IDPath& parameterID, long& value) const
00254 {  
00255   std::string sParameterName;
00256   ValueCountType iItemPos = 0;
00257   LayerCountType iLayer = 0;
00258 
00259   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00260   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00261 };
00262 
00263 bool
00264 ParameterCollection::
00265 GetParameterValueByIDPath(const IDPath& parameterID, unsigned long& value) const
00266 {  
00267   std::string sParameterName;
00268   ValueCountType iItemPos = 0;
00269   LayerCountType iLayer = 0;
00270 
00271   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00272   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00273 };
00274 
00275 bool
00276 ParameterCollection::
00277 GetParameterValueByIDPath(const IDPath& parameterID, std::string& value) const
00278 {  
00279   std::string sParameterName;
00280   ValueCountType iItemPos = 0;
00281   LayerCountType iLayer = 0;
00282 
00283   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00284   return GetParameterValue(sParameterName,value,iItemPos,iLayer);
00285 };
00286 
00287 Parameter*
00288 ParameterCollection::
00289 GetParameter(const std::string& sParameterName) const
00290 {
00291   return GetParameter(GetParameterIndex(sParameterName));
00292 };
00293 
00294 Parameter*
00295 ParameterCollection::
00296 GetParameter(ParameterCountType index) const
00297 {
00298   if (index>=Size()) return NULL;
00299   return m_Parameters[index];
00300 };
00301 
00302 bool
00303 ParameterCollection::
00304 SetParameterValue(const std::string& sParameterName, const bool value, const ValueCountType iItemPos, const LayerCountType iLayer)
00305 {  
00306   ParameterCountType index = GetParameterIndex(sParameterName);
00307   if (index==-1) return false;
00308   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00309 };
00310 
00311 bool
00312 ParameterCollection::
00313 SetParameterValue(const std::string& sParameterName, const double value, const ValueCountType iItemPos, const LayerCountType iLayer)
00314 {  
00315   ParameterCountType index = GetParameterIndex(sParameterName);
00316   if (index==-1) return false;
00317   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00318 };
00319   
00320 bool
00321 ParameterCollection::
00322 SetParameterValue(const std::string& sParameterName, const int value, const ValueCountType iItemPos, const LayerCountType iLayer)
00323 {  
00324   ParameterCountType index = GetParameterIndex(sParameterName);
00325   if (index==-1) return false;
00326   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00327 };
00328 
00329 bool
00330 ParameterCollection::
00331 SetParameterValue(const std::string& sParameterName, const long value, const ValueCountType iItemPos, const LayerCountType iLayer)
00332 {  
00333   ParameterCountType index = GetParameterIndex(sParameterName);
00334   if (index==-1) return false;
00335   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00336 };
00337 
00338 bool
00339 ParameterCollection::
00340 SetParameterValue(const std::string& sParameterName, const unsigned long value, const ValueCountType iItemPos, const LayerCountType iLayer)
00341 {  
00342   ParameterCountType index = GetParameterIndex(sParameterName);
00343   if (index==-1) return false;
00344   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00345 };
00346 
00347 bool
00348 ParameterCollection::
00349 SetParameterValue(const std::string& sParameterName, const std::string& value, const ValueCountType iItemPos, const LayerCountType iLayer)
00350 {  
00351   ParameterCountType index = GetParameterIndex(sParameterName);
00352   if (index==-1) return false;
00353   return m_Parameters[index]->SetParameterValue(value,iItemPos,iLayer);
00354 };
00355 
00356 bool
00357 ParameterCollection::
00358 SetParameterValueByIDPath(const IDPath& parameterID, bool& value)
00359 {  
00360   std::string sParameterName;
00361   ValueCountType iItemPos = 0;
00362   LayerCountType iLayer = 0;
00363 
00364   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00365   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00366 };
00367 
00368 bool
00369 ParameterCollection::
00370 SetParameterValueByIDPath(const IDPath& parameterID, double& value)
00371 {  
00372   std::string sParameterName;
00373   ValueCountType iItemPos = 0;
00374   LayerCountType iLayer = 0;
00375 
00376   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00377   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00378 };
00379   
00380 bool
00381 ParameterCollection::
00382 SetParameterValueByIDPath(const IDPath& parameterID, int& value)
00383 {  
00384   std::string sParameterName;
00385   ValueCountType iItemPos = 0;
00386   LayerCountType iLayer = 0;
00387 
00388   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00389   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00390 };
00391 
00392 bool
00393 ParameterCollection::
00394 SetParameterValueByIDPath(const IDPath& parameterID, long& value)
00395 {  
00396   std::string sParameterName;
00397   ValueCountType iItemPos = 0;
00398   LayerCountType iLayer = 0;
00399 
00400   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00401   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00402 };
00403 
00404 bool
00405 ParameterCollection::
00406 SetParameterValueByIDPath(const IDPath& parameterID, unsigned long& value)
00407 {  
00408   std::string sParameterName;
00409   ValueCountType iItemPos = 0;
00410   LayerCountType iLayer = 0;
00411 
00412   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00413   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00414 };
00415 
00416 bool
00417 ParameterCollection::
00418 SetParameterValueByIDPath(const IDPath& parameterID, std::string& value)
00419 {  
00420   std::string sParameterName;
00421   ValueCountType iItemPos = 0;
00422   LayerCountType iLayer = 0;
00423 
00424   DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00425   return SetParameterValue(sParameterName,value,iItemPos,iLayer);
00426 };
00427 
00428 ParameterCollection&
00429 ParameterCollection::
00430 operator = (const ParameterCollection& rParameterCollection)
00431 {
00432   if (this == &rParameterCollection) return *this;
00433 
00434   Reset();
00435 
00436   for (ParameterCountType i=0; i < rParameterCollection.Size(); i++)
00437   {
00438     ParameterPointer smpNewParameter = Parameter::New();
00439     *(smpNewParameter.GetPointer()) = *(rParameterCollection.GetParameter(i));
00440     m_Parameters.push_back(smpNewParameter);
00441   };
00442 
00443   return *this;
00444 };
00445 
00446 ParameterCollection::
00447 ParameterCollection() : XMLStreamObject(cXML_ComponentParameters)
00448 {
00449   Reset();
00450 };
00451 
00452 ParameterCollection::
00453 ParameterCollection( const ParameterCollection& rParameterCollection) : XMLStreamObject(cXML_ComponentParameters)
00454 {
00455   *this = rParameterCollection;
00456 };
00457 
00458 ParameterCollection::
00459 ~ParameterCollection()
00460 {
00461   Reset();
00462 };
00463 
00464 void
00465 ParameterCollection::
00466 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00467 {
00468   if (rsXMLSubTag==cXML_Parameter)
00469   {
00470     ParameterPointer smpNewParameter = Parameter::New();
00471 
00472     try
00473     {
00474       smpNewParameter->LoadFromString(rsXMLSubElement);
00475     }
00476     catchAllNPassMacro("Unknown error occured while loading parameter for a collection.");
00477 
00478     m_Parameters.push_back(smpNewParameter);
00479   }
00480   else if (rsXMLSubTag!=cXML_Text) throwExceptionMacro("Unknown xml tag, unable to load value. Incorrect Tag: " << rsXMLSubTag);
00481 };
00482 
00483 std::string
00484 ParameterCollection::
00485 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00486 {
00487   std::string sResult;
00488   for(ParametersType::const_iterator pos = m_Parameters.begin(); pos != m_Parameters.end(); pos++)
00489   {
00490     AddSubElement(sResult,(*pos),iDepth);
00491   };
00492   return sResult;
00493 };
00494 
00495 }//end of namespace FREE

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