Elements
6.2
A C++ base framework for the Euclid Software.
|
#include <ClassExample2.h>
Public Member Functions | |
virtual | ~ClassExample2 ()=default |
Destructor. More... | |
double | fundamentalTypeMethod (const double input_variable) const |
Simple method example. More... | |
double | divideNumbers (const double first, const double second) const |
Divide two double variables. More... | |
void | passingUniquePointer (std::unique_ptr< std::vector< double >> vector_unique_ptr) const |
Example method with a unique pointer argument. More... | |
void | passingObjectInGeneral (const std::vector< double > &input_object) const |
Example method taking an object in input. More... | |
std::int64_t | getSourceId () const |
double | getRa () const |
Static Public Member Functions | |
static ClassExample2 | factoryMethod (const std::int64_t source_id, const double ra) |
Example factory method. More... | |
static const std::string & | getStaticString () |
Private Member Functions | |
ClassExample2 (const std::int64_t source_id, const double ra) | |
Constructor. More... | |
Private Attributes | |
std::int64_t | m_source_id {0} |
Source ID as an example of a 64 bits integer. More... | |
double | m_ra {0.0} |
Source right ascension. More... | |
Static Private Attributes | |
static std::string | s_static_string = "This is a static field example" |
An example of a static string. More... | |
Definition at line 49 of file ClassExample2.h.
|
virtualdefault |
Destructor.
|
inlineprivate |
Constructor.
We propose a public factory and private constructor. This is not really useful here, but could be interesting in a more elaborated call especially if the factory is returning an abstract class (interface) and that different implementation can be chosen via the factory.
Definition at line 181 of file ClassExample2.h.
double Elements::Examples::ClassExample2::divideNumbers | ( | const double | first, |
const double | second | ||
) | const |
Divide two double variables.
This is a simple class to illustrate the case of a method which can throw an exception
first | The first double value |
second | The second double value |
EuclidException,if | the second number is (close to) zero |
Definition at line 47 of file ClassExample2.cpp.
References Elements::Kernel::Units::e, and Elements::Kernel::Units::second.
|
static |
Example factory method.
source_id | The source identifier |
ra | Right Ascension coordinate |
Definition at line 63 of file ClassExample2.cpp.
double Elements::Examples::ClassExample2::fundamentalTypeMethod | ( | const double | input_variable | ) | const |
Simple method example.
This is a simple example method, taking a double variable in input and returning a double value. The displayed way to pass and return fundamental type variables is recommended as the cost of copying them is small.
The const keyword send a meaningful message to the user. The "input_variable" will not be modified and can safely be reused after the call to "fundamentalTypesMethod".
The syntax
output = methodName(input)
is strongly recommended. With C++11, the std::tuple can be used to return a set of values or objects.
input_variable | The input_variable double value |
Definition at line 40 of file ClassExample2.cpp.
|
inline |
Getter to access private m_ra
Definition at line 164 of file ClassExample2.h.
|
inline |
Getter to access private sourceId
Definition at line 156 of file ClassExample2.h.
|
inlinestatic |
Definition at line 68 of file ClassExample2.h.
void Elements::Examples::ClassExample2::passingObjectInGeneral | ( | const std::vector< double > & | input_object | ) | const |
Example method taking an object in input.
General method example taking any object in input. Because a const reference is used, the method can accept both a rvalue or a rvalue as an argument.
The vector is used here as an example object.
input_object | a vector of double |
Definition at line 59 of file ClassExample2.cpp.
References ELEMENTS_UNUSED, and std::vector< T >::size().
void Elements::Examples::ClassExample2::passingUniquePointer | ( | std::unique_ptr< std::vector< double >> | vector_unique_ptr | ) | const |
Example method with a unique pointer argument.
This illustrates the case where the ownership of the pointed object is transfered to the method. Users will have to move the object (syntax: move(p)) and cannot reused it afterwards in the calling code.
The vector is used here as an example object.
vector_unique_ptr | Unique pointer to a vector object |
Definition at line 55 of file ClassExample2.cpp.
References ELEMENTS_UNUSED.
|
private |
Source right ascension.
Definition at line 190 of file ClassExample2.h.
|
private |
Source ID as an example of a 64 bits integer.
Definition at line 187 of file ClassExample2.h.
|
staticprivate |
An example of a static string.
Definition at line 184 of file ClassExample2.h.