Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/DataSource/PtclBaseDataSource.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "DataSource/PtclBaseDataSource.h"
00028 #include "DataSource/PtclAttribDataSource.h"
00029 #include "Profile/Profiler.h"
00030 
00031 
00032 // static objects for this class
00033 ParticleBaseDataSource::BaseList_t ParticleBaseDataSource::BaseList;
00034 
00035 
00037 // constructor: name, connection method, transfer method
00038 ParticleBaseDataSource::ParticleBaseDataSource(const char *nm,
00039                                                DataConnect *dc,
00040                                                int tm,
00041                                                DataSource *ds)
00042   : DataSourceObject(nm, ds, dc, tm){ }
00043 
00044 
00046 // destructor ... unregister ourselves if this has not already been done
00047 ParticleBaseDataSource::~ParticleBaseDataSource() {
00048   TAU_PROFILE("ParticleBaseDataSource::~ParticleBaseDataSource()",
00049               "void ()", TAU_VIZ);
00050 
00051   // disconnect all our currently connected attributes
00052   while (AttribList.size() > 0)
00053     disconnect_attrib(AttribList.front());
00054 
00055   // remove ourselves from the list of available ParticleBase containers
00056   checkout();
00057 }
00058 
00059 
00061 // try to add a new ParticleAttrib (stored in a ParticleAttribDataSource
00062 // object) to our list of connected attributes.  This will check through
00063 // the list of registered ParticleBase's, and add it to the proper one.
00064 // If none are found, this returns NULL, otherwise this method returns
00065 // a pointer to the ParticleBaseDataSource to which the attrib was added.
00066 // This function is static, so that it may be called without a specific
00067 // ParticleBaseDataSource instance.
00068 ParticleBaseDataSource*
00069 ParticleBaseDataSource::find_particle_base(ParticleAttribDataSource *pa,
00070                                            ParticleAttribBase *pabase) {
00071   TAU_PROFILE("ParticleBaseDataSource::find_particle_base()",
00072 "ParticleBaseDataSource * (ParticleAttribDataSource *, ParticleAttribBase *)", 
00073               TAU_VIZ);
00074 
00075   // search through the particle base holders, and check for matching
00076   // connection method, and if pa is in currbase
00077   BaseList_t::iterator currbase = ParticleBaseDataSource::begin_base();
00078   BaseList_t::iterator endbase = ParticleBaseDataSource::end_base();
00079   for ( ; currbase != endbase; ++currbase ) {
00080     ParticleBaseDataSource *list = *currbase;
00081     if (pa->getConnection()==list->getConnection() && list->has_attrib(pabase))
00082       return list;
00083   }
00084 
00085   // if we're here, we did not find the attribute
00086   return 0;
00087 }
00088 
00089 
00091 // register ourselves as a properly-connected ParticleBase holder.  This
00092 // should be called by the constructors of subclasses after a successful
00093 // connect.  Argument = name of this particle base
00094 void ParticleBaseDataSource::checkin() {
00095   TAU_PROFILE("ParticleBaseDataSource::checkin()", "void ()", TAU_VIZ);
00096 
00097   // first see if we're already here ...
00098   BaseList_t::iterator currbase = ParticleBaseDataSource::begin_base();
00099   BaseList_t::iterator endbase = ParticleBaseDataSource::end_base();
00100   for ( ; currbase != endbase; ++currbase )
00101     if (*currbase == this)
00102       return;                   // we're already checked in
00103 
00104   // add to the end of the list
00105   BaseList.push_back(this);
00106 }
00107 
00108 
00110 // unregister ourselves ... generally called by subclass destructors.
00111 void ParticleBaseDataSource::checkout() {
00112   TAU_PROFILE("ParticleBaseDataSource::checkout()", "void ()", TAU_VIZ);
00113 
00114   for (unsigned i=0; i < BaseList.size(); ++i) {
00115     if (BaseList[i] == this) {
00116       BaseList[i] = BaseList.back(); // move last element into this spot
00117       BaseList.pop_back();
00118       return;
00119     }
00120   }
00121 }
00122 
00123 
00125 // make a connection using the given attribute.  Return success.
00126 bool ParticleBaseDataSource::connect_attrib(ParticleAttribDataSource *pa) {
00127   TAU_PROFILE("ParticleBaseDataSource::connect_attrib()", 
00128     "bool (ParticleAttribDataSource *)", TAU_VIZ);
00129 
00130   AttribList.push_back(pa);
00131   return true;
00132 }
00133 
00134   
00136 // disconnect from the external agency the connection involving this
00137 // particle base and the given attribute.  Return success.
00138 bool ParticleBaseDataSource::disconnect_attrib(ParticleAttribDataSource *pa) {
00139   TAU_PROFILE("ParticleBaseDataSource::disconnect_attrib()", 
00140     "bool (ParticleAttribDataSource *)", TAU_VIZ);
00141 
00142   // remove the attribute from our list
00143   int i, size = AttribList.size();
00144   for (i=0; i < size; ++i) {
00145     if (pa == AttribList[i]) {
00146       AttribList[i] = AttribList.back();
00147       AttribList.pop_back();
00148       break;
00149     }
00150   }
00151 
00152   // tell the attribute we're disconnecting it
00153   pa->setDisconnected();
00154   return true;
00155 }
00156 
00157 
00158 /***************************************************************************
00159  * $RCSfile: PtclBaseDataSource.cpp,v $   $Author: adelmann $
00160  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:25 $
00161  * IPPL_VERSION_ID: $Id: PtclBaseDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $ 
00162  ***************************************************************************/

Generated on Fri Nov 2 01:25:55 2007 for IPPL by doxygen 1.3.5