The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
LinkManager.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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\***********************************************************************************/
14#include <algorithm>
15
16namespace {
17 template <typename Container, typename Pred>
18 auto findLink( Container& c, Pred pred ) {
19 auto i = std::find_if( c.begin(), c.end(), pred );
20 return i != c.end() ? *i : nullptr;
21 }
22
23} // namespace
24
27 for ( auto& i : m_linkVector ) delete i;
28}
29
32 if ( m_pObject ) {
33 IRegistry* pReg = m_pObject->registry();
34 if ( pReg ) return pReg->address();
35 }
36 return nullptr;
37}
38
40const LinkManager::Link* LinkManager::link( long id ) const {
41 return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
42}
43
45 return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
46}
47
49const LinkManager::Link* LinkManager::link( const DataObject* pObject ) const {
50 return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
51}
52
54 return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
55}
56
58const LinkManager::Link* LinkManager::link( std::string_view path ) const {
59 return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
60}
61LinkManager::Link* LinkManager::link( std::string_view path ) {
62 return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
63}
64
66long LinkManager::addLink( const std::string& path, const DataObject* pObject ) {
67 long n = 0;
68 for ( auto& lnk : m_linkVector ) {
69 const DataObject* pO = lnk->object();
70 if ( pO && pO == pObject ) return n;
71 if ( lnk->path() == path ) {
72 if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
73 return n;
74 }
75 ++n;
76 }
77 // Link is completely unknown
78 return m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) )->ID();
79}
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
Opaque address interface definition.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.