I have two different object CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING. These two classes both inherit four other classes that are similar but not identical. The functions names and parameter of the different inherited classes are identical but the code is not.
I am have difficultly finding a way to create a generic class object pointer and then useing the new operator. I am finding it difficult because, i don't have a way to create a generic base class because of the four other objects inherited(CLX_LENZE_LIFT_INVERTOR,etc.) I was thinking may i could do something with templates or null pointer( void *inverter; inverter = new CLX_MITSUBISHI_POLLING() Unfortunately, the null pointer did not work. Any recommendations would be greatly a appreciated.
my goal is to be able to do this!
CLX_POLLING *Invertors;
if( inverter_type == MITSUBISHI )
Invertors = new CLX_MITSUBISHI_POLLING;
else
Invertors = new CLX_LENZE_POLLING;
My CLX_MITSUBISHI_POLLING clases header is below the CLX_LENZE_POLLING is identical except for the LENZE is used instead of MITSUBISHI. the inherited class all have different code except ClxThread.
class CLX_MITSUBISHI_POLLING :
public ClxThread,
public CLX_MITSUBISHI_PITCH_INVERTOR,
public CLX_MITSUBISHI_ROLL_INVERTOR,
public CLX_MITSUBISHI_LIFT_INVERTOR,
public CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR
{
public:
CLX_MITSUBISHI_POLLING(void);
~CLX_MITSUBISHI_POLLING(void);
bool mStartPolling(void){ return CreateNewThread(); }
private: // Serial Port Specific Commands and Data
unsigned short m_BaudRate;
int m_CommPort;
int m_SerialPortHandlePolling;
public:
bool mvInitComm( int comm_port, int baud_rate );
bool mvCloseComm( void );
bool mvRestartComm( void );
void mvSetBaudRate(int value);
unsigned short mvGetBaudRate(void);
void mvSetCommPort(int value);
unsigned short mvGetCommPort(void);
int mvGetSerialPortHandle( void );
void mvSetSerialPortHandle( int );
private:
int mvPutByte( char txdata );
int mvPutPacket( int lenght, char txdata[] );
int mvGetBytes( void );
int mvFlushRxBuf( void );
int mvFlushTxBuf( void );
int mvGetRxBuf(void);
int mvGetTxBuf(void);
bool mvIsOverrunErrors(void);
bool mvIsParityErrors(void);
bool mvIsRxBufferEmpty(void);
bool mvIsTxBufferEmpty(void);
int mvGetRxBufferSize(void);
int mvGetTxBufferSize(void);
private:
void ThreadRun(void);
CRITICAL_SECTION m_csMitsubishiPolling;
};
All the classes name listed below are identical except for function name will correspond to component name Lift, Roll, Pitch, or CounterWeight accordingly. There are differents between Lift, Roll, Pitch or CounterWeight classes but the function names and parameters are the same.The inherited CLX_PARAMETERS contains functions to send and recieve packets. It also has a some virtual function such as mvGetByte, mvPutByte, mvSetCommPort. This virtual function are overrided in CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING so the all the inherited classes use the same serial port. There are differents between LENZE or MITSUBISHI objects but the function names and parameters are the same.
CLX_LENZE_PITCH_INVERTOR
CLX_LENZE_ROLL_INVERTOR
CLX_LENZE_LIFT_INVERTOR
CLX_LENZE_COUNTERWEIGHT_INVERTOR
CLX_MITSUBISHI_PITCH_INVERTOR
CLX_MITSUBISHI_ROLL_INVERTOR
CLX_MITSUBISHI_LIFT_INVERTOR
CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR
#pragma once
#include "Windows.h"
#include "ClxSafeQue.h"
#include "ClxMitsubishiParameters.h"
class CLX_MITSUBISHI_LIFT_INVERTOR :
public CLX_MITSUBISHI_PARAMETERS
{
public:
CLX_MITSUBISHI_LIFT_INVERTOR(void);
~CLX_MITSUBISHI_LIFT_INVERTOR(void);
char m_cAddress;// This is the address of the lift inverter. This value should never change
double m_dJogFrequency; // Jog
int m_cConfigurationVoltage;
bool m_bActiveFault; // Indicates if there is a active fault
bool m_bConnected; // Indicates if there drive or software is problems
bool m_bInhibited; // Indicates if the drive is inhibited
bool m_bIsBootMode; // Boot
bool m_bIsSerialMode; // Serial
bool m_bIsAnalogMode; // Analog
bool m_bIsUnknownMode; // Unknown
bool m_bValidDriveState;
double m_dBusVoltage; // Holds the current drive bus voltage
bool m_bValidBusVoltage;
double m_dOutputVoltage; // Holds the current drive output voltage
bool m_bValidOutputVoltage;
double m_dOutputCurrent;
bool m_bValidOutputCurrent;
double m_dOutputFrequencey;
bool m_bValidOutputFrequencey;
double m_dOutputTemperature;
bool m_bValidOutputTemperature;
double m_dOperatingTime;
bool m_bValidOperatingTime;
double m_dPowerOnTime; // Holds the drives Power On Time
bool m_bValidPowerOnTime;
int m_iActiveFault; // Holds the most recent fault
bool m_bValidActiveFault;
int m_iLastFault;
bool m_bValidLastFault;
int m_iLastFault2; // Holds the thrid most recent fault
bool m_bValidLastFault2;
int m_iLastFault3; // Holds the Fourth most recent fault
bool m_bValidLastFault3;
unsigned long m_lCurrentNumTxPktFailed;
unsigned long m_iMaxinumNumTxPktFailures;
unsigned long m_lTotalNumTxPktFailed;
unsigned long m_lTotalNumTxPktCount;
char m_cPollingCommandIndex;