AnimatLab  2
Test
FiringRateSim/ClassFactory.cpp
1 
7 #include "StdAfx.h"
8 
9 #include "Synapse.h"
10 #include "GatedSynapse.h"
11 #include "ModulatedSynapse.h"
12 #include "ModulateNeuronPropSynapse.h"
13 #include "Neuron.h"
14 #include "PacemakerNeuron.h"
15 #include "TonicNeuron.h"
16 #include "RandomNeuron.h"
17 #include "BistableNeuron.h"
18 #include "FiringRateModule.h"
19 #include "ClassFactory.h"
20 
21 namespace FiringRateSim
22 {
23 
31 {
32 
33 }
34 
42 {
43 
44 }
45 
46 Neuron *ClassFactory::CreateNeuron(std::string strType, bool bThrowError)
47 {
48  Neuron *lpNeuron=NULL;
49 
50 try
51 {
52  strType = Std_ToUpper(Std_Trim(strType));
53 
54  if(strType == "REGULAR")
55  lpNeuron = new Neuron;
56  else if(strType == "PACEMAKER")
57  lpNeuron = new PacemakerNeuron;
58  else if(strType == "TONIC")
59  lpNeuron = new TonicNeuron;
60  else if(strType == "RANDOM")
61  lpNeuron = new RandomNeuron;
62  else if(strType == "BISTABLE")
63  lpNeuron = new BistableNeuron;
64  else
65  {
66  lpNeuron = NULL;
67  if(bThrowError)
68  THROW_PARAM_ERROR(Nl_Err_lInvalidNeuronType, Nl_Err_strInvalidNeuronType, "NeuronType", strType);
69  }
70 
71  return lpNeuron;
72 }
73 catch(CStdErrorInfo oError)
74 {
75  if(lpNeuron) delete lpNeuron;
76  RELAY_ERROR(oError);
77  return NULL;
78 }
79 catch(...)
80 {
81  if(lpNeuron) delete lpNeuron;
82  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
83  return NULL;
84 }
85 }
86 
87 
88 // ************* Neuron Type Conversion functions ******************************
89 
90 
91 // ************* Synapse Type Conversion functions ******************************
92 
93 
94 Synapse *ClassFactory::CreateSynapse(std::string strType, bool bThrowError)
95 {
96  Synapse *lpSynapse=NULL;
97 
98 try
99 {
100  strType = Std_ToUpper(Std_Trim(strType));
101 
102  if(strType == "REGULAR")
103  lpSynapse = new Synapse;
104  else if(strType == "COMPOUND")
105  lpSynapse = new Synapse;
106  else if(strType == "GATED")
107  lpSynapse = new GatedSynapse;
108  else if(strType == "MODULATED")
109  lpSynapse = new ModulatedSynapse;
110  else if(strType == "MODULATENEURONPROP")
111  lpSynapse = new ModulateNeuronPropSynapse;
112  else
113  {
114  lpSynapse = NULL;
115  if(bThrowError)
116  THROW_PARAM_ERROR(Nl_Err_lInvalidSynapseType, Nl_Err_strInvalidSynapseType, "SynapseType", strType);
117  }
118 
119  return lpSynapse;
120 }
121 catch(CStdErrorInfo oError)
122 {
123  if(lpSynapse) delete lpSynapse;
124  RELAY_ERROR(oError);
125  return NULL;
126 }
127 catch(...)
128 {
129  if(lpSynapse) delete lpSynapse;
130  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
131  return NULL;
132 }
133 }
134 
135 // ************* Synapse Type Conversion functions ******************************
136 
137 
138 // ************* DataColumn Type Conversion functions ******************************
139 
140 
141 DataColumn *ClassFactory::CreateDataColumn(std::string strType, bool bThrowError)
142 {
143  DataColumn *lpColumn=NULL;
144 
145 try
146 {
147  strType = Std_ToUpper(Std_Trim(strType));
148 
149  //if(strType == "NEURONDATA")
150  // lpColumn = new NeuronData;
151  //else
152  //{
153  lpColumn = NULL;
154  if(bThrowError)
155  THROW_PARAM_ERROR(Al_Err_lInvalidDataColumnType, Al_Err_strInvalidDataColumnType, "DataColumnType", strType);
156  //}
157 
158  return lpColumn;
159 }
160 catch(CStdErrorInfo oError)
161 {
162  if(lpColumn) delete lpColumn;
163  RELAY_ERROR(oError);
164  return NULL;
165 }
166 catch(...)
167 {
168  if(lpColumn) delete lpColumn;
169  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
170  return NULL;
171 }
172 }
173 
174 // ************* DataColumn Type Conversion functions ******************************
175 
176 
177 // ************* External Stimulus Type Conversion functions ******************************
178 
179 
180 ExternalStimulus *ClassFactory::CreateExternalStimulus(std::string strType, bool bThrowError)
181 {
182  ExternalStimulus *lpStimulus=NULL;
183 
184 try
185 {
186  strType = Std_ToUpper(Std_Trim(strType));
187 
188  //if(strType == "CURRENTINJECTION")
189  // lpStimulus = new CurrentInjection;
190  if(strType == "CURRENT")
192  else if(strType == "VOLTAGECLAMP")
194  else
195  {
196  lpStimulus = NULL;
197  if(bThrowError)
198  THROW_PARAM_ERROR(Nl_Err_lInvalidExternalStimulusType, Nl_Err_strInvalidExternalStimulusType, "ExternalStimulusType", strType);
199  }
200 
201  return lpStimulus;
202 }
203 catch(CStdErrorInfo oError)
204 {
205  if(lpStimulus) delete lpStimulus;
206  RELAY_ERROR(oError);
207  return NULL;
208 }
209 catch(...)
210 {
211  if(lpStimulus) delete lpStimulus;
212  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
213  return NULL;
214 }
215 }
216 
217 // ************* External Stimulus Type Conversion functions ******************************
218 
219 
220 // ************* External Neural Module Conversion functions ******************************
221 
222 
223 NeuralModule *ClassFactory::CreateNeuralModule(std::string strType, bool bThrowError)
224 {
225  NeuralModule *lpModule=NULL;
226 
227 try
228 {
229  strType = Std_ToUpper(Std_Trim(strType));
230 
231  if(strType == "FIRINGRATESIMMODULE")
232  lpModule = new FiringRateModule;
233  else
234  {
235  lpModule = NULL;
236  if(bThrowError)
237  THROW_PARAM_ERROR(Al_Err_lInvalidNeuralModuleType, Al_Err_strInvalidNeuralModuleType, "NeuralModule", strType);
238  }
239 
240  return lpModule;
241 }
242 catch(CStdErrorInfo oError)
243 {
244  if(lpModule) delete lpModule;
245  RELAY_ERROR(oError);
246  return NULL;
247 }
248 catch(...)
249 {
250  if(lpModule) delete lpModule;
251  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
252  return NULL;
253 }
254 }
255 
256 // ************* Neural Module Type Conversion functions ******************************
257 
258 
259 // ************* IStdClassFactory functions ******************************
260 
261 CStdSerialize *ClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
262 {
263  CStdSerialize *lpObject=NULL;
264 
265  strClassType = Std_ToUpper(Std_Trim(strClassType));
266 
267  if(strClassType == "DATACOLUMN")
268  lpObject = CreateDataColumn(strObjectType, bThrowError);
269  else if(strClassType == "EXTERNALSTIMULUS")
270  lpObject = CreateExternalStimulus(strObjectType, bThrowError);
271  else if(strClassType == "NEURON")
272  lpObject = CreateNeuron(strObjectType, bThrowError);
273  else if(strClassType == "SYNAPSE")
274  lpObject = CreateSynapse(strObjectType, bThrowError);
275  else if(strClassType == "NEURALMODULE")
276  lpObject = CreateNeuralModule(strObjectType, bThrowError);
277  else
278  {
279  lpObject = NULL;
280  if(bThrowError)
281  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
282  }
283 
284  return lpObject;
285 }
286 
287 // ************* IStdClassFactory functions ******************************
288 
289 } //FiringRateSim
Firing rate neural module.
Declares the gated synapse class.
Random firing rate neuron.
Definition: RandomNeuron.h:24
Gated firing rate synapse.
Definition: GatedSynapse.h:25
Declares the random neuron class.
Bistable firing rate neuron.
Declares the bistable neuron class.
Modulated firing rate synapse.
virtual Neuron * CreateNeuron(std::string strType, bool bThrowError=true)
Creates a neuron.
virtual ExternalStimulus * CreateExternalStimulus(std::string strType, bool bThrowError=true)
Creates an external stimulus.
std::string Std_Trim(std::string strVal)
Trims a string.
virtual Synapse * CreateSynapse(std::string strType, bool bThrowError=true)
Creates a synapse.
Declares the modulated synapse class.
Firing Rate Neuron model.
virtual DataColumn * CreateDataColumn(std::string strType, bool bThrowError=true)
Creates a data column.
Current stimulus for neural items.
Declares the synapse class.
Declares the firing rate module class.
Declares the pacemaker neuron class.
Firing rate synapse model for modulating neuron properties.
Declares the tonic neuron class.
Contains the classes for a firing rate neural model.
Firing rate synapse model.
Definition: Synapse.h:29
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
Tonic firing rate neuron.
Definition: TonicNeuron.h:21
virtual NeuralModule * CreateNeuralModule(std::string strType, bool bThrowError=true)
Creates a neural module.