AnimatLab  2
Test
CsClassFactory.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 #include "CsNeuralModule.h"
10 #include "CsNeuronGroup.h"
11 #include "CsSpikeGeneratorGroup.h"
12 #include "CsSynapseGroup.h"
13 #include "CsSynapseOneToOne.h"
14 #include "CsSynapseFull.h"
15 #include "CsSynapseRandom.h"
16 #include "CsSynapseIndividual.h"
18 #include "CsFiringRateStimulus.h"
19 #include "CsNeuronDataColumn.h"
20 #include "CsAdapter.h"
21 #include "CsClassFactory.h"
22 
23 namespace AnimatCarlSim
24 {
25 
33 {
34 
35 }
36 
44 {
45 
46 }
47 
48 Node *CsClassFactory::CreateNeuron(std::string strType, bool bThrowError)
49 {
50  Node *lpNeuron=NULL;
51 
52 try
53 {
54  strType = Std_ToUpper(Std_Trim(strType));
55 
56  if(strType == "NEURONGROUP")
57  lpNeuron = new CsNeuronGroup;
58  else if(strType == "SPIKEGENERATORGROUP")
59  lpNeuron = new CsSpikeGeneratorGroup;
60  else
61  {
62  lpNeuron = NULL;
63  if(bThrowError)
64  THROW_PARAM_ERROR(Cs_Err_lInvalidNeuronType, Cs_Err_strInvalidNeuronType, "NeuronType", strType);
65  }
66 
67  return lpNeuron;
68 }
69 catch(CStdErrorInfo oError)
70 {
71  if(lpNeuron) delete lpNeuron;
72  RELAY_ERROR(oError);
73  return NULL;
74 }
75 catch(...)
76 {
77  if(lpNeuron) delete lpNeuron;
78  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
79  return NULL;
80 }
81 }
82 
83 
84 // ************* Neuron Type Conversion functions ******************************
85 
86 
87 // ************* Synapse Type Conversion functions ******************************
88 
89 
90 AnimatSim::Link *CsClassFactory::CreateSynapse(std::string strType, bool bThrowError)
91 {
92  AnimatSim::Link *lpSynapse=NULL;
93 
94 try
95 {
96  strType = Std_ToUpper(Std_Trim(strType));
97 
98  if(strType == "ONETOONESYNAPSE")
99  lpSynapse = new CsSynapseOneToOne;
100  else if(strType == "FULLSYNAPSE")
101  lpSynapse = new CsSynapseFull;
102  else if(strType == "RANDOMSYNAPSE")
103  lpSynapse = new CsSynapseRandom;
104  else if(strType == "INDIVIDUALSYNAPSE")
105  lpSynapse = new CsSynapseIndividual;
106  else if(strType == "SPIKINGCURRENTSYNAPSE")
107  lpSynapse = new CsSpikingCurrentSynapse;
108  else
109  {
110  lpSynapse = NULL;
111  if(bThrowError)
112  THROW_PARAM_ERROR(Cs_Err_lInvalidSynapseType, Cs_Err_strInvalidSynapseType, "SynapseType", strType);
113  }
114 
115  return lpSynapse;
116 }
117 catch(CStdErrorInfo oError)
118 {
119  if(lpSynapse) delete lpSynapse;
120  RELAY_ERROR(oError);
121  return NULL;
122 }
123 catch(...)
124 {
125  if(lpSynapse) delete lpSynapse;
126  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
127  return NULL;
128 }
129 }
130 
131 // ************* Synapse Type Conversion functions ******************************
132 
133 
134 // ************* External Neural Module Conversion functions ******************************
135 
136 
137 NeuralModule *CsClassFactory::CreateNeuralModule(std::string strType, bool bThrowError)
138 {
139  NeuralModule *lpModule=NULL;
140 
141 try
142 {
143  strType = Std_ToUpper(Std_Trim(strType));
144 
145  if(strType == "CARLSIMNEURALMODULE")
146  lpModule = new CsNeuralModule;
147  else
148  {
149  lpModule = NULL;
150  if(bThrowError)
151  THROW_PARAM_ERROR(Al_Err_lInvalidNeuralModuleType, Al_Err_strInvalidNeuralModuleType, "NeuralModule", strType);
152  }
153 
154  return lpModule;
155 }
156 catch(CStdErrorInfo oError)
157 {
158  if(lpModule) delete lpModule;
159  RELAY_ERROR(oError);
160  return NULL;
161 }
162 catch(...)
163 {
164  if(lpModule) delete lpModule;
165  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
166  return NULL;
167 }
168 }
169 
170 // ************* Neural Module Type Conversion functions ******************************
171 
172 
173 // ************* External Stimulus Type Conversion functions ******************************
174 
175 ExternalStimulus *CsClassFactory::CreateExternalStimulus(std::string strType, bool bThrowError)
176 {
177  ExternalStimulus *lpStimulus=NULL;
178 
179 try
180 {
181  strType = Std_ToUpper(Std_Trim(strType));
182 
183  if(strType == "FIRINGRATE")
184  lpStimulus = new CsFiringRateStimulus;
185  else
186  {
187  lpStimulus = NULL;
188  if(bThrowError)
189  THROW_PARAM_ERROR(Al_Err_lInvalidExternalStimulusType, Al_Err_strInvalidExternalStimulusType, "ExternalStimulusType", strType);
190  }
191 
192  return lpStimulus;
193 }
194 catch(CStdErrorInfo oError)
195 {
196  if(lpStimulus) delete lpStimulus;
197  RELAY_ERROR(oError);
198  return NULL;
199 }
200 catch(...)
201 {
202  if(lpStimulus) delete lpStimulus;
203  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
204  return NULL;
205 }
206 }
207 
208 // ************* External Stimulus Type Conversion functions ******************************
209 
210 
211 // ************* DataColumn Type Conversion functions ******************************
212 
213 DataColumn *CsClassFactory::CreateDataColumn(std::string strType, bool bThrowError)
214 {
215  DataColumn *lpColumn=NULL;
216 
217 try
218 {
219  strType = Std_ToUpper(Std_Trim(strType));
220 
221  if(strType == "NEURONDATACOLUMN")
222  lpColumn = new CsNeuronDataColumn;
223  else
224  {
225  lpColumn = NULL;
226  if(bThrowError)
227  THROW_PARAM_ERROR(Al_Err_lInvalidDataColumnType, Al_Err_strInvalidDataColumnType, "DataColumnType", strType);
228  }
229 
230  return lpColumn;
231 }
232 catch(CStdErrorInfo oError)
233 {
234  if(lpColumn) delete lpColumn;
235  RELAY_ERROR(oError);
236  return NULL;
237 }
238 catch(...)
239 {
240  if(lpColumn) delete lpColumn;
241  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
242  return NULL;
243 }
244 }
245 
246 // ************* DataColumn Type Conversion functions ******************************
247 
248 
249 // ************* Adapter Type Conversion functions ******************************
250 
251 Adapter *CsClassFactory::CreateAdapter(std::string strType, bool bThrowError)
252 {
253  Adapter *lpAdapter=NULL;
254 
255 try
256 {
257  strType = Std_ToUpper(Std_Trim(strType));
258 
259  if(strType == "NODETONODE")
260  lpAdapter = new CsAdapter;
261  else if(strType == "PHYSICALTONODE")
262  lpAdapter = new CsAdapter;
263  else
264  {
265  lpAdapter = NULL;
266  if(bThrowError)
267  THROW_PARAM_ERROR(Al_Err_lInvalidAdapterType, Al_Err_strInvalidAdapterType, "AdapterType", strType);
268  }
269 
270  return lpAdapter;
271 }
272 catch(CStdErrorInfo oError)
273 {
274  if(lpAdapter) delete lpAdapter;
275  RELAY_ERROR(oError);
276  return NULL;
277 }
278 catch(...)
279 {
280  if(lpAdapter) delete lpAdapter;
281  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
282  return NULL;
283 }
284 }
285 
286 // ************* Adpater Type Conversion functions ******************************
287 
288 
289 
290 // ************* IStdCsClassFactory functions ******************************
291 
292 CStdSerialize *CsClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
293 {
294  CStdSerialize *lpObject=NULL;
295 
296  strClassType = Std_ToUpper(Std_Trim(strClassType));
297 
298  if(strClassType == "NEURON")
299  lpObject = CreateNeuron(strObjectType, bThrowError);
300  else if(strClassType == "SYNAPSE")
301  lpObject = CreateSynapse(strObjectType, bThrowError);
302  else if(strClassType == "NEURALMODULE")
303  lpObject = CreateNeuralModule(strObjectType, bThrowError);
304  else if(strClassType == "EXTERNALSTIMULUS")
305  lpObject = CreateExternalStimulus(strObjectType, bThrowError);
306  else if(strClassType == "DATACOLUMN")
307  lpObject = CreateDataColumn(strObjectType, bThrowError);
308  else if(strClassType == "ADAPTER")
309  lpObject = CreateAdapter(strObjectType, bThrowError);
310  else
311  {
312  lpObject = NULL;
313  if(bThrowError)
314  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
315  }
316 
317  return lpObject;
318 }
319 
320 // ************* IStdCsClassFactory functions ******************************
321 
322 } //AnimatCarlSim
323 
324 #ifdef WIN32
325 extern "C" __declspec(dllexport) IStdClassFactory* __cdecl GetStdClassFactory()
326 #else
327 extern "C" IStdClassFactory* GetStdClassFactory()
328 #endif
329 {
330  IStdClassFactory *lpFactory = new CsClassFactory;
331  return lpFactory;
332 }
Contains the classes for a firing rate neural model.
Definition: CsAdapter.cpp:14
virtual ExternalStimulus * CreateExternalStimulus(std::string strType, bool bThrowError=true)
Creates an external stimuli.
Declares the CsNeuronGroup class.
virtual ~CsClassFactory()
Destructor.
Firing rate synapse model.
Firing rate synapse model.
Definition: CsSynapseFull.h:22
std::string Std_Trim(std::string strVal)
Trims a string.
Firing rate neural module.
virtual Node * CreateNeuron(std::string strType, bool bThrowError=true)
Creates a neuron.
Declares the current stimulus class.
Declares the synapse class.
Current stimulus for neural items.
Firing Rate Neuron model.
Definition: CsNeuronGroup.h:28
Declares the synapse class.
Firing rate synapse model.
Declares the current stimulus class.
Firing rate neural module class factory.
Carlsim Data column class.
virtual NeuralModule * CreateNeuralModule(std::string strType, bool bThrowError=true)
Creates a neural module.
Firing rate synapse model.
CsClassFactory()
Default constructor.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
virtual AnimatSim::Link * CreateSynapse(std::string strType, bool bThrowError=true)
Creates a synapse.
Declares the data column class.
Current stimulus for neural items.
Definition: CsAdapter.h:20