AnimatLab  2
Test
IntegrateFireSim/ClassFactory.cpp
1 
7 #include "stdafx.h"
8 #include "IonChannel.h"
9 #include "SynapseType.h"
10 #include "Connexion.h"
11 #include "CaActivation.h"
12 #include "Neuron.h"
13 #include "ElectricalSynapse.h"
15 #include "SpikingChemicalSynapse.h"
16 #include "IntegrateFireModule.h"
17 #include "IonChannelSigmoid.h"
18 #include "ClassFactory.h"
19 
20 namespace IntegrateFireSim
21 {
22 
30 {
31 
32 }
33 
41 {
42 
43 }
44 
45 
46 // ************* External Stimulus Type Conversion functions ******************************
47 
48 
49 ExternalStimulus *ClassFactory::CreateExternalStimulus(std::string strType, bool bThrowError)
50 {
51  ExternalStimulus *lpStimulus=NULL;
52 
53 try
54 {
55  strType = Std_ToUpper(Std_Trim(strType));
56 
57  if(strType == "CURRENT")
59  else if(strType == "VOLTAGECLAMP")
61  else
62  {
63  lpStimulus = NULL;
64  if(bThrowError)
65  THROW_PARAM_ERROR(Al_Err_lInvalidExternalStimulusType, Al_Err_strInvalidExternalStimulusType, "ExternalStimulusType", strType);
66  }
67 
68  return lpStimulus;
69 }
70 catch(CStdErrorInfo oError)
71 {
72  if(lpStimulus) delete lpStimulus;
73  RELAY_ERROR(oError);
74  return NULL;
75 }
76 catch(...)
77 {
78  if(lpStimulus) delete lpStimulus;
79  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
80  return NULL;
81 }
82 }
83 
84 // ************* External Stimulus Type Conversion functions ******************************
85 
86 
87 // ************* External Neural Module Conversion functions ******************************
88 
89 
90 NeuralModule *ClassFactory::CreateNeuralModule(std::string strType, bool bThrowError)
91 {
92  NeuralModule *lpModule=NULL;
93 
94 try
95 {
96  strType = Std_ToUpper(Std_Trim(strType));
97 
98  if(strType == "INTEGRATEFIRESIMMODULE")
99  lpModule = new IntegrateFireNeuralModule;
100  else
101  {
102  lpModule = NULL;
103  if(bThrowError)
104  THROW_PARAM_ERROR(Al_Err_lInvalidNeuralModuleType, Al_Err_strInvalidNeuralModuleType, "NeuralModule", strType);
105  }
106 
107  return lpModule;
108 }
109 catch(CStdErrorInfo oError)
110 {
111  if(lpModule) delete lpModule;
112  RELAY_ERROR(oError);
113  return NULL;
114 }
115 catch(...)
116 {
117  if(lpModule) delete lpModule;
118  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
119  return NULL;
120 }
121 }
122 
123 
124 // ************* Neural Module Type Conversion functions ******************************
125 
126 
127 // ************* DataColumn Type Conversion functions ******************************
128 
129 
130 DataColumn *ClassFactory::CreateDataColumn(std::string strType, bool bThrowError)
131 {
132  DataColumn *lpColumn=NULL;
133 
134 try
135 {
136  strType = Std_ToUpper(Std_Trim(strType));
137 
138  //if(strType == "NEURONDATA")
139  // lpColumn = new NeuronData;
140  //else if(strType == "IONCHANNELDATA")
141  // lpColumn = new ChannelData;
142  //else
143  //{
144  lpColumn = NULL;
145  if(bThrowError)
146  THROW_PARAM_ERROR(Al_Err_lInvalidDataColumnType, Al_Err_strInvalidDataColumnType, "DataColumnType", strType);
147  //}
148 
149  return lpColumn;
150 }
151 catch(CStdErrorInfo oError)
152 {
153  if(lpColumn) delete lpColumn;
154  RELAY_ERROR(oError);
155  return NULL;
156 }
157 catch(...)
158 {
159  if(lpColumn) delete lpColumn;
160  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
161  return NULL;
162 }
163 }
164 
165 
166 // ************* DataColumn Type Conversion functions ******************************
167 
168 
169 // ************* Gain Type Conversion functions ******************************
170 
171 
172 Gain *ClassFactory::CreateGain(std::string strType, bool bThrowError)
173 {
174  Gain *lpGain=NULL;
175 
176 try
177 {
178  strType = Std_ToUpper(Std_Trim(strType));
179 
180  if(strType == "IONCHANNELSIGMOID")
182  else
183  {
184  lpGain = NULL;
185  if(bThrowError)
186  THROW_PARAM_ERROR(Al_Err_lInvalidGainType, Al_Err_strInvalidGainType, "GainType", strType);
187  }
188 
189  return lpGain;
190 }
191 catch(CStdErrorInfo oError)
192 {
193  if(lpGain) delete lpGain;
194  RELAY_ERROR(oError);
195  return NULL;
196 }
197 catch(...)
198 {
199  if(lpGain) delete lpGain;
200  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
201  return NULL;
202 }
203 }
204 
205 
206 // ************* Gain Conversion functions ******************************
207 
208 
209 // ************* Neuron Type Conversion functions ******************************
210 
211 
212 Neuron *ClassFactory::CreateNeuron(std::string strType, bool bThrowError)
213 {
214  Neuron *lpNeuron=NULL;
215 
216 try
217 {
218  strType = Std_ToUpper(Std_Trim(strType));
219 
220  if(strType == "NEURON")
221  lpNeuron = new Neuron;
222  else
223  {
224  lpNeuron = NULL;
225  if(bThrowError)
226  THROW_PARAM_ERROR(Rn_Err_lInvalidNeuronType, Rn_Err_strInvalidNeuronType, "NeuronType", strType);
227  }
228 
229  return lpNeuron;
230 }
231 catch(CStdErrorInfo oError)
232 {
233  if(lpNeuron) delete lpNeuron;
234  RELAY_ERROR(oError);
235  return NULL;
236 }
237 catch(...)
238 {
239  if(lpNeuron) delete lpNeuron;
240  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
241  return NULL;
242 }
243 }
244 
245 
246 // ************* Neuron Type Conversion functions ******************************
247 
248 
249 // ************* Synapse Type Conversion functions ******************************
250 
251 
252 Connexion *ClassFactory::CreateSynapse(std::string strType, bool bThrowError)
253 {
254  Connexion *lpSynapse=NULL;
255 
256 try
257 {
258  strType = Std_ToUpper(Std_Trim(strType));
259 
260  if(strType == "SYNAPSE")
261  lpSynapse = new Connexion;
262  else
263  {
264  lpSynapse = NULL;
265  if(bThrowError)
266  THROW_PARAM_ERROR(Rn_Err_lInvalidSynapseType, Rn_Err_strInvalidSynapseType, "SynapseType", strType);
267  }
268 
269  return lpSynapse;
270 }
271 catch(CStdErrorInfo oError)
272 {
273  if(lpSynapse) delete lpSynapse;
274  RELAY_ERROR(oError);
275  return NULL;
276 }
277 catch(...)
278 {
279  if(lpSynapse) delete lpSynapse;
280  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
281  return NULL;
282 }
283 }
284 
285 // ************* Synapse Type Conversion functions ******************************
286 
287 
288 // ************* Synapse Type Conversion functions ******************************
289 
290 
291 SynapseType *ClassFactory::CreateSynapseType(std::string strType, bool bThrowError)
292 {
293  SynapseType *lpSynapseType=NULL;
294 
295 try
296 {
297  strType = Std_ToUpper(Std_Trim(strType));
298 
299  if(strType == "SPIKINGCHEMICAL")
300  lpSynapseType = new SpikingChemicalSynapse;
301  else if(strType == "NONSPIKINGCHEMICAL")
302  lpSynapseType = new NonSpikingChemicalSynapse;
303  else if(strType == "ELECTRICAL")
304  lpSynapseType = new ElectricalSynapse;
305  else
306  {
307  lpSynapseType = NULL;
308  if(bThrowError)
309  THROW_PARAM_ERROR(Rn_Err_lInvalidSynapseType, Rn_Err_strInvalidSynapseType, "SynapseType", strType);
310  }
311 
312  return lpSynapseType;
313 }
314 catch(CStdErrorInfo oError)
315 {
316  if(lpSynapseType) delete lpSynapseType;
317  RELAY_ERROR(oError);
318  return NULL;
319 }
320 catch(...)
321 {
322  if(lpSynapseType) delete lpSynapseType;
323  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
324  return NULL;
325 }
326 }
327 
328 // ************* Synapse Type Conversion functions ******************************
329 
330 
331 // ************* Ion Channel Conversion functions ******************************
332 
333 
334 IonChannel *ClassFactory::CreateIonChannel(std::string strType, bool bThrowError)
335 {
336  IonChannel *lpChannel=NULL;
337 
338 try
339 {
340  strType = Std_ToUpper(Std_Trim(strType));
341 
342  if(strType == "IONCHANNEL")
343  lpChannel = new IonChannel;
344  else
345  {
346  lpChannel = NULL;
347  if(bThrowError)
348  THROW_PARAM_ERROR(Rn_Err_lInvalidIonChannelType, Rn_Err_strInvalidIonChannelType, "IonChannel", strType);
349  }
350 
351  return lpChannel;
352 }
353 catch(CStdErrorInfo oError)
354 {
355  if(lpChannel) delete lpChannel;
356  RELAY_ERROR(oError);
357  return NULL;
358 }
359 catch(...)
360 {
361  if(lpChannel) delete lpChannel;
362  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
363  return NULL;
364 }
365 }
366 
367 // ************* Ion Channel Conversion functions ******************************
368 
369 
370 // ************* IStdClassFactory functions ******************************
371 
372 CStdSerialize *ClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
373 {
374  CStdSerialize *lpObject=NULL;
375 
376  strClassType = Std_ToUpper(Std_Trim(strClassType));
377 
378  if(strClassType == "EXTERNALSTIMULUS")
379  lpObject = CreateExternalStimulus(strObjectType, bThrowError);
380  else if(strClassType == "NEURALMODULE")
381  lpObject = CreateNeuralModule(strObjectType, bThrowError);
382  else if(strClassType == "DATACOLUMN")
383  lpObject = CreateDataColumn(strObjectType, bThrowError);
384  else if(strClassType == "GAIN")
385  lpObject = CreateGain(strObjectType, bThrowError);
386  else if(strClassType == "NEURON")
387  lpObject = CreateNeuron(strObjectType, bThrowError);
388  else if(strClassType == "SYNAPSE")
389  lpObject = CreateSynapse(strObjectType, bThrowError);
390  else if(strClassType == "SYNAPSETYPE")
391  lpObject = CreateSynapseType(strObjectType, bThrowError);
392  else if(strClassType == "IONCHANNEL")
393  lpObject = CreateIonChannel(strObjectType, bThrowError);
394  else
395  {
396  lpObject = NULL;
397  if(bThrowError)
398  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
399  }
400 
401  return lpObject;
402 }
403 
404 // ************* IStdClassFactory functions ******************************
405 
406 } //IntegrateFireSim
Declares the integrate fire module class.
Integrate and fire neural module.
Declares the connexion class.
Integrate and fire neuron model.
virtual ExternalStimulus * CreateExternalStimulus(std::string strType, bool bThrowError=true)
Creates an external stimulus.
virtual IonChannel * CreateIonChannel(std::string strType, bool bThrowError=true)
Creates an ion channel.
virtual SynapseType * CreateSynapseType(std::string strType, bool bThrowError=true)
Creates a synapse type.
Declares the spiking chemical synapse class.
std::string Std_Trim(std::string strVal)
Trims a string.
Declares the ca activation class.
virtual Connexion * CreateSynapse(std::string strType, bool bThrowError=true)
Creates a synapse.
Current stimulus for neural items.
Synapse type base class.
Definition: SynapseType.h:22
Declares the synapse type class.
virtual Neuron * CreateNeuron(std::string strType, bool bThrowError=true)
Creates a neuron.
virtual DataColumn * CreateDataColumn(std::string strType, bool bThrowError=true)
Creates a data column.
virtual NeuralModule * CreateNeuralModule(std::string strType, bool bThrowError=true)
Creates a neural module.
Declares the electrical synapse class.
virtual Gain * CreateGain(std::string strType, bool bThrowError=true)
Creates a gain.
Declares the ion channel sigmoid class.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
Contains all of the classes to implement a basic integrate and fire neural model. ...
Declares the non spiking chemical synapse class.
Declares the neuron class.