freParameterListIO.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: 2007/05/04 12:00:00 $
00006   Module:    $RCSfile: freParameterListIO.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 
00023 #include "freParameterListIO.h"
00024 
00025 #include "freSessionAccessor.h"
00026 
00027 namespace FREE
00028 {
00029 void
00030 ParameterListIO::
00031 SetComponentCache(SessionComponentCache* pCache)
00032 {
00033   m_pCache = pCache;
00034 };
00035 
00036 SessionComponentCache*
00037 ParameterListIO::
00038 GetComponentCache()
00039 {
00040   return m_pCache;
00041 };
00042 
00043 ParameterListIO::~ParameterListIO()
00044 {
00045 };
00046 
00047 ParameterListIO::
00048 ParameterListIO()
00049 {
00050   m_pCache = 0;
00051 };
00052 
00053 void
00054 ParameterListIO::
00055 AddParameterLink(const std::string& sName, const IDPath& idPath)
00056 {
00057   m_Links[sName] = idPath;
00058 };
00059 
00060 void
00061 ParameterListIO::
00062 DeleteParameterLink(const std::string& sName)
00063 {
00064   m_Links.erase(sName);
00065 };
00066 
00067 IDPath
00068 ParameterListIO::
00069 GetParameterLink(const std::string& sName)
00070 {
00071   return m_Links[sName];
00072 };
00073 
00074 void
00075 ParameterListIO::
00076 ResetParameterLinks()
00077 {
00078   m_Links.clear();
00079 };
00080 
00081 void
00082 ParameterListIO::
00083 SaveListToFile(const std::string& sFileName)
00084 {
00085   if (!m_pCache) throwExceptionMacro("Error. Cannot save parameters. No cache specified.");
00086   ParameterCollection parameterList;
00087 
00088   for (ParameterLinkMapType::const_iterator pos= m_Links.begin(); pos!=m_Links.end(); pos++)
00089   {
00090     Parameter::Pointer smpSourceParam = SessionAccessor::GetParameterByIDPath(m_pCache, pos->second);
00091     if (smpSourceParam.IsNull()) throwExceptionMacro("Error. Cannot save parameter. Link does not point to an existant parameter. Link: "<<pos->second.ToStr());
00092 
00093     Parameter::Pointer smpDestParam = parameterList.AddParameter(pos->first);
00094     smpDestParam->operator = (*(smpSourceParam.GetPointer()));
00095     smpDestParam->SetParameterName(pos->first);
00096   }
00097 
00098   try
00099   {
00100     parameterList.SaveToFile(sFileName);
00101   }
00102   catchAllNPassMacro("Error while saving parameter list");
00103 };
00104   
00105 void
00106 ParameterListIO::
00107 LoadListFromFile(const std::string& sFileName)
00108 {
00109   if (!m_pCache) throwExceptionMacro("Error. Cannot load parameters. No cache specified.");
00110   if (! (m_pCache->Setup())) throwExceptionMacro("Error. Cannot load parameters. cache has no setup.");
00111 
00112   ParameterCollection parameterList;
00113   try
00114   {
00115     parameterList.LoadFromFile(sFileName);
00116   }
00117   catchAllNPassMacro("Error while saving parameter list");
00118 
00119   for (ParameterLinkMapType::const_iterator pos= m_Links.begin(); pos!=m_Links.end(); pos++)
00120   {
00121     Parameter::Pointer smpSourceParam = parameterList.GetParameter(pos->first);
00122     if (smpSourceParam.IsNull()) throwExceptionMacro("Error. Cannot set parameter. Parameter is not in list. File: "<<sFileName<<"; Parameter: "<<pos->first);
00123 
00124     ComponentSetup* pCompSetup = m_pCache->Setup()->GetComponentByIDPath(pos->second.GetParentComponentIDPath());
00125 
00126     if (!pCompSetup) throwExceptionMacro("Error. Cannot set parameter. Link does not point to an existant component. Link: "<<pos->second.ToStr());
00127 
00128     Parameter::Pointer smpDestParam = pCompSetup->Parameters().GetParameter(pos->second.GetParameterName());
00129 
00130     if (smpDestParam.IsNull()) throwExceptionMacro("Error. Cannot set parameter. Link does not point to an existant parameter. Link: "<<pos->second.ToStr());
00131 
00132     smpDestParam->operator = (*(smpSourceParam.GetPointer()));
00133     smpDestParam->SetParameterName(pos->second.GetParameterName());
00134   }
00135 };
00136   
00137 
00138 } //end of namespace

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