PtclBaseDataSource.h 4.3 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

#ifndef PARTICLE_BASE_DATA_SOURCE_H
#define PARTICLE_BASE_DATA_SOURCE_H

/***********************************************************************
 *
16
 * class IpplParticleBaseDataSource
gsell's avatar
gsell committed
17
 *
18 19 20
 * IpplParticleBaseDataSource is a base class which
 * stores a static list of all IpplParticleBaseDataSource's (stored as
 * IpplParticleBaseDataSource pointers) which are currently connected.  This
gsell's avatar
gsell committed
21
 * is needed so that ParticleAttrib's can determine if their parent
22 23
 * IpplParticleBase has been previously connected, and if so they can then
 * put themselves in the list for that IpplParticleBase as an attribute to be
gsell's avatar
gsell committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * transmitted along with the particle positions.  Subclasses provide
 * specific functionality to connect to external agencies such as viz
 * programs.
 *
 ***********************************************************************/

// include files 
#include "DataSource/DataSourceObject.h"

#ifdef IPPL_STDSTL
#include <vector>
#else
#include <vector.h>
#endif // IPPL_STDSTL


// forward declarations
class ParticleAttribDataSource;
class ParticleAttribBase;


45
class IpplParticleBaseDataSource : public DataSourceObject {
gsell's avatar
gsell committed
46 47 48 49

public:
  // some useful typedefs
  typedef std::vector<ParticleAttribDataSource *> AttribList_t;
50
  typedef std::vector<IpplParticleBaseDataSource *>   BaseList_t;
gsell's avatar
gsell committed
51 52 53

public:
  // constructor: name, connection method, transfer method
54
  IpplParticleBaseDataSource(const char *, DataConnect *, int, DataSource *);
gsell's avatar
gsell committed
55 56

  // destructor
57
  virtual ~IpplParticleBaseDataSource();
gsell's avatar
gsell committed
58 59 60 61 62 63 64 65 66 67 68

  // get the begin/end iterators for the list of attributes
  AttribList_t::iterator begin_attrib() { return AttribList.begin(); }
  AttribList_t::iterator end_attrib()   { return AttribList.end(); }

  // return begin/end iterators for the list of particle base holders
  static BaseList_t::iterator begin_base() { return BaseList.begin(); }
  static BaseList_t::iterator end_base()   { return BaseList.end(); }

  // try to add a new ParticleAttrib (stored in a ParticleAttribDataSource
  // object) to our list of connected attributes.  This will check through
69
  // the list of registered IpplParticleBase's, and add it to the proper one.
gsell's avatar
gsell committed
70
  // If none are found, this returns NULL, otherwise this method returns
71
  // a pointer to the IpplParticleBaseDataSource to which the attrib was added.
gsell's avatar
gsell committed
72
  // This function is static, so that it may be called without a specific
73
  // IpplParticleBaseDataSource instance.
gsell's avatar
gsell committed
74
  static
75
  IpplParticleBaseDataSource* find_particle_base(ParticleAttribDataSource *,
gsell's avatar
gsell committed
76 77 78
					     ParticleAttribBase *);

  //
79
  // IpplParticleBaseDataSource public virtual function interface
gsell's avatar
gsell committed
80 81 82 83 84 85 86 87 88
  //

  // make a connection using the given attribute.  Return success.
  virtual bool connect_attrib(ParticleAttribDataSource *);

  // disconnect from the external agency the connection involving this
  // particle base and the given attribute.  Return success.
  virtual bool disconnect_attrib(ParticleAttribDataSource *);

89
  // check to see if the given ParticleAttribBase is in this IpplParticleBase's
gsell's avatar
gsell committed
90 91 92 93
  // list of registered attributes.  Return true if this is so.
  virtual bool has_attrib(ParticleAttribBase *) = 0;

protected:
94
  // register ourselves as a properly-connected IpplParticleBase holder.  This
gsell's avatar
gsell committed
95 96 97 98 99 100 101 102 103 104
  // should be called by the connect method in subclasses after a successful
  // checkin.
  void checkin();

  // unregister ourselves ... generally called by the disconnect method
  // of subclasses.
  void checkout();

private:
  // a non-static list of the ParticleAttrib's which have been requested
105
  // to connect to the same receiver as this object's IpplParticleBase
gsell's avatar
gsell committed
106 107
  AttribList_t AttribList;

108
  // a static list of the currently-connected IpplParticleBaseDataSource's.
gsell's avatar
gsell committed
109 110 111 112 113 114 115 116 117 118 119
  static BaseList_t BaseList;
};


#endif // PARTICLE_BASE_DATA_SOURCE_H

/***************************************************************************
 * $RCSfile: PtclBaseDataSource.h,v $   $Author: adelmann $
 * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:25 $
 * IPPL_VERSION_ID: $Id: PtclBaseDataSource.h,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $ 
 ***************************************************************************/