Skip to content

Commit

Permalink
Create FairBaseTypes.h
Browse files Browse the repository at this point in the history
Created `namespace FairRoot`
with `struct EntryID {size_t fId;}`.

Should replace PR #1405.
  • Loading branch information
karabowi committed Jun 13, 2023
1 parent 9717b2e commit b1796c2
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fairroot/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set(sources

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

list(APPEND headers
FairBaseTypes.h
)

add_library(${target} SHARED ${sources} ${headers})
fairroot_library_settings(${target})
# Keep old filesystem name
Expand Down
81 changes: 81 additions & 0 deletions fairroot/tools/FairBaseTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/********************************************************************************
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/*
* FairBaseTypes.h
*
* Created on: May 16, 2023
* Author: R.Karabowicz
*/

#ifndef FAIR_BASETYPES_H_
#define FAIR_BASETYPES_H_

#include <iostream>
#include <limits>

namespace FairRoot {
struct EntryID {
using underlying_type = size_t;

static constexpr underlying_type None = std::numeric_limits<underlying_type>::max();

EntryID(underlying_type value) : fId(value) {}

EntryID() : EntryID(None) {}

operator underlying_type() const { return fId; }

friend auto operator<<(std::ostream& os, EntryID id) -> std::ostream& {
if (id == None) {
return os << "<No Entry>";
}
return os << static_cast<underlying_type>(id);
}

auto operator++() {
if (fId != None) {
++fId;
}
return *this;
}
auto operator++(int) {
auto temp = *this;
if (fId != None) {
++fId;
}
return temp;
}

auto operator--() {
if (fId != None) {
--fId;
}
return *this;
}
auto operator--(int) {
auto temp = *this;
if (fId != None) {
--fId;
}
return temp;
}
auto operator+=(const EntryID& rhs) {
fId += rhs.fId;
return *this;
}
auto operator-=(const EntryID& rhs) {
fId -= rhs.fId;
return *this;
}

private:
underlying_type fId;
};
}

#endif // FAIR_BASETYPES_H_

0 comments on commit b1796c2

Please sign in to comment.