| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LinkManager.cpp
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/LinkManager.cpp,v 1.3 2004/01/23 11:22:04 mato Exp $
2
3 // Experiment specific include files
4 #include "GaudiKernel/LinkManager.h"
5 #include "GaudiKernel/DataObject.h"
6 #include "GaudiKernel/IRegistry.h"
7
8 static LinkManager* (*s_newInstance)() = 0;
9
11 IOpaqueAddress* LinkManager::Link::address() {
12 if ( 0 != m_pObject ) {
13 IRegistry* pReg = m_pObject->registry();
14 if ( 0 != pReg ) {
15 return pReg->address();
16 }
17 }
18 return 0;
19 }
20
22 void LinkManager::setInstantiator( LinkManager* (*newInstance)() ) {
23 s_newInstance = newInstance;
24 }
25
27 LinkManager* LinkManager::newInstance() {
28 return s_newInstance ? (*s_newInstance)() : new LinkManager();
29 }
30
32 LinkManager::LinkManager() {
33 }
34
36 LinkManager::~LinkManager() {
37 clearLinks();
38 }
39
41 LinkManager::Link* LinkManager::link(long id) {
42 return (0<=id && (unsigned)id < m_linkVector.size()) ? m_linkVector[id] : 0;
43 }
44
46 LinkManager::Link* LinkManager::link(const DataObject* pObject) {
47 if ( 0 != pObject ) {
48 for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
49 if ( (*i)->object() == pObject ) {
50 return (*i);
51 }
52 }
53 }
54 return 0;
55 }
56
58 LinkManager::Link* LinkManager::link(const std::string& path) {
59 if ( 0 != path.length() ) {
60 for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
61 if ( (*i)->path() == path ) {
62 return (*i);
63 }
64 }
65 }
66 return 0;
67 }
68
70 long LinkManager::addLink(const std::string& path, const DataObject* pObject) const {
71 long n = 0;
72 for ( LinkVector::const_iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
73 Link* lnk = *i;
74 const DataObject* pO = lnk->object();
75 if ( 0 != pO && pO == pObject ) {
76 return n;
77 }
78 bool same_path = lnk->path() == path;
79 if ( same_path ) {
80 if ( 0 != pObject && pObject != pO ) {
81 lnk->setObject(pObject);
82 }
83 return n;
84 }
85 n++;
86 }
87 // Link is completely unknown
88 Link* link = new Link(m_linkVector.size(), path, pObject);
89 m_linkVector.push_back( link );
90 return link->ID();
91 }
92
93 // Remove a link by object reference
94 long LinkManager::removeLink(const DataObject* pObject) const {
95 long n = 0;
96 for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
97 if ( (*i)->object() == pObject ) {
98 delete (*i);
99 m_linkVector.erase(i);
100 return n;
101 }
102 n++;
103 }
104 return INVALID;
105 }
106
107 // Remove a link by object reference
108 long LinkManager::removeLink(const std::string& path) const {
109 long n = 0;
110 for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
111 if ( (*i)->path() == path ) {
112 delete (*i);
113 m_linkVector.erase(i);
114 return n;
115 }
116 n++;
117 }
118 return INVALID;
119 }
120
121 // Remove a link by object reference
122 long LinkManager::removeLink(long id) const {
123 LinkVector::iterator i = m_linkVector.begin();
124 i += id;
125 delete (*i);
126 m_linkVector.erase(i);
127 return id;
128 }
129
131 void LinkManager::clearLinks() {
132 for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
133 delete (*i);
134 }
135 m_linkVector.erase(m_linkVector.begin(), m_linkVector.end());
136 }