forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClassExample.h
More file actions
211 lines (188 loc) · 5.71 KB
/
Copy pathClassExample.h
File metadata and controls
211 lines (188 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* @file ClassExample.h
*
* @date January 9, 2015
* @author Pierre Dubath
*
* @copyright 2012-2020 Euclid Science Ground Segment
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* @addtogroup ElementsExamples ElementsExamples
* @{
*/
#ifndef ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_CLASSEXAMPLE_H_
#define ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_CLASSEXAMPLE_H_
#include <memory> // for std::unique_ptr
#include <string> // for std::string
#include <vector> // for std::vector
#include <cstdint> // for std::int64_t
#include "ElementsKernel/Export.h"
namespace Elements::Examples {
/**
* @class ClassExample
* @ingroup ElementsExamples
* @brief
* An class example
* @details
* Our naming convention and coding standard are used in this example
* @startuml
* class ClassExample {
* +ClassExample {static} factoryMethod()
* +std::string& {static} getStaticString()
* +double fundamentalTypeMethod(const double, const double) const
* -double m_ra
* -const std::string {static} s_static_string
* -std::int64_t m_source_id
* }
* @enduml
*/
class ELEMENTS_API ClassExample {
public:
/**
* @brief
* Example factory method
* @details
*
* @param source_id
* The source identifier
* @param ra
* Right Ascension coordinate
*
*/
static ClassExample factoryMethod(const std::int64_t source_id, const double ra);
/**
* @brief
* Retrieves the static string.
* @details
* This method returns a reference to the static string member.
* @return
* A constant reference to the static string.
*/
static const std::string& getStaticString() {
return s_static_string;
}
/**
* @brief Destructor
*/
virtual ~ClassExample() = default;
/**
* @brief
* Simple method example
* @details
* 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.
*
* @param input_variable
* The input_variable double value
*
* @return
* The output of the method
*/
static double fundamentalTypeMethod(const double input_variable);
/**
* @brief
* Divide two double variables
* @details
* This is a simple class to illustrate the case of a method which can
* throw an exception
*
* @param first
* The first double value
* @param second
* The second double value
* @return
* The division of the two double values
* @throws
* EuclidException, if the second number is (close to) zero
*/
static double divideNumbers(const double first, const double second);
/**
* @brief
* Example method with a unique pointer argument
* @details
* 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.
*
* @param vector_unique_ptr
* Unique pointer to a vector object
*/
static void passingUniquePointer(const std::unique_ptr<std::vector<double>>& vector_unique_ptr);
/**
* @brief
* Example method taking an object in input
* @details
* 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.
*
* @param input_object
* a vector of double
*/
static void passingObjectInGeneral(const std::vector<double>& input_object);
/**
* Getter to access private sourceId
*/
std::int64_t getSourceId() const {
return m_source_id;
}
/**
* Getter to access private m_ra
*
*/
double getRa() const {
return m_ra;
}
private:
/**
* @brief Constructor
*
* @details
*
* 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.
*
*/
ClassExample(const std::int64_t source_id, const double ra) : m_source_id(source_id), m_ra(ra) {}
/// An example of a static string
static const std::string s_static_string;
/// Source ID as an example of a 64 bits integer
std::int64_t m_source_id{0};
/// Source right ascension
double m_ra{0.0};
};
} // namespace Elements::Examples
#endif // ELEMENTSEXAMPLES_ELEMENTSEXAMPLES_CLASSEXAMPLE_H_
/**@}*/