The Gaudi Framework  v36r1 (3e2fb5a8)
LinkManager.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 // Experiment specific include files
13 #include "GaudiKernel/DataObject.h"
14 #include "GaudiKernel/IRegistry.h"
15 
16 static LinkManager* ( *s_newInstance )() = nullptr;
17 
20  for ( auto& i : m_linkVector ) delete i;
21 }
22 
25  if ( m_pObject ) {
26  IRegistry* pReg = m_pObject->registry();
27  if ( pReg ) return pReg->address();
28  }
29  return nullptr;
30 }
31 
34 
36 LinkManager* LinkManager::newInstance() { return s_newInstance ? ( *s_newInstance )() : new LinkManager(); }
37 
40  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
41 }
42 
45  if ( pObject ) {
46  for ( auto& i : m_linkVector ) {
47  if ( i->object() == pObject ) return i;
48  }
49  }
50  return nullptr;
51 }
52 
55  if ( 0 != path.length() ) {
56  for ( auto& i : m_linkVector ) {
57  if ( i->path() == path ) return i;
58  }
59  }
60  return nullptr;
61 }
62 
64 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) const {
65  long n = 0;
66  for ( auto& lnk : m_linkVector ) {
67  const DataObject* pO = lnk->object();
68  if ( pO && pO == pObject ) return n;
69  if ( lnk->path() == path ) {
70  if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
71  return n;
72  }
73  ++n;
74  }
75  // Link is completely unknown
76  m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) );
77  return m_linkVector.back()->ID();
78 }
79 
80 // Remove a link by object reference
81 long LinkManager::removeLink( const DataObject* pObject ) const {
82  long n = 0;
83  for ( auto i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
84  if ( ( *i )->object() == pObject ) {
85  delete *i;
86  m_linkVector.erase( i );
87  return n;
88  }
89  ++n;
90  }
91  return INVALID;
92 }
93 
94 // Remove a link by object reference
96  long n = 0;
97  for ( auto i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
98  if ( ( *i )->path() == path ) {
99  delete *i;
100  m_linkVector.erase( i );
101  return n;
102  }
103  n++;
104  }
105  return INVALID;
106 }
107 
108 // Remove a link by object reference
109 long LinkManager::removeLink( long id ) const {
110  auto i = std::next( m_linkVector.begin(), id );
111  delete *i;
112  m_linkVector.erase( i );
113  return id;
114 }
115 
118  for ( auto& i : m_linkVector ) delete i;
119  m_linkVector.clear();
120 }
std::string
STL class.
IOpaqueAddress
Definition: IOpaqueAddress.h:33
IRegistry
Definition: IRegistry.h:32
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:943
IRegistry.h
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:221
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
DataObject.h
DataObject
Definition: DataObject.h:40
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
std::next
T next(T... args)