AnimatLab  2
Test
PyClassFactory.cpp
1 // RbClassFactory.cpp: implementation of the RbClassFactory class.
2 //
4 
5 #include "StdAfx.h"
6 #include "PyClassFactory.h"
7 #include "ScriptProcessorPy.h"
8 
9 #ifdef _WINDOWS
10  extern "C" __declspec(dllexport) IStdClassFactory* __cdecl GetStdClassFactory()
11 #else
12  extern "C" IStdClassFactory* GetStdClassFactory()
13 #endif
14 {
16  return lpFactory;
17 }
18 
19 
20 namespace AnimatSimPy
21 {
22 
24 // Construction/Destruction
26 
27 PyClassFactory::PyClassFactory()
28 {
29 
30 }
31 
32 PyClassFactory::~PyClassFactory()
33 {
34 
35 }
36 
37 // ************* Script Processor Type Conversion functions ******************************
38 
39 ScriptProcessor *PyClassFactory::CreateScriptProcessor(std::string strType, bool bThrowError)
40 {
41  ScriptProcessor *lpScript=NULL;
42 
43 try
44 {
45  strType = Std_ToUpper(Std_Trim(strType));
46 
47  if(strType == "SCRIPTPROCESSORPY")
48  lpScript = new ScriptProcessorPy();
49  else
50  {
51  lpScript = NULL;
52  if(bThrowError)
53  THROW_PARAM_ERROR(Al_Err_lInvalidPartType, Al_Err_strInvalidPartType, "PartType", strType);
54  }
55 
56  return lpScript;
57 }
58 catch(CStdErrorInfo oError)
59 {
60  if(lpScript) delete lpScript;
61  RELAY_ERROR(oError);
62  return NULL;
63 }
64 catch(...)
65 {
66  if(lpScript) delete lpScript;
67  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
68  return NULL;
69 }
70 }
71 
72 // ************* Script Processor Type Conversion functions ******************************
73 
74 // ************* IStdClassFactory functions ******************************
75 
76 CStdSerialize *PyClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
77 {
78  CStdSerialize *lpObject=NULL;
79 
80  strClassType = Std_ToUpper(Std_Trim(strClassType));
81 
82  if(strClassType == "SCRIPTPROCESSOR")
83  lpObject = CreateScriptProcessor(strObjectType, bThrowError);
84  else
85  {
86  lpObject = NULL;
87  if(bThrowError)
88  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
89  }
90 
91  return lpObject;
92 }
93 // ************* IStdClassFactory functions ******************************
94 
95 
96 
97 } //RoboticsAnimatSim
std::string Std_Trim(std::string strVal)
Trims a string.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.