-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created `namespace FairRoot` with `struct EntryID {size_t fId;}`. Should replace PR #1405.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |