Elements  6.2
A C++ base framework for the Euclid Software.
ClassExample2.cpp
Go to the documentation of this file.
1 
23 
24 #include <cmath> // for std::abs
25 #include <cstdint> // for std::int64_t
26 #include <memory> // for unique_ptr
27 #include <string> // for string
28 #include <vector> // for vector
29 
31 #include "ElementsKernel/Unused.h"
32 
33 using std::vector;
34 
35 namespace Elements {
36 namespace Examples {
37 
38 std::string ClassExample2::s_static_string = "This is a static field example";
39 
40 double ClassExample2::fundamentalTypeMethod(const double input_variable) const {
41  return input_variable;
42 }
43 
44 /*
45  * This is a silly example just to have a method throwing an exception
46  */
47 double ClassExample2::divideNumbers(const double first, const double second) const {
48  double tolerance = 1e-12;
49  if (std::abs(second) < tolerance) {
50  throw Elements::Exception() << "Dividing by " << second << " exception in ClassExample2::divideNumbers(...)";
51  }
52  return first / second;
53 }
54 
56  ELEMENTS_UNUSED auto vect_size = vector_unique_ptr->size();
57 }
58 
59 void ClassExample2::passingObjectInGeneral(const vector<double>& input_object) const {
60  ELEMENTS_UNUSED auto object_size = input_object.size();
61 }
62 
63 ClassExample2 ClassExample2::factoryMethod(const std::int64_t source_id, const double ra) {
64  return ClassExample2{source_id, ra};
65 }
66 
67 } // namespace Examples
68 } // namespace Elements
std::string
STL class.
Elements::Examples::ClassExample2::s_static_string
static std::string s_static_string
An example of a static string.
Definition: ClassExample2.h:184
std::vector
STL class.
std::vector::size
T size(T... args)
Elements::Examples::ClassExample2::passingUniquePointer
void passingUniquePointer(std::unique_ptr< std::vector< double >> vector_unique_ptr) const
Example method with a unique pointer argument.
Definition: ClassExample2.cpp:55
Elements::Kernel::Units::second
constexpr double second
Definition: SystemOfUnits.h:107
ClassExample2.h
Elements::Examples::ClassExample2::divideNumbers
double divideNumbers(const double first, const double second) const
Divide two double variables.
Definition: ClassExample2.cpp:47
Elements::Examples::ClassExample2::fundamentalTypeMethod
double fundamentalTypeMethod(const double input_variable) const
Simple method example.
Definition: ClassExample2.cpp:40
Elements::Examples::ClassExample2::passingObjectInGeneral
void passingObjectInGeneral(const std::vector< double > &input_object) const
Example method taking an object in input.
Definition: ClassExample2.cpp:59
Exception.h
defines the base Elements exception class
Elements::Exception
Elements base exception class.
Definition: Exception.h:47
std::int64_t
Elements::Examples::ClassExample2
Definition: ClassExample2.h:49
Elements::Examples::ClassExample2::factoryMethod
static ClassExample2 factoryMethod(const std::int64_t source_id, const double ra)
Example factory method.
Definition: ClassExample2.cpp:63
Unused.h
Macro to silence unused variables warnings from the compiler.
std::unique_ptr
STL class.
Elements::Kernel::Units::e
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:51
ELEMENTS_UNUSED
#define ELEMENTS_UNUSED
Definition: Unused.h:39
Elements
Definition: callBackExample.h:35