#include <atomic_fibonacci.hpp>
Public Member Functions | |
AtomicFibonacci (const int &last_number, const int ¤t_number, const int &max_number=256, const std::string &name="") | |
virtual int | next () |
virtual int | nextAndLog (const std::string &log_prefix="") |
virtual int | nextNext () |
virtual void | setMax (const int &value) |
virtual | ~AtomicFibonacci () |
Protected Member Functions | |
AtomicFibonacci () | |
Protected Attributes | |
std::mutex | mutex_ |
Mutex for locking. | |
Private Member Functions | |
int | next_ () |
Private Attributes | |
int | current_number_ |
Current Fibonacci number. | |
int | last_number_ |
Last Fibonacci number. | |
std::string | log_prefix_ |
Log prefix. | |
std::atomic< int > | max_number_ |
Max Fibonacci number before reseting the sequence. |
Class which returns the next (or next next) Fibonacci number thread safe
Definition at line 15 of file atomic_fibonacci.hpp.
ros1_cpptemplate::AtomicFibonacci::AtomicFibonacci | ( | const int & | last_number, |
const int & | current_number, | ||
const int & | max_number = 256 , |
||
const std::string & | name = "" |
||
) |
Constructor If max_number
is reached the sqeuence is reset to (0, 1) making last_number_
0 and current_number_
1
last_number | Initial last Fibonacci number |
current_number | Initial current Fibonacci number |
max_number | max_number after the sequence gets reset to (0, 1) |
name | Name used for logging prefix |
Definition at line 11 of file atomic_fibonacci.cpp.
ros1_cpptemplate::AtomicFibonacci::~AtomicFibonacci | ( | ) | [virtual] |
Deconstructor
Definition at line 31 of file atomic_fibonacci.cpp.
ros1_cpptemplate::AtomicFibonacci::AtomicFibonacci | ( | ) | [inline, protected] |
Protected default construtor for easy mocking
Definition at line 66 of file atomic_fibonacci.hpp.
int ros1_cpptemplate::AtomicFibonacci::next | ( | ) | [virtual] |
Get the next Fibonacci number
Definition at line 43 of file atomic_fibonacci.cpp.
int ros1_cpptemplate::AtomicFibonacci::next_ | ( | ) | [private] |
Get the next Fibonacci number without locking
Definition at line 56 of file atomic_fibonacci.cpp.
int ros1_cpptemplate::AtomicFibonacci::nextAndLog | ( | const std::string & | log_prefix = "" | ) | [virtual] |
Get the next Fibonacci number and log it
Definition at line 35 of file atomic_fibonacci.cpp.
int ros1_cpptemplate::AtomicFibonacci::nextNext | ( | ) | [virtual] |
Get the Fibonacci number after the next Fibonacci number This advances the sequence of the internal state by two steps (bascially it calls next() twice)
Definition at line 49 of file atomic_fibonacci.cpp.
void ros1_cpptemplate::AtomicFibonacci::setMax | ( | const int & | value | ) | [virtual] |
Set the max Fibonacci number before reset to (0, 1)
value | New value |
Definition at line 73 of file atomic_fibonacci.cpp.
int ros1_cpptemplate::AtomicFibonacci::current_number_ [private] |
Current Fibonacci number.
Definition at line 84 of file atomic_fibonacci.hpp.
int ros1_cpptemplate::AtomicFibonacci::last_number_ [private] |
Last Fibonacci number.
Definition at line 81 of file atomic_fibonacci.hpp.
std::string ros1_cpptemplate::AtomicFibonacci::log_prefix_ [private] |
Log prefix.
Definition at line 90 of file atomic_fibonacci.hpp.
std::atomic<int> ros1_cpptemplate::AtomicFibonacci::max_number_ [private] |
Max Fibonacci number before reseting the sequence.
Definition at line 87 of file atomic_fibonacci.hpp.
std::mutex ros1_cpptemplate::AtomicFibonacci::mutex_ [mutable, protected] |
Mutex for locking.
Definition at line 71 of file atomic_fibonacci.hpp.