Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ros1_cpptemplate::AtomicFibonacci Class Reference

#include <atomic_fibonacci.hpp>

Public Member Functions

 AtomicFibonacci (const int &last_number, const int &current_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. More...
 

Private Member Functions

int next_ ()
 

Private Attributes

int current_number_
 Current Fibonacci number. More...
 
int last_number_
 Last Fibonacci number. More...
 
std::string log_prefix_
 Log prefix. More...
 
std::atomic< int > max_number_
 Max Fibonacci number before reseting the sequence. More...
 

Detailed Description

Class which returns the next (or next next) Fibonacci number thread safe

Definition at line 15 of file atomic_fibonacci.hpp.

Constructor & Destructor Documentation

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

Parameters
last_numberInitial last Fibonacci number
current_numberInitial current Fibonacci number
max_numbermax_number after the sequence gets reset to (0, 1)
nameName 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 ( )
inlineprotected

Protected default construtor for easy mocking

Definition at line 66 of file atomic_fibonacci.hpp.

Member Function Documentation

int ros1_cpptemplate::AtomicFibonacci::next ( )
virtual

Get the next Fibonacci number

Returns
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

Returns
Next Fibonacci number

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

Returns
Next Fibonacci number

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)

Returns
Next next Fibonacci number

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)

Parameters
valueNew value

Definition at line 73 of file atomic_fibonacci.cpp.

Member Data Documentation

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_
mutableprotected

Mutex for locking.

Definition at line 71 of file atomic_fibonacci.hpp.


The documentation for this class was generated from the following files:


ros1_cpptemplate
Author(s): Alexander Reimann
autogenerated on Sat Sep 2 2017 02:37:58