Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

loopcontrol_impl.h

Go to the documentation of this file.
00001 /*-*-c++-*-*****************************************************************
00002                           loopcontrol_impl.h  -  description
00003                              -------------------
00004     begin                : Fri Feb 20 2004
00005     copyright            : (C) 2004 by Christian Stimming
00006     email                : stimming@tuhh.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00038 #ifndef _LOOPCONTROL_IMPL_H
00039 #define _LOOPCONTROL_IMPL_H
00040 
00041 #include <simthetic/loopcontrol.h>
00042 #include <simthetic/exceptions.h>
00043 
00044 namespace simth
00045 {
00046 template<class T>
00047 LinearLoopControl<T>::~LinearLoopControl() {}
00048 
00049 template<class T>
00050 LinearLoopControl<T>::LinearLoopControl(const std::string& namePar, T start, T end, T increment)
00051     : name_(namePar), start_(start), end_(end), incr(increment), value_(start)
00052 {
00053   if(incr == T(0)) {
00054     throw std::runtime_error("Increment value of LinerLoopControl "+name()+" is zero!");
00055   }
00056   if((value_ < end_) && (incr < 0)) {
00057     throw std::runtime_error("LinearLoopControl "+name()+" covers improper range");
00058   }
00059   if((value_ > end_) && (incr > 0)) {
00060     throw std::runtime_error("LinearLoopControl "+name()+" covers improper range");
00061   }
00062 }
00063 
00064 template<class T>
00065 inline std::string LinearLoopControl<T>::currentIteration() const
00066 {
00067   std::ostringstream os;
00068   os<<value_;
00069   return os.str();
00070 }
00071 
00072 template<class T>
00073 inline std::string LinearLoopControl<T>::lastIteration() const
00074 {
00075   std::ostringstream os;
00076   os<<end_;
00077   return os.str();
00078 }
00079 
00080 
00081 template<class T>
00082 inline bool LinearLoopControl<T>::nextIteration()
00083 {
00084   value_ += incr;
00085   if(!reachedEnd()) {
00086     for(unsigned int i=0;i<interfaces.size();++i) {
00087       interfaces[i]->callFunc(value_);
00088     }
00089     return true;
00090   }
00091   else {
00092     return false;
00093   }
00094 }
00095 
00096 
00097 
00098 template<class T>
00099 inline void LinearLoopControl<T>::connectControlInterface(ControlInterface* interface)
00100 {
00101   ControlInterfaceT<T>* interPtr = dynamic_cast<ControlInterfaceT<T> * >(interface);
00102   if(interPtr == NULL)
00103   {
00104     throw simth::type_mismatch_connection("control interface and loop_control have different types");
00105   }
00106   interPtr->callFunc(value_);
00107   interfaces.push_back(interPtr);
00108 }
00109 
00110 
00111 
00112 template<class T>
00113 inline bool LinearLoopControl<T>::reachedEnd()
00114 {
00115    // Check for direction of increment
00116    return (incr > T(0)) ?
00117       // Positive increment
00118       (value_ > end_) :
00119       // Negative increment
00120       (value_ <= end_);
00121 }
00122 
00123 template<class T>
00124 inline void LinearLoopControl<T>::reset()
00125 {
00126   value_ = start_;
00127   for(unsigned int i=0;i<interfaces.size();++i) {
00128     interfaces[i]->callFunc(value_);
00129   }
00130 }
00131 
00132 
00133 } // namespace
00134 
00135 #endif // _LOOPCONTROL_IMPL_H
00136 

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1