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

# Tools/Xabsl2/Xabsl2Engine/Xabsl2BasicBehavior.h

Go to the documentation of this file.

    00001 /**
    00002 * @file Xabsl2BasicBehavior.h
    00003 *
    00004 * Declaration class Xabsl2BasicBehavior
    00005 *
    00006 * @author Matthias Jüngel
    00007 * @author Martin Lötzsch
    00008 */
    00009
    00010 #ifndef __Xabsl2BasicBehavior_h_
    00011 #define __Xabsl2BasicBehavior_h_
    00012
    00013 #include "Xabsl2Tools.h"
    00014
    00015 /**
    00016 * The base class for basic behaviors that are used by the XabslEngine
    00017 *
    00018 * @author Matthias Jüngel
    00019 * @author Martin Lötzsch
    00020 *
    00021 */
    00022 class Xabsl2BasicBehavior : public Xabsl2NamedItem
    00023 {
    00024 public:
    00025   /**
    00026   * Constructor
    00027   * @param name The name of the basic behavior
    00028   * @param errorHandler A reference
    00029   */
    00030   Xabsl2BasicBehavior(const char* name, Xabsl2ErrorHandler& errorHandler)
    00031     : Xabsl2NamedItem(name), errorHandler(errorHandler),
    00032     basicBehaviorWasActiveDuringLastExecutionOfEngine(false)
    00033   {};
    00034
    00035   /**
    00036   * executes the basic behavior
    00037   */
    00038   virtual void execute() = 0;
    00039
    00040   /** sets all parameter values to 0 */
    00041   void reset()
    00042   { for (int i=0; i<parameters.getSize(); i++) parameters[i]=0; }
    00043
    00044   /** The parameters of the basic behavior */
    00045   Xabsl2Array<double&> parameters;
    00046
    00047   /** Determines if the basic behavior was active during the last execution of the engine */
    00048   bool basicBehaviorWasActiveDuringLastExecutionOfEngine;
    00049
    00050 /**
    00051 * Registeres a reference to a parameter at the parameters array.
    00052 * @param name The name of the parameter
    00053 * @param parameter The reference to a parameter of the basic behavior
    00054   */
    00055   void registerParameter(const char* name, double& parameter)
    00056   {
    00057     XABSL2_DEBUG_INIT(errorHandler.message("registering parameter \"%s\" of basic behavior \"%s\"",name,n));
    00058
    00059     if (parameters.exists(name))
    00060     {
    00061       errorHandler.error("registerParameter(): parameter \"%s\" was already registered",name);
    00062       return;
    00063     }
    00064     parameters.append(name,parameter);
    00065     parameter = 0;
    00066   };
    00067
    00068 protected:
    00069   /** Is invoked when a errors occur */
    00070   Xabsl2ErrorHandler& errorHandler;
    00071 };
    00072
    00073
    00074 #endif // __Xabsl2BasicBehavior_h_
    00075