Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ros1_cpptemplate::AtomicFibonacci Class Reference

#include <atomic_fibonacci.hpp>

List of all members.

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.

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.

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.

Deconstructor

Definition at line 31 of file atomic_fibonacci.cpp.

Protected default construtor for easy mocking

Definition at line 66 of file atomic_fibonacci.hpp.


Member Function Documentation

Get the next Fibonacci number

Returns:
Next Fibonacci number

Definition at line 43 of file atomic_fibonacci.cpp.

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.

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

Current Fibonacci number.

Definition at line 84 of file atomic_fibonacci.hpp.

Last Fibonacci number.

Definition at line 81 of file atomic_fibonacci.hpp.

Log prefix.

Definition at line 90 of file atomic_fibonacci.hpp.

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.


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


ros1_cpptemplate
Author(s): Alexander Reimann
autogenerated on Fri Sep 1 2017 02:23:31