You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.4 KiB
C

2 years ago
#pragma once
class CMotionControllerBase;
class CMtrProfile;
#ifdef BUILD_IODLL
#define IODLLCLASS __declspec(dllexport)
2 years ago
#else
#define IODLLCLASS __declspec(dllimport)
2 years ago
#endif
class IODLLCLASS CAbstractMotionControllerFactory
{
private:
int m_cardType{ -1 };
std::string m_cardName;
2 years ago
public:
CAbstractMotionControllerFactory(int cardType, const std::string& m_cardName);
2 years ago
virtual ~CAbstractMotionControllerFactory();
virtual CMotionControllerBase* CreateMotionController(int index) = 0;
int GetCardType() const;
const std::string& GetCardName() const;
2 years ago
};
/**
* @class CMotionControllerFactory
*
* @brief The CMotionControllerFactory is used to create all MotionControllers.
*
*/
class IODLLCLASS CMotionControllerFactory
{
private:
CMotionControllerFactory(void);
2 years ago
public:
virtual ~CMotionControllerFactory(void);
static CMotionControllerFactory& Instance();
void AddFactory(CAbstractMotionControllerFactory* pFactory);
void RemoveFactory(CAbstractMotionControllerFactory* pFactory);
CMotionControllerBase* CreateMotionController(int index, const std::string& cardName);
CMotionControllerBase* CreateMotionController(int index, int cardType);
int GetCardType(const std::string& cardName);
2 years ago
};
/**
* @def REGISTER_MOTIONCONTROLLER_FACTORY(mType, name, MotionController_class)
*
* @brief A macro that defines MotionController factory.
*
* The factories are registered to the CMotionControllerFactory which uses them to create MotionControllers.
* To define a new type of MotionController it needs to derive from CMotionControllerBase and be registered.
*
* Example usage:
*
* \code{.cpp}
* REGISTER_MOTIONCONTROLLER_FACTORY(PCI_8164_ADLINK, "8164", CMotionController_8164)
* \endcode
*
* @param mType The MotionController type.
* @param MotionController_class The class of the MotionController that the factory creates.
*/
#define REGISTER_MOTIONCONTROLLER_FACTORY(mType, name, MotionController_class) \
class Factory##MotionController_class : public CAbstractMotionControllerFactory \
{ \
public: \
Factory##MotionController_class() : CAbstractMotionControllerFactory(mType, name) {} \
CMotionControllerBase* CreateMotionController(int index) \
{ \
CMotionControllerBase* ptr = new MotionController_class(index); \
ptr->SetCardInfo(mType, name); \
return ptr; \
} \
}; \
static Factory##MotionController_class StaticFactory##MotionController_class; \
CAbstractMotionControllerFactory* GetFactory##MotionController_class() { return &StaticFactory##MotionController_class; }