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::ClassExample Class Reference

An class example. More...

#include <ClassExample.h>

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

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

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~ClassExample()

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

Destructor.

◆ ClassExample()

Elements::Examples::ClassExample::ClassExample ( 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 191 of file ClassExample.h.

Member Function Documentation

◆ divideNumbers()

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

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

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

Referenced by Elements::Examples::Program::mainMethod().

◆ factoryMethod()

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

Example factory method.

Parameters
source_idThe source identifier
raRight Ascension coordinate
Examples
ElementsExamples/src/program/Program.cpp, and ElementsExamples/src/program/SimpleProgram.cpp.

Definition at line 63 of file ClassExample.cpp.

Referenced by Elements::Examples::Program::mainMethod().

◆ fundamentalTypeMethod()

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.

Parameters
input_variableThe input_variable double value
Returns
The output of the method

Definition at line 40 of file ClassExample.cpp.

Referenced by Elements::Examples::Program::mainMethod().

◆ getRa()

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

Getter to access private m_ra

Definition at line 174 of file ClassExample.h.

◆ getSourceId()

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

Getter to access private sourceId

Definition at line 166 of file ClassExample.h.

◆ getStaticString()

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

Definition at line 78 of file ClassExample.h.

◆ passingObjectInGeneral()

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.

Parameters
input_objecta 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().

Here is the call graph for this function:

◆ passingUniquePointer()

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.

Parameters
vector_unique_ptrUnique pointer to a vector object

Definition at line 55 of file ClassExample.cpp.

References ELEMENTS_UNUSED.

Referenced by Elements::Examples::Program::mainMethod().

Member Data Documentation

◆ m_ra

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

Source right ascension.

Definition at line 200 of file ClassExample.h.

◆ m_source_id

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

Source ID as an example of a 64 bits integer.

Definition at line 197 of file ClassExample.h.

◆ s_static_string

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

An example of a static string.

Definition at line 194 of file ClassExample.h.


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