• Main Page
  • Classes
  • Files
  • File List

EvSimObject.h

00001 #ifndef EvSimObject_H_
00002 #define EvSimObject_H_
00003 
00004 #include <cstring>
00005 #include <vector>
00006 
00007 #include <boost/shared_ptr.hpp>
00008 using boost::shared_ptr;
00009 
00010 #include "globals.h"
00011 #include "EvSimObjectFactory.h"
00012 
00013 #include <string>
00014 using std::string;
00015 
00016 #ifndef SWIG
00017 
00018 #include <typeinfo>
00019 using std::type_info;
00020 
00021 #endif
00022 
00023 class EvSimNetwork;
00024 class SimContext;
00025 
00026 class EvSimObjectTypeUtilsBase;
00027 
00029 class NoVariableFound {
00030 };
00031 
00033 
00037 class EvSimObject : public virtual EvSimObjectFactory {
00038 
00039 public:
00040         typedef enum { eventPortDirect, eventPortProjected, portUndefined } PortType;
00041 
00042 
00043         typedef unsigned ID;
00044 
00045         typedef shared_ptr< std::vector< ID > > IDVector;
00046 
00047         EvSimObject();
00048         virtual ~EvSimObject();
00049 
00050         virtual void announceEvEmitted(SimContext & sim_ctxt, Time time, global_proj_out_port_id_t port_id) {};
00051 
00052         virtual void eventHit(SimContext & sim_ctxt, Time time, port_id_t port) {};
00053 
00054         virtual void updateState(SimContext &sim_ctxt, Time time, update_id_t upd_id) {};
00055 
00056         virtual bool owned_by_net()
00057         {
00058                 return true;
00059         };
00060 
00061         virtual unsigned numProjOutputPorts() const
00062         {
00063                 return 0;
00064         };
00065 
00066         virtual unsigned numOutputPorts() const
00067         {
00068                 return 0;
00069         };
00070 
00071 
00072         virtual unsigned numInputPorts() const
00073         {
00074                 return 0;
00075         };
00076 
00077         virtual PortType getOutputPortType(port_id_t) const
00078         {
00079                 return portUndefined;
00080         };
00081 
00082         virtual PortType getInputPortType(port_id_t) const
00083         {
00084                 return portUndefined;
00085         };
00086 
00087         virtual void init(EvSimNetwork & net, ID id)
00088         {};
00089 
00090         virtual void reset(SimContext &sim_ctxt)
00091         {};
00092 
00093         virtual const EvSimObjectTypeUtilsBase * getSimObjTypeUtils() const {return 0;} ;
00094 
00095         virtual EvSimObject *copy() const;
00096 
00097         EvSimObject *create(void) const;
00098 
00099         void * const getVariablePtr(const string &var_name) const;
00100 
00101         const type_info & getVariableType(const string &var_name) const;
00102 
00103         const string & getTypeName() const;
00104 
00105         string getTypeNameWithPtr() const {
00106                 return getTypeName() + " *";
00107         }
00108 
00109         virtual void postAddedInNetwork(EvSimNetwork &net, EvSimObject::ID self) {};
00110 
00111         virtual void postOutPortConnect(EvSimNetwork &net, port_id_t p, EvSimObject::ID dest, port_id_t dest_port) {};
00112 
00113         virtual void postInputPortConnect(EvSimNetwork &net, port_id_t p, EvSimObject::ID src, port_id_t src_port) {};
00114 
00115         virtual void postSrcCausalLink(EvSimNetwork &net, EvSimObject::ID target, update_id_t upd_id) {};
00116 
00117         virtual void postTargetCausalLink(EvSimNetwork &net, EvSimObject::ID src, update_id_t upd_id) {};
00118 
00119         virtual void postMountAsMountedObj(EvSimNetwork &net, EvSimObject::ID self, EvSimObject::ID mountpoint) {};
00120 
00121         virtual void postMountAsMountPoint(EvSimNetwork &net, EvSimObject::ID self, EvSimObject::ID mounted_obj) {};
00122 
00123         virtual bool propagatesUpdate(update_id_t upd_id) const {
00124                 return true;
00125         }
00126 
00127 
00128 
00129 
00130 
00131 
00132 #ifndef SWIG
00133 
00134 public:
00136 
00140     class BlockAllocator
00141     {
00142     public:
00143         BlockAllocator( size_t blockSize = EVSIMOBJECT_ALLOCATOR_BLOCK_SIZE );
00144 
00145         ~BlockAllocator();
00146         void *allocate( size_t size );
00147     private:
00148         size_t blk_sz;
00149         std::vector< void* > mem_block;
00150         char *free_pos;
00151         size_t num_free_bytes;
00152     };
00153 
00154     void static setAllocator( BlockAllocator & ba );
00155 
00156     void *operator new(size_t sz);
00157     void operator delete(void *, size_t);
00158 
00159     void *operator new[](size_t sz);
00160     void operator delete[](void *, size_t);
00161 
00162 #ifdef DEBUG
00163 
00164         void setID(ID id) {
00165                 my_id = id;
00166         }
00167 
00168         ID my_id;
00169 
00170 #endif
00171 
00172 
00173 
00174 private:
00175 
00176     static BlockAllocator defaultAllocator;
00177     static BlockAllocator *currentAllocator;
00179 
00180 
00181 
00182 #endif
00183 
00184 };
00185 
00186 extern const EvSimObject::ID INVALID_EVSIMOBJECT_ID;
00187 
00188 #endif /* EvSimObject_H_ */

Generated on Wed Sep 18 2013 11:25:40 for NEVESIM by  doxygen 1.7.1