Skip to content

Commit 4b5b7e6

Browse files
committed
change code formatting
1 parent 511fc16 commit 4b5b7e6

File tree

132 files changed

+2454
-2962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2454
-2962
lines changed

.clang-format

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ PointerAlignment: Left
1010
UseTab: Never
1111
TabWidth: 4
1212
# extra
13-
# AlignConsecutiveAssignments: true
1413
ColumnLimit: 150
15-
# AlignConsecutiveMacros : true
14+
AlignConsecutiveAssignments: Consecutive
15+
AlignConsecutiveMacros: Consecutive
16+
AlignConsecutiveBitFields: Consecutive
17+
# AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
18+
# AlignConsecutiveShortCaseStatements:
19+
# AlignEscapedNewlines: ENAS_LeftWithLastLine
20+
# AlignOperands: True
21+
# AlignTrailingComments: TCAS_Always
22+
AllowShortBlocksOnASingleLine: Always
23+
AllowShortIfStatementsOnASingleLine: WithoutElse

Intern/rayx-core/src/Beamline/Beamline.cpp

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@ Group::Group(std::string name) : m_name(std::move(name)) {}
2323
// Move constructor
2424
Group::Group(Group&& other) noexcept
2525
: m_position(std::move(other.m_position)), m_orientation(std::move(other.m_orientation)), m_children(std::move(other.m_children)) {
26-
for (auto& child : m_children) {
27-
child->m_parent = this;
28-
}
26+
for (auto& child : m_children) { child->m_parent = this; }
2927
}
3028

3129
// Move assignment operator
3230
Group& Group::operator=(Group&& other) noexcept {
3331
if (this != &other) {
34-
m_position = std::move(other.m_position);
32+
m_position = std::move(other.m_position);
3533
m_orientation = std::move(other.m_orientation);
36-
m_children = std::move(other.m_children);
34+
m_children = std::move(other.m_children);
3735

38-
for (auto& child : m_children) {
39-
child->m_parent = this;
40-
}
36+
for (auto& child : m_children) { child->m_parent = this; }
4137
}
4238
return *this;
4339
}
@@ -204,9 +200,7 @@ void Group::ctraverse(const std::function<bool(const BeamlineNode&)>& callback)
204200

