Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ConstantFunction.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_CONSTANT_FUNCTION_H
4 #define GRAIL_CONSTANT_FUNCTION_H
5 
6 #include "Curve.hh"
7 
8 namespace grail
9 {
10 namespace evaluator
11 {
12  template <typename ContextType>
17  class ConstantFunction final : public Curve<ContextType>
18  {
19  public:
25  ConstantFunction(std::shared_ptr<Evaluator<ContextType>> childEvaluator, float constant)
26  : Curve<ContextType>{childEvaluator}, constant{constant}
27  {
28  }
29 
30  virtual float Sample(float) const override final
31  {
32  return constant;
33  }
34 
39  float GetConstant() const { return constant; }
40  virtual data::EvaluatorType GetEvaluatorType() const override final { return data::EvaluatorType::CURVE_CONSTANT; }
41 
42  private:
43  float constant = 0.0f;
44  };
45 }
46 }
47 #endif // GRAIL_CONSTANT_FUNCTION_H
grail::evaluator::ConstantFunction::Sample
virtual float Sample(float) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: ConstantFunction.hh:30
grail::evaluator::ConstantFunction
The ConstantFunction class - Constant function.
Definition: ConstantFunction.hh:17
grail::evaluator::ConstantFunction::ConstantFunction
ConstantFunction(std::shared_ptr< Evaluator< ContextType >> childEvaluator, float constant)
ConstantFunction - Constructor.
Definition: ConstantFunction.hh:25
grail::evaluator::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:22
grail::evaluator::ConstantFunction::GetConstant
float GetConstant() const
GetConstant.
Definition: ConstantFunction.hh:39
grail::evaluator::Curve
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21