Main Page · Modules · All Classes · Class Hierarchy
MAValueGenerators.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MACoreTypes.hpp"
25 #include "MASignal.hpp"
26 
27 #include <MCDefs.hpp>
28 
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/shared_ptr.hpp>
31 
32 #include <vector>
33 
34 class MADevice;
35 class MAGeneratorBase;
37 class MCTimer;
38 
44 namespace MA
45 {
47 typedef std::vector<MAGeneratorBase*> GeneratorList;
48 }
49 
54 {
55 public:
57  typedef enum
58  {
59  FunctionTypeMin = 0,
60  Linear = FunctionTypeMin,
63  FunctionTypeMax = DeceleratingSines
64  } FunctionType;
65 
66 protected:
67 
78  MAGeneratorBase(float min = MCFloatInfinity(), float max = MCFloatInfinity());
79 
80 public:
81  virtual ~MAGeneratorBase();
82 
90  static FunctionType GetRandomFunction();
91 
99  bool IsAbsolute() const;
100 
108  int GetStartTime() const;
109 
117  int GetElapsedTime() const;
118 
126  virtual int GetDuration() const;
127 
137  virtual void ScaleDuration(float scale);
138 
146  float GetMinValue() const;
147 
155  virtual void SetMinValue(float min_value);
156 
164  float GetMaxValue() const;
165 
173  virtual void SetMaxValue(float max_value);
174 
182  void SetTransferFunction(FunctionType function);
183 
191  bool IsStarted() const;
192 
200  virtual void Start();
201 
212  virtual void Start(float value);
213 
224  virtual void StartFromTime(int start_time);
225 
233  bool IsExpired() const;
234 
242  virtual float GetCurrentValue() = 0;
243 
251  virtual int GetOverTime() const = 0;
252 
253 protected:
254 
264  float GetTransformedValue(float value) const;
265 
276  bool CheckValueRange(float value, bool verbose = true);
277 
278 private:
280  float MinValue;
282  float MaxValue;
283 protected:
285  int Duration;
287  boost::scoped_ptr<MCTimer> Timer;
289  FunctionType Function;
290 };
291 
292 
297 {
298 public:
299  // This declaration is needed to have overloaded member functions with different
300  // parameter signature visible.
302 
310  explicit MADelayGenerator(int duration);
311 
312  virtual void SetMinValue(float min_value) override;
313  virtual void SetMaxValue(float max_value) override;
314  virtual void Start() override;
315  virtual void Start(float value) override;
316  virtual void StartFromTime(int start_time) override;
317  virtual float GetCurrentValue() override;
318  virtual int GetOverTime() const override;
319 };
320 
325 {
326 public:
327  // This declaration is needed to have overloaded member functions with different
328  // parameter signature visible.
330 
340  MASimpleGenerator(float min, float max, int duration);
341 
352  MASimpleGenerator(float max, int duration);
353 
354  virtual float GetCurrentValue() override;
355  virtual int GetOverTime() const override;
356 };
357 
364 {
365 public:
366  // This declaration is needed to have overloaded member functions with different
367  // parameter signature visible.
369 
384  MAPeriodicGenerator(float min, float max, int dur1, int dur2, int dur3, int dur4,
385  int dur5, bool loop = false);
386 
402  MAPeriodicGenerator(float max, int dur1, int dur2, int dur3, int dur4, int dur5,
403  bool loop = false);
404 
405  virtual void Start(float value) override;
406  virtual void ScaleDuration(float scale) override;
407  virtual float GetCurrentValue() override;
408  virtual int GetOverTime() const override;
409 
410 protected:
422  bool Loop;
423 };
424 
429 {
430 public:
432  typedef MASignal<MAGeneratorContainer&> ExpiredSignalType;
433 
443  explicit MAGeneratorContainer(MAGeneratorBase& generator);
444 
453 
459  static void DumpAllContainers();
460 
468  static void SetVerbose(bool new_state);
469 
477  void SetOwnerDevice(MADevice& owner);
478 
487  void BlockExpiredSignal();
488 
497  void UnblockExpiredSignal();
498 
506  bool IsExpiredSignalBlocked() const;
507 
515  void SetTransitionName(const std::string& name);
516 
524  std::string GetTransitionName() const;
525 
537  bool IsAbsolute() const;
538 
547  int GetDuration() const;
548 
556  void ScaleDuration(float scale);
557 
565  bool IsFinite() const;
566 
574  bool IsPermanent() const;
575 
583  bool IsStarted() const;
584 
592  bool IsExpired();
593 
601  bool HasOneGenerator() const;
602 
610  bool HasRealGenerator() const;
611 
624  void AddGenerator(MAGeneratorBase& generator, bool in_front = false);
625 
635  void ScaleGenerators(float min, float max, float new_max);
636 
646  void Start(float device_value);
647 
655  void CalculateCurrentValue(float device_value);
656 
666  float GetCurrentValue();
667 
676  float GetStartingValue() const;
677 
687  float GetDesiredStartingValue() const;
688 
697  float GetTargetValue() const;
698 
704  void MakePermanent();
705 
711  void Dump();
712 
714  boost::shared_ptr<ExpiredSignalType> ExpiredSignal;
715 private:
717  MA::GeneratorList Generators;
725  std::string TransitionName;
730 };
731 
Delay generator class.
int Duration1
First segment duration (when it keeps the minimum value)
boost::shared_ptr< ExpiredSignalType > ExpiredSignal
Just expired signal.
int Duration3
Third segment duration (when it keeps the maximum value)
MADevice * Device
Owner device.
bool AlreadyExpired
Whenever it is expired already.
float MaxValue
Maximum value.
std::string TransitionName
Transition name.
float StartingValue
Starting value.
int Duration5
Fifth segment duration (when it keeps the minimum value)
Device class.
Definition: MADevice.hpp:57
Simple generator class.
int Duration4
Fourth segment duration (when it interpolates back to the minimum value)
bool Loop
Whether the generator is looped.
boost::scoped_ptr< MCTimer > Timer
Timer.
FunctionType Function
Transfer function.
float MinValue
Minimum value.
MASignal< MAGeneratorContainer & > ExpiredSignalType
Generator just expired signal type.
Generator container class.
float CurrentValue
Current value.
Base class for generators.
virtual void Start()
Start the generator.
Simple timer class with microsecond precision.
Definition: MCTimer.hpp:59
float MCFloatInfinity()
Get float infinity.
Definition: MCDefs.cpp:110
Periodic generator class (waveform _/‾\_)
int ExpiredSignalBlockRefCount
Whenever the signal of the "just expiration" is blocked.
int Duration
Duration.
int Duration2
Second segment duration (when it interpolates to the maximum value)
MA::GeneratorList Generators
Value generators.