freXMLValueSet.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: freXMLValueSet.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 "freXMLValueSet.h"
00023 #include "freExceptions.h"
00024 #include "freConvert.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 
00034 void
00035 XMLValueSet::
00036 Reset(const XMLValueSet::ValueCountType iValueCount, const std::string& sNewValue)
00037 {
00038   Reset();
00039   m_Values.resize(iValueCount, sNewValue);
00040 };
00041 
00042 void
00043 XMLValueSet::
00044 Resize(const XMLValueSet::ValueCountType iNewSize, const std::string& sNewValue)
00045 {
00046   m_Values.resize(iNewSize, sNewValue);
00047 };
00048 
00049 XMLValueSet::ValueCountType
00050 XMLValueSet::
00051 Size() const
00052 {
00053   return m_Values.size();
00054 };
00055 
00056 bool
00057 XMLValueSet::
00058 GetValue(bool& value, XMLValueSet::ValueCountType iItemPos) const
00059 {
00060   std::string  sValue;
00061   bool bResult = GetValue(sValue,iItemPos);
00062 
00063   if (bResult) value = Convert::ToBool(sValue);
00064   return bResult;
00065 };
00066 
00067 bool
00068 XMLValueSet::
00069 GetValue(double& value, XMLValueSet::ValueCountType iItemPos) const
00070 {
00071   std::string  sValue;
00072   bool bResult = GetValue(sValue,iItemPos);
00073 
00074   if (bResult) value = Convert::ToDouble(sValue);
00075   return bResult;
00076 };
00077   
00078 bool
00079 XMLValueSet::
00080 GetValue(float& value, XMLValueSet::ValueCountType iItemPos) const
00081 {
00082   std::string  sValue;
00083   bool bResult = GetValue(sValue,iItemPos);
00084 
00085   if (bResult) value = Convert::ToFloat(sValue);
00086   return bResult;
00087 };
00088 
00089 bool
00090 XMLValueSet::
00091 GetValue(int& value, XMLValueSet::ValueCountType iItemPos) const
00092 {
00093   std::string  sValue;
00094   bool bResult = GetValue(sValue,iItemPos);
00095 
00096   if (bResult) value = Convert::ToInt(sValue);
00097   return bResult;
00098 };
00099 
00100 bool
00101 XMLValueSet::
00102 GetValue(unsigned int& value, XMLValueSet::ValueCountType iItemPos) const
00103 {
00104   std::string  sValue;
00105   bool bResult = GetValue(sValue,iItemPos);
00106 
00107   if (bResult) value = Convert::ToUInt(sValue);
00108   return bResult;
00109 };
00110 
00111 bool
00112 XMLValueSet::
00113 GetValue(long& value, XMLValueSet::ValueCountType iItemPos) const
00114 {
00115   std::string  sValue;
00116   bool bResult = GetValue(sValue,iItemPos);
00117 
00118   if (bResult) value = Convert::ToLong(sValue);
00119   return bResult;
00120 };
00121 
00122 bool
00123 XMLValueSet::
00124 GetValue(unsigned long& value, XMLValueSet::ValueCountType iItemPos) const
00125 {
00126   std::string  sValue;
00127   bool bResult = GetValue(sValue,iItemPos);
00128 
00129   if (bResult) value = Convert::ToULong(sValue);
00130   return bResult;
00131 };
00132 
00133 bool
00134 XMLValueSet::
00135 GetValue(std::string& value, XMLValueSet::ValueCountType iItemPos) const
00136 {
00137   if (iItemPos>=m_Values.size()) return false;
00138 
00139   value = m_Values[iItemPos];
00140   return true;
00141 };
00142 
00143 bool
00144 XMLValueSet::
00145 SetValue(const bool value, XMLValueSet::ValueCountType iItemPos)
00146 {
00147   return SetValue(Convert::ToStr(value), iItemPos);
00148 };
00149 
00150 bool
00151 XMLValueSet::
00152 SetValue(const double value, ValueCountType iItemPos)
00153 {
00154   return SetValue(Convert::ToStr(value), iItemPos);
00155 };
00156   
00157 bool
00158 XMLValueSet::
00159 SetValue(const float value, ValueCountType iItemPos)
00160 {
00161   return SetValue(Convert::ToStr(value), iItemPos);
00162 };
00163 
00164 bool
00165 XMLValueSet::
00166 SetValue(const int value, ValueCountType iItemPos)
00167 {
00168   return SetValue(Convert::ToStr(value), iItemPos);
00169 };
00170 
00171 bool
00172 XMLValueSet::
00173 SetValue(const unsigned int value, ValueCountType iItemPos)
00174 {
00175   return SetValue(Convert::ToStr(value), iItemPos);
00176 };
00177 
00178 bool
00179 XMLValueSet::
00180 SetValue(const long value, ValueCountType iItemPos)
00181 {
00182   return SetValue(Convert::ToStr(value), iItemPos);
00183 };
00184 
00185 bool
00186 XMLValueSet::
00187 SetValue(const unsigned long value, ValueCountType iItemPos)
00188 {
00189   return SetValue(Convert::ToStr(value), iItemPos);
00190 };
00191 
00192 bool
00193 XMLValueSet::
00194 SetValue(const std::string& value, ValueCountType iItemPos)
00195 {
00196   if (iItemPos>=m_Values.size()) return false;
00197 
00198   m_Values[iItemPos] = value;
00199   return true;
00200 };
00201 
00202 XMLValueSet&
00203 XMLValueSet::
00204 operator = (const XMLValueSet& valueSet)
00205 {
00206   if (this == &valueSet) return *this;
00207 
00208   m_Values.assign(valueSet.m_Values.begin(),valueSet.m_Values.end());
00209 
00210   return *this;
00211 };
00212 
00213 XMLValueSet::
00214 XMLValueSet(const ValueCountType iValueCount, const std::string& sNewValue) : XMLStreamObject("XMLValueSet")
00215 {
00216   Reset(iValueCount,sNewValue);
00217 };
00218 
00219 XMLValueSet::
00220 XMLValueSet() : XMLStreamObject("XMLValueSet")
00221 {
00222   Reset(0,"");
00223 };
00224 
00225 XMLValueSet::
00226 XMLValueSet( const XMLValueSet& valueSet) : XMLStreamObject(valueSet.GetXMLTag())
00227 {
00228   *this = valueSet;
00229 };
00230 
00231 XMLValueSet::
00232 ~XMLValueSet()
00233 {
00234 };
00235 
00236 void
00237 XMLValueSet::
00238 Reset()
00239 {
00240   XMLStreamObject::Reset();
00241   m_Values.clear();
00242 };
00243 
00244 
00245 void
00246 XMLValueSet::
00247 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00248 {
00249   if (rsXMLSubTag == cXML_ParameterValue)
00250   {
00251     m_Values.push_back(rsXMLSubData);
00252   }
00253   else if (rsXMLSubTag!=cXML_Text) throwExceptionMacro("Unknown xml tag, unable to load value. Incorrect Tag: "<< rsXMLSubTag);
00254 };
00255 
00256 std::string
00257 XMLValueSet::SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00258 {
00259   std::string sData;
00260 
00261   for(ValuesType::const_iterator pos = m_Values.begin(); pos != m_Values.end(); pos++)
00262   {
00263     AddSubElement(sData,cXML_ParameterValue,*pos,iDepth);
00264   }
00265   return sData;
00266 };
00267 
00268 }//end of namespace FREE

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