Skip to content

Commit 914afe8

Browse files
committed
Create FairTypes.h
Created `namespace FairRoot` with `struct EntryID {size_t fId;}`. Should replace PR #1405.
1 parent 9717b2e commit 914afe8

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

fairroot/base/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ endif()
8282

8383
fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)
8484

85+
list(APPEND headers
86+
steer/FairTypes.h
87+
)
88+
8589
add_library(${target} SHARED ${sources} ${headers})
8690
fairroot_library_settings(${target})
8791

fairroot/base/steer/FairTypes.h

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/********************************************************************************
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3+
* *
4+
* This software is distributed under the terms of the *
5+
* GNU Lesser General Public Licence (LGPL) version 3, *
6+
* copied verbatim in the file "LICENSE" *
7+
********************************************************************************/
8+
/*
9+
* FairTypes.h
10+
*
11+
* Created on: May 16, 2023
12+
* Author: R.Karabowicz
13+
*/
14+
15+
#ifndef FAIR_TYPES_H_
16+
#define FAIR_TYPES_H_
17+
18+
#include <iostream>
19+
#include <limits>
20+
21+
/**
22+
* \brief Main namespace for FairRoot classes / types
23+
*
24+
* All new public classes and types of FairRoot will be in this namespace.
25+
* Note: Nost classes are still in no namespace.
26+
*/
27+
namespace FairRoot {
28+
/**
29+
* \brief Ordinal identification number of entry in IO stream
30+
*
31+
* Data stored in ROOT trees are gropued into entries,
32+
* essentially equivalent to HEP events
33+
*/
34+
struct EntryID
35+
{
36+
using underlying_type = size_t;
37+
38+
static const EntryID None;
39+
40+
EntryID(underlying_type value)
41+
: fId(value)
42+
{}
43+
44+
EntryID() = default;
45+
46+
operator underlying_type() const { return fId; }
47+
48+
friend auto operator<<(std::ostream& os, EntryID id) -> std::ostream&
49+
{
50+
if (id == None) {
51+
return os << "<No Entry>";
52+
}
53+
return os << static_cast<underlying_type>(id);
54+
}
55+
56+
auto operator++()
57+
{
58+
if (fId != None) {
59+
++fId;
60+
}
61+
return *this;
62+
}
63+
auto operator++(int)
64+
{
65+
auto temp = *this;
66+
if (fId != None) {
67+
++fId;
68+
}
69+
return temp;
70+
}
71+
72+
auto operator--()
73+
{
74+
if (fId != None) {
75+
--fId;
76+
}
77+
return *this;
78+
}
79+
auto operator--(int)
80+
{
81+
auto temp = *this;
82+
if (fId != None) {
83+
--fId;
84+
}
85+
return temp;
86+
}
87+
auto operator+=(const EntryID& rhs)
88+
{
89+
fId += rhs.fId;
90+
return *this;
91+
}
92+
auto operator-=(const EntryID& rhs)
93+
{
94+
fId -= rhs.fId;
95+
return *this;
96+
}
97+
98+
private:
99+
underlying_type fId{std::numeric_limits<underlying_type>::max()};
100+
};
101+
102+
/// \sa https://stackoverflow.com/questions/29432283/c-static-constexpr-field-with-incomplete-type/50295183#50295183
103+
inline constexpr const EntryID EntryID::None{};
104+
} // namespace FairRoot
105+
106+
#endif // FAIR_TYPES_H_

0 commit comments

Comments
 (0)