AnimatLab  2
Test
HiClassFactory.cpp
1 // HiClassFactory.cpp: implementation of the HiClassFactory class.
2 //
4 
5 #include "StdAfx.h"
6 #include "HiClassFactory.h"
7 
8 #include "HiSpike2.h"
9 #include "HiC884Controller.h"
10 #include "HiM110Actuator.h"
11 
12 #ifdef _WINDOWS
13  extern "C" __declspec(dllexport) IStdClassFactory* __cdecl GetStdClassFactory()
14 #else
15  extern "C" IStdClassFactory* GetStdClassFactory()
16 #endif
17 {
18  IStdClassFactory *lpFactory = new HiClassFactory;
19  return lpFactory;
20 }
21 
22 namespace HybridInterfaceSim
23 {
24 
26 // Construction/Destruction
28 
29 HiClassFactory::HiClassFactory()
30 {
31 
32 }
33 
34 HiClassFactory::~HiClassFactory()
35 {
36 
37 }
38 
39 
40 // ************* Robot IO Control Conversion functions ******************************
41 
42 RobotIOControl *HiClassFactory::CreateRobotIOControl(std::string strType, bool bThrowError)
43 {
44  RobotIOControl *lpControl=NULL;
45 
46 try
47 {
48  strType = Std_ToUpper(Std_Trim(strType));
49 
50  if(strType == "SPIKE2")
51  {
52  lpControl = new HiSpike2;
53  }
54  else if(strType == "C884CONTROLLER")
55  {
56  lpControl = new HiC884Controller;
57  }
58  else
59  {
60  lpControl = NULL;
61  if(bThrowError)
62  THROW_PARAM_ERROR(Al_Err_lInvalidRobotIOControlType, Al_Err_strInvalidRobotIOControlType, "RobotartIOControl", strType);
63  }
64 
65  return lpControl;
66 }
67 catch(CStdErrorInfo oError)
68 {
69  if(lpControl) delete lpControl;
70  RELAY_ERROR(oError);
71  return NULL;
72 }
73 catch(...)
74 {
75  if(lpControl) delete lpControl;
76  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
77  return NULL;
78 }
79 }
80 
81 
82 // ************* Robot IO Control Conversion functions ******************************
83 
84 
85 // ************* Robot Part Interface Conversion functions ******************************
86 
87 RobotPartInterface *HiClassFactory::CreateRobotPartInterface(std::string strType, bool bThrowError)
88 {
89  RobotPartInterface *lpInterface=NULL;
90 
91 try
92 {
93  strType = Std_ToUpper(Std_Trim(strType));
94 
95  if(strType == "M110ACTUATOR")
96  {
97  lpInterface = new HiM110Actuator;
98  }
99  else
100  {
101  lpInterface = NULL;
102  if(bThrowError)
103  THROW_PARAM_ERROR(Al_Err_lInvalidRobotPartInterfaceType, Al_Err_strInvalidRobotPartInterfaceType, "RobotartInterface", strType);
104  }
105 
106  return lpInterface;
107 }
108 catch(CStdErrorInfo oError)
109 {
110  if(lpInterface) delete lpInterface;
111  RELAY_ERROR(oError);
112  return NULL;
113 }
114 catch(...)
115 {
116  if(lpInterface) delete lpInterface;
117  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
118  return NULL;
119 }
120 }
121 
122 
123 // ************* Robot Part Interface Type Conversion functions ******************************
124 
125 
126 
127 // ************* IStdClassFactory functions ******************************
128 
129 CStdSerialize *HiClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
130 {
131  CStdSerialize *lpObject=NULL;
132 
133  strClassType = Std_ToUpper(Std_Trim(strClassType));
134 
135  if(strClassType == "ROBOTIOCONTROL")
136  lpObject = CreateRobotIOControl(strObjectType, bThrowError);
137  else if(strClassType == "ROBOTPARTINTERFACE")
138  lpObject = CreateRobotPartInterface(strObjectType, bThrowError);
139  else
140  {
141  lpObject = NULL;
142  if(bThrowError)
143  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
144  }
145 
146  return lpObject;
147 }
148 // ************* IStdClassFactory functions ******************************
149 
150 
151 } //HybridInterfaceSim
std::string Std_Trim(std::string strVal)
Trims a string.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.