Elements
6.2
A C++ base framework for the Euclid Software.
|
An class example. More...
#include <ClassExample.h>
Public Member Functions | |
virtual | ~ClassExample ()=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 ClassExample | factoryMethod (const std::int64_t source_id, const double ra) |
Example factory method. More... | |
static const std::string & | getStaticString () |
Private Member Functions | |
ClassExample (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 const std::string | s_static_string = "This is a static field example" |
An example of a static string. More... | |
An class example.
Our naming convention and coding standard are used in this example
Our naming convention and coding standard are used in this example
Definition at line 59 of file ClassExample.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 191 of file ClassExample.h.
double Elements::Examples::ClassExample::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 ClassExample.cpp.
References Elements::Kernel::Units::e, and Elements::Kernel::Units::second.
Referenced by Elements::Examples::Program::mainMethod().
|
static |
Example factory method.
source_id | The source identifier |
ra | Right Ascension coordinate |
Definition at line 63 of file ClassExample.cpp.
Referenced by Elements::Examples::Program::mainMethod().
double Elements::Examples::ClassExample::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 ClassExample.cpp.
Referenced by Elements::Examples::Program::mainMethod().
|
inline |
Getter to access private m_ra
Definition at line 174 of file ClassExample.h.
|
inline |
Getter to access private sourceId
Definition at line 166 of file ClassExample.h.
|
inlinestatic |
Definition at line 78 of file ClassExample.h.
void Elements::Examples::ClassExample::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 ClassExample.cpp.
References ELEMENTS_UNUSED, and std::vector< T >::size().
Referenced by Elements::Examples::Program::mainMethod().
void Elements::Examples::ClassExample::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 ClassExample.cpp.
References ELEMENTS_UNUSED.
Referenced by Elements::Examples::Program::mainMethod().
|
private |
Source right ascension.
Definition at line 200 of file ClassExample.h.
|
private |
Source ID as an example of a 64 bits integer.
Definition at line 197 of file ClassExample.h.
|
staticprivate |
An example of a static string.
Definition at line 194 of file ClassExample.h.