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

Functor.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file Functor.h
00003 *  \brief Implementation of a Functor class for vectors.
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.2 $
00006 *  \date    $Date: 2005/06/10 12:53:29 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*
00009 */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __SSF_FUNCTOR_H__
00013 #define __SSF_FUNCTOR_H__
00014 
00015 #include <Matrix.h>
00016 #include <utils/Time.h>
00017 #include <orbit/OrbitState.h>
00018 #include <attitude/AttitudeState.h>
00019 
00020 namespace O_SESSAME {
00021 
00022 /*! \brief Abstract class to hold the pointer to an force calculating functor.
00023 * \ingroup IntegrationLibrary
00024 * \ingroup EnvironmentToolkit
00025 *
00026 * A @em Function @em Object, or @em Functor (the two terms are synonymous) is simply 
00027 any object that can be called as if it is a function. It is used to define a call-back function that evaluates 
00028 any algorithm that takes the defined inputs and returns a vector of values. Examples of usage include 
00029 evaluating a disturbance force or torque given the current time, orbit state, and attitude state. The returned 
00030 vector will then be the 3 forces (or torques). 
00031 
00032 \par Examples:
00033 The simplest functor is a placeholder that can be set to just return a vector of zeros:
00034 \code
00035 Vector NullFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState, const AttitudeState& _pAttitudeState)
00036 {
00037     return Vector(3);
00038 }
00039 \endcode
00040 This isn't very useful, but may be necessary for filling out a parameter list such as for \sa Integrator that 
00041 requests a Functor call-back function. The Functor object is created as follows:
00042 \code 
00043 SpecificFunctor AttitudeForcesFunctor(&NullFunctor);
00044 \endcode
00045 SpecificFunctor is used since it is only a function that was used, and not a member function of a class. For that 
00046 case, an ObjectFunctor is required which stores the type (or class) of the function as well as the pointer to 
00047 the function itself. 
00048 
00049 \par
00050 An ObjectFunctor may be assigned from an Environment object (@em pEarthEnv) where the function is @em GetForces:
00051 \code
00052 ObjectFunctor<Environment> OrbitForcesFunctor(pEarthEnv, &Environment::GetForces);
00053 \endcode
00054 To review, we are creating an ObjectFunctor that will hold a call-back function to the Environment class (hence 
00055 the template argument <Environment>). The function, @em OrbitForcesFunctor, needs a pointer to the instance 
00056 of the class we are using (@em pEarthEnv), and the reference to the function (@em &Environment::GetForces). The 
00057 @em \& is required to specify that it is a @em reference, and the @em Environment:: defines the scope of the 
00058 function @em GetForces. It is also important to note that the @em GetForces function conforms to the ObjectFunctor 
00059 interface. (\sa Environment::GetForces).
00060 
00061 * \todo make Functors for variety of function types 
00062 */
00063 class Functor
00064 {
00065 public:
00066 
00067       // two possible functions to call member function. virtual cause derived
00068       // classes will use a pointer to an object and a pointer to a member function
00069       // to make the function call
00070       virtual Vector Call(const ssfTime&, const OrbitState&, const AttitudeState&) const =0;        // call using function
00071 };
00072 
00073 /*! \brief derived template class
00074 * \ingroup IntegrationLibrary
00075 * \ingroup EnvironmentToolkit
00076 *
00077 */
00078 class SpecificFunctor : public Functor
00079 {
00080 private:
00081       Vector (*fpt)(const ssfTime&, const OrbitState&, const AttitudeState&);           // pointer to member function
00082 
00083 public:
00084 
00085       // constructor - takes pointer to a Function
00086       SpecificFunctor(Vector(*_fpt)(const ssfTime&, const OrbitState&, const AttitudeState&)):fpt(_fpt) {};
00087 
00088       // override function "Call"
00089       virtual Vector Call(const ssfTime &_ssfTime, const OrbitState &_orbState, const AttitudeState &_attState) const { return (*fpt)(_ssfTime, _orbState, _attState);};             // execute member function
00090 };
00091 
00092 /*! \brief derived template class
00093 * \ingroup IntegrationLibrary
00094 * \ingroup EnvironmentToolkit
00095 *
00096 */
00097 template <class TClass> class ObjectFunctor : public Functor
00098 {
00099 private:
00100       TClass* pt2Object;                        /*!< pointer to object */
00101       Vector (TClass::*fpt)(const ssfTime&, const OrbitState&, const AttitudeState&);           /*!< pointer to member function */
00102 
00103 public:
00104 
00105       /*! constructor - takes pointer to an object and pointer to a member and stores
00106       * them in two private variables */
00107       ObjectFunctor(TClass* _pt2Object, Vector(TClass::*_fpt)(const ssfTime&, const OrbitState&, const AttitudeState&)): pt2Object(_pt2Object),  fpt(_fpt) {};
00108       ObjectFunctor(): pt2Object(NULL),  fpt(NULL) {};
00109       void Set(TClass* _pt2Object, Vector(TClass::*_fpt)(const ssfTime&, const OrbitState&, const AttitudeState&)){ pt2Object = _pt2Object;  fpt=_fpt; };
00110       
00111       // override function "Call"
00112       virtual Vector Call(const ssfTime &_ssfTime, const OrbitState &_orbState, const AttitudeState &_attState) const { return (*pt2Object.*fpt)(_ssfTime, _orbState, _attState);};             // execute member function
00113 };
00114 } // close namespace O_SESSAME
00115 
00116 #endif /* __SSF_FUNCTOR_H__ */
00117 
00118 // Do not change the comments below - they will be added automatically by CVS
00119 /*****************************************************************************
00120 *       $Log: Functor.h,v $
00121 *       Revision 1.2  2005/06/10 12:53:29  jayhawk_hokie
00122 *       Changed header file format to make it easier to link to the spacecraft code by only having to specify dsacss/dep/spacecraft/src (ex. "file.h" changed to <dir/file.h> where dir is a folder in src).
00123 *       
00124 *       Revision 1.1.1.1  2005/04/26 17:41:00  cakinli
00125 *       Adding OpenSESSAME to DSACSS distrib to capture fixed version.
00126 *       
00127 *       Revision 1.10  2003/10/18 21:37:28  rsharo
00128 *       Removed "../utils" from all qmake project paths. Prepended "utils
00129 *       /" to all #include directives for utils. Removed ".h" extensions from STL header
00130 *       s and referenced STL components from "std::" namespace.  Overall, changed to be
00131 *       more portable.
00132 *       
00133 *       Revision 1.9  2003/05/21 19:52:22  nilspace
00134 *       Updated comments.
00135 *       
00136 *       Revision 1.8  2003/05/20 17:44:20  nilspace
00137 *       Updated comments.
00138 *       
00139 *       Revision 1.7  2003/05/13 18:58:04  nilspace
00140 *       Cleaned up comments.
00141 *       
00142 *       Revision 1.6  2003/04/27 22:04:34  nilspace
00143 *       Created the namespace O_SESSAME.
00144 *       
00145 *       Revision 1.5  2003/04/25 18:55:45  nilspace
00146 *       Implemented ObjectFunctor body (empty), and moved constructor assignments to inline with constructor.
00147 *       
00148 *       Revision 1.4  2003/04/25 13:45:53  nilspace
00149 *       const'd Get() functions.
00150 *       
00151 *       Revision 1.3  2003/04/24 20:00:10  nilspace
00152 *       Made all Call() functions const to prevent warnings.
00153 *       
00154 *       Revision 1.2  2003/04/24 13:51:10  nilspace
00155 *       Added a Set function for setting the object & function afterwards, or by using the default constructor.
00156 *       
00157 *       Revision 1.1  2003/04/08 22:33:06  nilspace
00158 *       Initial Submission
00159 *       
00160 *
00161 ******************************************************************************/

Generated on Wed Sep 5 12:54:21 2007 for DSACSS Operational Code by  doxygen 1.3.9.1