• Main Page
  • Classes
  • Files
  • File List

GenericBinaryArrayInputSynapse.h

00001 #ifndef GENERICBINARYARRAYINPUTSYNAPSE_H_
00002 #define GENERICBINARYARRAYINPUTSYNAPSE_H_
00003 
00004 #include "EvSimObjectTypeUtils.h"
00005 #include "Synapse.h"
00006 #include "SharedArrayTypes.h"
00007 
00008 #include <vector>
00009 
00010 #ifndef SWIG
00011 
00012 #include <iostream>
00013 using std::cerr;
00014 using std::endl;
00015 
00016 #endif
00017 
00018 #include "SharedArrayTypes.h"
00019 #include "SimContext.h"
00020 
00021 
00022 template<class BaseSyn>
00023 class GenericBinaryArrayInputSynapse : public BaseSyn {
00024 
00025 public:
00026         GenericBinaryArrayInputSynapse(SharedBoolArray & shared_bin_array,
00027                                                                    float psr_level_hi = 5,
00028                                                                    float psr_level_lo = 0,
00029                                                                    bool isActive = true) {
00030                 this->bin_array = shared_bin_array.get();
00031                 is_arr_owner = false;
00032                 this->psr_level_hi = psr_level_hi;
00033                 this->psr_level_lo = psr_level_lo;
00034                 this->isActive = isActive;
00035         }
00036 
00037         float psr_level_hi;
00038 
00039         float psr_level_lo;
00040 
00041         GenericBinaryArrayInputSynapse(const vector<bool> & bin_array,
00042                                                                    float psr_level_hi = 5,
00043                                                                    float psr_level_lo = 0,
00044                                                                    bool isActive = true) {
00045                 this->bin_array = new vector<bool>(bin_array);
00046                 is_arr_owner = true;
00047                 this->psr_level_hi = psr_level_hi;
00048                 this->psr_level_lo = psr_level_lo;
00049                 this->isActive = isActive;
00050         }
00051 
00052         const std::vector<bool> & getBinaryArray() {
00053                 return *bin_array;
00054         }
00055 
00056         void setBinaryArray(const vector<bool> & bin_array) {
00057                 if (is_arr_owner) {
00058                         if (this->bin_array)
00059                                 delete this->bin_array;
00060                 }
00061                 is_arr_owner = true;
00062                 this->bin_array = new vector<bool>(bin_array);
00063         }
00064 
00065         void setBinaryArray(SharedBoolArray & shared_bin_array) {
00066                 if (is_arr_owner) {
00067                         if (bin_array)
00068                                 delete bin_array;
00069                 }
00070                 is_arr_owner = false;
00071                 this->bin_array = shared_bin_array.get();
00072         }
00073 
00074         virtual ~GenericBinaryArrayInputSynapse() {
00075                 if (is_arr_owner)
00076                         delete bin_array;
00077         }
00078 
00079         virtual EvSimObject *copy() const {
00080                 GenericBinaryArrayInputSynapse<BaseSyn> *obj =
00081                                      dynamic_cast<GenericBinaryArrayInputSynapse<BaseSyn> *>(this->EvSimObject::copy());
00082                 if (is_arr_owner)
00083                         obj->bin_array = new vector<bool>(*bin_array);
00084                 return obj;
00085         }
00086 
00087         virtual void reset(SimContext &sim_ctxt);
00088 
00089         virtual void eventHit(SimContext & sim_ctxt, Time time, port_id_t port);
00090 
00091 protected:
00092         double psr;
00093         const vector<bool> *bin_array;
00094         unsigned curr_idx;
00095         bool is_arr_owner;
00096         bool isActive;
00097 };
00098 
00099 template<class BaseSyn>
00100 void GenericBinaryArrayInputSynapse<BaseSyn>::eventHit(SimContext & sim_ctxt, Time time, port_id_t port)
00101 {
00102         if (port == 0) {
00103                 if (curr_idx == bin_array->size())
00104                         curr_idx = 0;
00105                 if (isActive)
00106                         BaseSyn::updatePSR(((*bin_array)[curr_idx++]) ? psr_level_hi : psr_level_lo, time);
00107         }
00108         else if (port == 1) {
00109                 isActive = !isActive;
00110                 if (!isActive)
00111                         BaseSyn::updatePSR(0, time);
00112                 else
00113                         BaseSyn::updatePSR(((*bin_array)[curr_idx]) ? psr_level_hi : psr_level_lo, time);
00114         }
00115 }
00116 
00117 
00118 template<class BaseSyn>
00119 void GenericBinaryArrayInputSynapse<BaseSyn>::reset(SimContext &sim_ctxt)
00120 {
00121         BaseSyn::resetPSRs();
00122         curr_idx = 0;
00123 }
00124 
00125 #endif /* GENERICBINARYARRAYINPUTSYNAPSE_H_ */

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