Elements  6.2
A C++ base framework for the Euclid Software.
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Elements::Examples::ClassExample2 Class Reference

#include <ClassExample2.h>

Collaboration diagram for Elements::Examples::ClassExample2:
Collaboration graph
[legend]

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::stringgetStaticString ()
 

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...
 

Detailed Description

Definition at line 49 of file ClassExample2.h.

Constructor & Destructor Documentation

◆ ~ClassExample2()

virtual Elements::Examples::ClassExample2::~ClassExample2 ( )
virtualdefault

Destructor.

◆ ClassExample2()

Elements::Examples::ClassExample2::ClassExample2 ( const std::int64_t  source_id,
const double  ra 
)
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.

Member Function Documentation

◆ divideNumbers()

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

Parameters
firstThe first double value
secondThe second double value
Returns
The division of the two double values
Exceptions
EuclidException,ifthe second number is (close to) zero

Definition at line 47 of file ClassExample2.cpp.

References Elements::Kernel::Units::e, and Elements::Kernel::Units::second.

◆ factoryMethod()

ClassExample2 Elements::Examples::ClassExample2::factoryMethod ( const std::int64_t  source_id,
const double  ra 
)
static

Example factory method.

Parameters
source_idThe source identifier
raRight Ascension coordinate

Definition at line 63 of file ClassExample2.cpp.

◆ fundamentalTypeMethod()

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.

Parameters
input_variableThe input_variable double value
Returns
The output of the method

Definition at line 40 of file ClassExample2.cpp.

◆ getRa()

double Elements::Examples::ClassExample2::getRa ( ) const
inline

Getter to access private m_ra

Definition at line 164 of file ClassExample2.h.

◆ getSourceId()

std::int64_t Elements::Examples::ClassExample2::getSourceId ( ) const
inline

Getter to access private sourceId

Definition at line 156 of file ClassExample2.h.

◆ getStaticString()

static const std::string& Elements::Examples::ClassExample2::getStaticString ( )
inlinestatic

Definition at line 68 of file ClassExample2.h.

◆ passingObjectInGeneral()

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.

Parameters
input_objecta vector of double

Definition at line 59 of file ClassExample2.cpp.

References ELEMENTS_UNUSED, and std::vector< T >::size().

Here is the call graph for this function:

◆ passingUniquePointer()

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.

Parameters
vector_unique_ptrUnique pointer to a vector object

Definition at line 55 of file ClassExample2.cpp.

References ELEMENTS_UNUSED.

Member Data Documentation

◆ m_ra

double Elements::Examples::ClassExample2::m_ra {0.0}
private

Source right ascension.

Definition at line 190 of file ClassExample2.h.

◆ m_source_id

std::int64_t Elements::Examples::ClassExample2::m_source_id {0}
private

Source ID as an example of a 64 bits integer.

Definition at line 187 of file ClassExample2.h.

◆ s_static_string

std::string Elements::Examples::ClassExample2::s_static_string = "This is a static field example"
staticprivate

An example of a static string.

Definition at line 184 of file ClassExample2.h.


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