OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PtclBaseDataSource.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17/***************************************************************************
18 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26// include files
29
30
31
32// static objects for this class
34
35
37// constructor: name, connection method, transfer method
39 DataConnect *dc,
40 int tm,
41 DataSource *ds)
42 : DataSourceObject(nm, ds, dc, tm){ }
43
44
46// destructor ... unregister ourselves if this has not already been done
48
49 // disconnect all our currently connected attributes
50 while (!AttribList.empty())
52
53 // remove ourselves from the list of available IpplParticleBase containers
54 checkout();
55}
56
57
59// try to add a new ParticleAttrib (stored in a ParticleAttribDataSource
60// object) to our list of connected attributes. This will check through
61// the list of registered IpplParticleBase's, and add it to the proper one.
62// If none are found, this returns NULL, otherwise this method returns
63// a pointer to the IpplParticleBaseDataSource to which the attrib was added.
64// This function is static, so that it may be called without a specific
65// IpplParticleBaseDataSource instance.
68 ParticleAttribBase *pabase) {
69
70 // search through the particle base holders, and check for matching
71 // connection method, and if pa is in currbase
74 for ( ; currbase != endbase; ++currbase ) {
75 IpplParticleBaseDataSource *list = *currbase;
76 if (pa->getConnection()==list->getConnection() && list->has_attrib(pabase))
77 return list;
78 }
79
80 // if we're here, we did not find the attribute
81 return 0;
82}
83
84
86// register ourselves as a properly-connected IpplParticleBase holder. This
87// should be called by the constructors of subclasses after a successful
88// connect. Argument = name of this particle base
90
91
92 // first see if we're already here ...
95 for ( ; currbase != endbase; ++currbase )
96 if (*currbase == this)
97 return; // we're already checked in
98
99 // add to the end of the list
100 BaseList.push_back(this);
101}
102
103
105// unregister ourselves ... generally called by subclass destructors.
107
108
109 for (unsigned i=0; i < BaseList.size(); ++i) {
110 if (BaseList[i] == this) {
111 BaseList[i] = BaseList.back(); // move last element into this spot
112 BaseList.pop_back();
113 return;
114 }
115 }
116}
117
118
120// make a connection using the given attribute. Return success.
122 AttribList.push_back(pa);
123 return true;
124}
125
126
128// disconnect from the external agency the connection involving this
129// particle base and the given attribute. Return success.
131
132 // remove the attribute from our list
133 int i, size = AttribList.size();
134 for (i=0; i < size; ++i) {
135 if (pa == AttribList[i]) {
136 AttribList[i] = AttribList.back();
137 AttribList.pop_back();
138 break;
139 }
140 }
141
142 // tell the attribute we're disconnecting it
143 pa->setDisconnected();
144 return true;
145}
146
147
148/***************************************************************************
149 * $RCSfile: PtclBaseDataSource.cpp,v $ $Author: adelmann $
150 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
151 * IPPL_VERSION_ID: $Id: PtclBaseDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
152 ***************************************************************************/
std::string::iterator iterator
Definition: MSLang.h:16
DataConnect * getConnection()
static BaseList_t::iterator end_base()
virtual bool disconnect_attrib(ParticleAttribDataSource *)
virtual bool connect_attrib(ParticleAttribDataSource *)
IpplParticleBaseDataSource(const char *, DataConnect *, int, DataSource *)
static BaseList_t::iterator begin_base()
std::vector< IpplParticleBaseDataSource * > BaseList_t
virtual bool has_attrib(ParticleAttribBase *)=0
static IpplParticleBaseDataSource * find_particle_base(ParticleAttribDataSource *, ParticleAttribBase *)