The Gaudi Framework  master (37c0b60a)
LinkManager.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_LINKMANAGER_H
12 #define GAUDIKERNEL_LINKMANAGER_H
13 
14 // STL includes
15 #include <memory>
16 #include <string>
17 #include <vector>
18 // Gaudi
19 #include <GaudiKernel/Kernel.h>
20 
21 class DataObject;
22 class IOpaqueAddress;
23 
31 class GAUDI_API LinkManager final {
32 
33 public:
35  enum DirLinkType { INVALID, VALID };
36 
41  class Link final {
45  DataObject* m_pObject = nullptr;
47  long m_id = INVALID;
48 
49  public:
51  Link( long id, std::string path, DataObject* pObject = nullptr )
52  : m_path( std::move( path ) ), m_pObject( pObject ), m_id( id ) {}
54  Link() = default;
56  bool operator==( const Link& link ) const { return link.m_path == m_path; }
58  void setObject( const DataObject* pObject ) { m_pObject = const_cast<DataObject*>( pObject ); }
60  const DataObject* object() const { return m_pObject; }
61  DataObject* object() { return m_pObject; }
63  const std::string& path() const { return m_path; }
65  long ID() const { return m_id; }
67  IOpaqueAddress* address();
68  };
69 
70 private:
80 
81 public:
83  LinkManager() = default;
84  LinkManager( LinkManager&& ) = default;
86  LinkManager( LinkManager const& ) = delete;
87  LinkManager& operator=( LinkManager const& ) = delete;
89  ~LinkManager();
91  long size() const { return m_linkVector.size(); }
92  bool empty() const { return m_linkVector.empty(); }
94  const Link* link( long id ) const;
95  Link* link( long id );
97  const Link* link( const DataObject* pObject ) const;
98  Link* link( const DataObject* pObject );
100  const Link* link( std::string_view path ) const;
101  Link* link( std::string_view path );
103  long addLink( const std::string& path, const DataObject* pObject );
104 
105  struct Sentinel {};
106  Sentinel end() const { return {}; }
107  auto begin() const {
108  class Iterator {
109  int i;
110  LinkManager const* parent;
111 
112  public:
113  Iterator( LinkManager const* p, int i ) : i{ i }, parent{ p } {}
114  bool operator==( Sentinel ) const { return i == parent->size(); }
115  bool operator!=( Sentinel ) const { return !( *this == Sentinel{} ); }
116  Iterator& operator++() {
117  ++i;
118  return *this;
119  }
120  const Link& operator*() const { return *parent->link( i ); }
121  };
122  return Iterator{ this, 0 };
123  }
124 };
125 #endif // GAUDIKERNEL_LINKMANAGER_H
std::string
STL class.
Io::INVALID
@ INVALID
Definition: IFileMgr.h:47
Gaudi::Accumulators::operator*
auto operator*(const std::chrono::duration< Rep1, Period > &lhs, const std::chrono::duration< Rep2, Period > &rhs)
Multiplication of two std::chrono::duration objects with same Period.
Definition: Counters.h:40
Gaudi::Allocator::operator!=
constexpr bool operator!=(Arena< Resource, T, DefaultResource > const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
Definition: Arena.h:86
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::vector
STL class.
std::vector::size
T size(T... args)
GaudiPartProp.tests.id
id
Definition: tests.py:111
std
STL namespace.
Kernel.h
DataObject
Definition: DataObject.h:36
std::vector::empty
T empty(T... args)
Gaudi::Details::operator==
bool operator==(const PropertyId &lhs, const PropertyId &rhs)
Definition: PropertyId.h:111
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28