205201
for (const auto& child : m_children) {
206202
if (!child) RAYX_EXIT << "m_children contains a nullptr! This should never happen.";
207-
if (callback(*child)) {
208-
return;
209-
}
203+
if (callback(*child)) { return; }
210204
if (child->isGroup()) {
211205
auto groupPtr = static_cast<Group*>(child.get());
212206
groupPtr->ctraverse(callback);
@@ -219,9 +213,7 @@ void Group::traverse(const std::function<bool(BeamlineNode&)>& callback) {
219213

220214
for (auto& child : m_children) {
221215
if (!child) RAYX_EXIT << "m_children contains a nullptr! This should never happen.";
222-
if (callback(*child)) {
223-
return;
224-
}
216+
if (callback(*child)) { return; }
225217
if (child->isGroup()) {
226218
auto groupPtr = static_cast<Group*>(child.get());
227219
groupPtr->traverse(callback);
@@ -241,7 +233,7 @@ std::unique_ptr<BeamlineNode> Group::releaseNodeFromChildren(const BeamlineNode*
241233
for (auto it = m_children.begin(); it != m_children.end(); ++it) {
242234
if (it->get() == node) {
243235
std::unique_ptr<BeamlineNode> releasedNode = std::move(*it);
244-
releasedNode->m_parent = nullptr;
236+
releasedNode->m_parent = nullptr;
245237
m_children.erase(it);
246238
return releasedNode;
247239
}
@@ -254,7 +246,7 @@ std::unique_ptr<BeamlineNode> Group::releaseNodeFromTree(const BeamlineNode* nod
254246
for (auto it = m_children.begin(); it != m_children.end(); ++it) {
255247
if (it->get() == node) {
256248
std::unique_ptr<BeamlineNode> releasedNode = std::move(*it);
257-
releasedNode->m_parent = nullptr;
249+
releasedNode->m_parent = nullptr;
258250
m_children.erase(it);
259251
return releasedNode;
260252
} else if ((*it)->isGroup()) {
@@ -272,9 +264,7 @@ MaterialTables Group::calcMinimalMaterialTables() const {
272264
relevantMaterials.fill(false);
273265
for (const auto& elemPtr : elements) {
274266
int material = static_cast<int>(elemPtr->getMaterial()); // assuming getMaterial() exists
275-
if (material >= 1 && material <= 92) {
276-
relevantMaterials[material - 1] = true;
277-
}
267+
if (material >= 1 && material <= 92) { relevantMaterials[material - 1] = true; }
278268
}
279269
return loadMaterialTables(relevantMaterials);
280270
}
@@ -288,13 +278,11 @@ void Group::accumulateLightSourcesWorldPositions(const Group& group, const glm::
288278
assert(child && "m_children contains a nullptr!");
289279
if (child->isSource()) {
290280
DesignSource* srcPtr = static_cast<DesignSource*>(child.get());
291-
glm::dvec4 worldPos = currentOri * srcPtr->getPosition() + currentPos;
281+
glm::dvec4 worldPos = currentOri * srcPtr->getPosition() + currentPos;
292282
positions.push_back(worldPos);
293283
} else if (child->isGroup()) {
294284
Group* grpPtr = static_cast<Group*>(child.get());
295-
if (grpPtr) {
296-
accumulateLightSourcesWorldPositions(*grpPtr, currentPos, currentOri, positions);
297-
}
285+
if (grpPtr) { accumulateLightSourcesWorldPositions(*grpPtr, currentPos, currentOri, positions); }
298286
}
299287
}
300288
}
@@ -326,9 +314,7 @@ std::vector<OpticalElementAndTransform> Group::compileElements() const {
326314
std::vector<const DesignElement*> Group::getElements() const {
327315
std::vector<const DesignElement*> elements;
328316
ctraverse([&elements](const BeamlineNode& node) -> bool {
329-
if (node.isElement()) {
330-
elements.push_back(static_cast<const DesignElement*>(&node));
331-
}
317+
if (node.isElement()) { elements.push_back(static_cast<const DesignElement*>(&node)); }
332318
return false;
333319
});
334320
return elements;
@@ -337,9 +323,7 @@ std::vector<const DesignElement*> Group::getElements() const {
337323
std::vector<const DesignSource*> Group::getSources() const {
338324
std::vector<const DesignSource*> sources;
339325
ctraverse([&sources](const BeamlineNode& node) -> bool {
340-
if (node.isSource()) {
341-
sources.push_back(static_cast<const DesignSource*>(&node));
342-
}
326+
if (node.isSource()) { sources.push_back(static_cast<const DesignSource*>(&node)); }
343327
return false;
344328
});
345329
return sources;
@@ -386,9 +370,7 @@ std::vector<std::string> Group::getObjectNames() const {
386370
size_t Group::numElements() const {
387371
size_t count = 0;
388372
ctraverse([&count](const BeamlineNode& node) -> bool {
389-
if (node.isElement()) {
390-
++count;
391-
}
373+
if (node.isElement()) { ++count; }
392374
return false;
393375
});
394376
return count;
@@ -397,9 +379,7 @@ size_t Group::numElements() const {
397379
size_t Group::numSources() const {
398380
size_t count = 0;
399381
ctraverse([&count](const BeamlineNode& node) -> bool {
400-
if (node.isSource()) {
401-
++count;
402-
}
382+
if (node.isSource()) { ++count; }
403383
return false;
404384
});
405385
return count;
@@ -408,9 +388,7 @@ size_t Group::numSources() const {
408388
size_t Group::numObjects() const {
409389
size_t count = 0;
410390
ctraverse([&count](const BeamlineNode& node) -> bool {
411-
if (node.isSource() || node.isElement()) {
412-
++count;
413-
}
391+
if (node.isSource() || node.isElement()) { ++count; }
414392
return false;
415393
});
416394
return count;

Intern/rayx-core/src/Beamline/Beamline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RAYX_API Group : public BeamlineNode {
2323
Group(std::string name);
2424
~Group() = default;
2525

26-
Group(const Group&) = delete;
26+
Group(const Group&) = delete;
2727
Group& operator=(const Group&) = delete;
2828

2929
Group(Group&& other) noexcept;
@@ -171,7 +171,7 @@ class RAYX_API Group : public BeamlineNode {
171171

172172
private:
173173
// Position and orientation could in theory be put into one transform matrix but this follows the rml style
174-
glm::dvec4 m_position = glm::dvec4(0, 0, 0, 1);
174+
glm::dvec4 m_position = glm::dvec4(0, 0, 0, 1);
175175
glm::dmat4 m_orientation = glm::dmat4(1);
176176
// m_children vec is not checked for dangling or nullptrs anywhere, changes to the Group interface/implementation are to be made with care
177177
std::vector<std::unique_ptr<BeamlineNode>> m_children;

Intern/rayx-core/src/Beamline/DatFile.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ bool DatFile::load(const std::filesystem::path& filename, DatFile* out) {
3232
// line 3..EOF
3333
out->m_weightSum = 0;
3434
for (uint32_t lineidx = 3; std::getline(s, line); lineidx++) {
35-
if (line.empty()) {
36-
continue;
37-
}
35+
if (line.empty()) { continue; }
3836

3937
DatEntry e{};
4038
#if defined(WIN32)
@@ -60,9 +58,7 @@ bool DatFile::load(const std::filesystem::path& filename, DatFile* out) {
6058
std::stringstream s;
6159
s << m_title << '\n';
6260
s << m_lineCount << ' ' << m_start << ' ' << m_end << ' ' << m_step << '\n';
63-
for (auto line : m_Lines) {
64-
s << line.m_energy << ' ' << line.m_weight << "\n";
65-
}
61+
for (auto line : m_Lines) { s << line.m_energy << ' ' << line.m_weight << "\n"; }
6662

6763
return s.str();
6864
}

Intern/rayx-core/src/Beamline/Node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class RAYX_API BeamlineNode {
7575
*/
7676
glm::dmat4 getWorldOrientation() const;
7777

78-
virtual std::string getName() const = 0;
78+
virtual std::string getName() const = 0;
7979
virtual void setName(std::string name) = 0;
8080

8181
bool hasParent() const { return m_parent != nullptr; }

Intern/rayx-core/src/CanonicalizePath.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ namespace RAYX {
99

1010
/// this function assumes that `base` is already an absolute path
1111
std::filesystem::path canonicalize(const std::filesystem::path& relPath, const std::filesystem::path& base) {
12-
if (!base.is_absolute()) {
13-
RAYX_EXIT << "canonicalize called with non-absolute base path: \"" << base << "\"";
14-
}
12+
if (!base.is_absolute()) { RAYX_EXIT << "canonicalize called with non-absolute base path: \"" << base << "\""; }
1513
// absolute paths will stay unchanged
16-
if (relPath.is_absolute()) {
17-
return relPath;
18-
}
14+
if (relPath.is_absolute()) { return relPath; }
1915
// relative paths will be joined onto the base:
2016
// canonicalize("../foo/bar", "/home/username/RAY-X") =
2117
// "/home/username/RAY-X/../foo/bar" = "/home/username/foo/bar"

Intern/rayx-core/src/Core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
// not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
4646
#ifdef _MSC_VER
4747
#define strncasecmp _strnicmp
48-
#define strcasecmp _stricmp
48+
#define strcasecmp _stricmp
4949
#endif
5050

5151
#ifdef RAYX_BUILD_DLL

Intern/rayx-core/src/Debug/Debug.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,22 @@ constexpr int PREFIX_LEN = 30;
2020
* */
2121
void formatDebugMsg(std::string filename, int line, std::ostream& o) {
2222
size_t idx = filename.find_last_of("/\\");
23-
if (idx != std::string::npos) {
24-
filename = filename.substr(idx + 1);
25-
}
23+
if (idx != std::string::npos) { filename = filename.substr(idx + 1); }
2624

2725
std::stringstream strm;
2826
strm << line;
2927
std::string line_string = strm.str();
3028

3129
// this shortens filenames which are too long
3230
if (filename.size() + line_string.size() + 4 > PREFIX_LEN) {
33-
filename = filename.substr(0, PREFIX_LEN - 4 - line_string.size());
31+
filename = filename.substr(0, PREFIX_LEN - 4 - line_string.size());
3432
filename[filename.size() - 1] = '.';
3533
filename[filename.size() - 2] = '.';
3634
filename[filename.size() - 3] = '.';
3735
}
3836

3937
std::string pad;
40-
while (4 + line_string.size() + filename.size() + pad.size() < PREFIX_LEN) {
41-
pad += " ";
42-
}
38+
while (4 + line_string.size() + filename.size() + pad.size() < PREFIX_LEN) { pad += " "; }
4339
o.precision(17);
4440
o << "[" << pad << filename << ":" << line_string << "] ";
4541
}
@@ -75,15 +71,11 @@ Exit::~Exit() {
7571

7672
Verb::Verb(std::string filename, int line) {
7773
// only print if the verbose flag it set!
78-
if (getDebugVerbose()) {
79-
formatDebugMsg(std::move(filename), line, std::cout);
80-
}
74+
if (getDebugVerbose()) { formatDebugMsg(std::move(filename), line, std::cout); }
8175
}
8276

8377
Verb::~Verb() {
84-
if (getDebugVerbose()) {
85-
std::cout << std::endl;
86-
}
78+
if (getDebugVerbose()) { std::cout << std::endl; }
8779
}
8880

8981
// The default error_fn value. Exit with an error code of 1.
@@ -100,9 +92,7 @@ void dbg(const std::string& filename, int line, std::string name, std::vector<do
10092
int counter = 0; // stores the number of elements in the stringstream
10193
std::stringstream s;
10294
for (size_t i = 0; i < v.size(); i++) {
103-
if (counter != 0) {
104-
s << " ";
105-
}
95+
if (counter != 0) { s << " "; }
10696
s << std::setprecision(PREC) << v[i];
10797

10898
counter++;
@@ -112,9 +102,7 @@ void dbg(const std::string& filename, int line, std::string name, std::vector<do
112102
s = std::stringstream();
113103
}
114104
}
115-
if (counter > 0) {
116-
RAYX::Log(filename, line) << s.str();
117-
}
105+
if (counter > 0) { RAYX::Log(filename, line) << s.str(); }
118106
}
119107

120108
// The verbose flag used for RAYX_VERB printing.

Intern/rayx-core/src/Debug/Debug.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ struct RAYX_API Verb {
132132

133133
template <typename T>
134134
Verb& operator<<(T t) {
135-
if (getDebugVerbose()) {
136-
std::cout << t;
137-
}
135+
if (getDebugVerbose()) { std::cout << t; }
138136
return *this;
139137
}
140138
};
@@ -152,23 +150,23 @@ extern void RAYX_API (*error_fn)();
152150
// Defines the actual RAYX logging macros using the structs defined above.
153151
// The __FILE__ and __LINE__ macros contain the current filename and linenumber.
154152
// They are defined for us by c++ https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
155-
#define RAYX_LOG RAYX::Log(__FILE__, __LINE__)
153+
#define RAYX_LOG RAYX::Log(__FILE__, __LINE__)
156154
#define RAYX_WARN RAYX::Warn(__FILE__, __LINE__)
157155
#define RAYX_EXIT RAYX::Exit(__FILE__, __LINE__)
158156
#define RAYX_VERB RAYX::Verb(__FILE__, __LINE__)
159157

160158
#ifdef RAYX_DEBUG_MODE
161159
// In debug mode, RAYX_D_LOG is just the same as RAYX_LOG.
162-
#define RAYX_D_LOG RAYX_LOG
160+
#define RAYX_D_LOG RAYX_LOG
163161
#define RAYX_D_WARN RAYX_WARN
164-
#define RAYX_D_ERR RAYX_EXIT
162+
#define RAYX_D_ERR RAYX_EXIT
165163
#define RAYX_D_VERB RAYX_VERB
166164

167165
#else
168166
// In release mode, RAYX_D_LOG instead calls the IgnoreLog, hence discarding the print.
169-
#define RAYX_D_LOG RAYX::IgnoreLog()
167+
#define RAYX_D_LOG RAYX::IgnoreLog()
170168
#define RAYX_D_WARN RAYX::IgnoreLog()
171-
#define RAYX_D_ERR RAYX::IgnoreLog()
169+
#define RAYX_D_ERR RAYX::IgnoreLog()
172170
#define RAYX_D_VERB RAYX::IgnoreLog()
173171
#endif
174172

Intern/rayx-core/src/Debug/Instrumentor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class RAYX_API InstrumentationTimer {
3030
auto endTimepoint = std::chrono::high_resolution_clock::now();
3131

3232
long long start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimepoint).time_since_epoch().count();
33-
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count();
33+
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count();
3434

3535
if (m_canPrint) {
3636
long long duration = end - start;
37-
double seconds = duration * 0.000001;
37+
double seconds = duration * 0.000001;
3838
std::cout << "BENCH: " << m_Name << ":" << std::endl << seconds << "s" << std::endl;
3939
}
4040

0 commit comments

Comments
 (0)