00001
00011 #ifndef SIMOBJECTPOPULATION_H_
00012 #define SIMOBJECTPOPULATION_H_
00013
00014 #include <cstdlib>
00015 #include <boost/shared_ptr.hpp>
00016 using boost::shared_ptr;
00017
00018 #include "SimNetwork.h"
00019
00021
00027 class SimObjectPopulation {
00028
00029 protected:
00030
00032 SimObjectPopulation( ) : id_vec(NULL), net(NULL) { }
00033 ;
00034
00036 SimObjectPopulation( SimNetwork &net ) : id_vec(NULL), net(&net) { }
00037 ;
00038
00039 public:
00040
00041 SimObjectPopulation( SimNetwork &net, SimObjectFactory &objFactory, size_t n )
00042 : net(&net)
00043 {
00044 shr_ptr_vec = net.add(objFactory, n);
00045 id_vec = shr_ptr_vec.get();
00046 };
00047
00048 SimObjectPopulation( SimNetwork &net, const SimObject::ID::Vector v )
00049 : net(&net)
00050 {
00051 shr_ptr_vec = v;
00052 id_vec = shr_ptr_vec.get();
00053 };
00054
00055 SimObjectPopulation( SimNetwork &net, vector< SimObject::ID::Packed > const& v )
00056 : net(&net)
00057 {
00058 shr_ptr_vec = SimObject::ID::Vector( new vector< SimObject::ID::Packed >( v ) );
00059 id_vec = shr_ptr_vec.get();
00060 }
00061
00062 protected:
00063
00064 friend class WiringMethod;
00065 friend class OneToOneWiringMethod;
00066 friend class SimpleAllToAllWiringMethod;
00067 friend class DistributedSyncWiringMethod;
00071 SimObjectPopulation(const vector< SimObject::ID::Packed > & v)
00072 : net(NULL) {
00073 id_vec = &v;
00074 };
00075
00076 public:
00077 SimObject::ID::Packed operator[] (int idx) const {
00078 return (*id_vec)[idx];
00079 };
00080
00081 virtual SimObject::ID getID(int idx) const {
00082 return SimObject::ID((*id_vec)[idx]);
00083 };
00084
00085 SimObject * object(int idx) const {
00086 return net->object((*id_vec)[idx]);
00087 };
00088
00089 SimObject::ID operator() (int idx) const {
00090 return (SimObject::ID)((*id_vec)[idx]);
00091 };
00092
00094 size_t size() const {
00095 return id_vec->size();
00096 };
00097
00098 const vector<SimObject::ID::Packed> & idVector() const {
00099 return *id_vec;
00100 };
00101
00102 virtual ~SimObjectPopulation() {}
00103 ;
00104
00105
00106 SimNetwork & getNet() const {
00107 return *net;
00108 } ;
00109
00111 shared_ptr<SimObjectPopulation> subset( vector< size_t > const& subindices ) const {
00112 return shared_ptr<SimObjectPopulation>( new_subset( subindices ) );
00113 };
00114
00115 shared_ptr<SimObjectPopulation> localSubPopulation();
00116
00117 vector<size_t> *localIndexes();
00118
00119 bool setFieldScale(string const & fieldname, double scale);
00120
00121 public:
00122
00123 virtual shared_ptr<SimObjectPopulation> record(const SimObjectFactory &recFactory, const port_t src_port = 0);
00124
00125 virtual shared_ptr<SimObjectPopulation> record(const SimObjectFactory &recFactory, const string field);
00126
00127
00128 protected:
00129
00131 virtual SimObjectPopulation* new_subset( vector< size_t > const& indices ) const;
00132
00134 SimObject::ID::Vector shr_ptr_vec;
00135
00137 const vector< SimObject::ID::Packed > * id_vec;
00138
00140 SimNetwork *net;
00141 };
00142
00143
00144 #endif