I have made a class to describe a serial port. It contains (settings for) the port properties, baudrate, connection status, etc. AND a small number of handling functions.
I need to make three instances of this class, one of these (Port1) will be connected to DCE (Data Communication Equipment) and two (Port2, Port3) will be connected to DTE (Data Terminal Equipment) . (colloquially known as PC's and Modems)
In the Main Loop, i call the class' has_data() function on all three instances. Port1.has_data(), will read data available at Port1... etc
This works, I can send and receive messages to and from all devices, but it is missing flexibility.
I want the class to have 2 (or 3) different has_data() functions. (They may have 3 different names) and be able to assign one of them when creating the instance of the class.
So that when i call Port1.has_data() it is handled by a different function in the class than when i call Port2.has_data().
Ideally, the class should have a pointer to function, that i can point to any of the 3 member functions(assign in the constuctor)
I have no idea what to google for. With some googeling i have found links to "pointers to member functions" , but it seem not exactly to provide what i need/want.
Has anybody done something similar before?
I need to make three instances of this class, one of these (Port1) will be connected to DCE (Data Communication Equipment) and two (Port2, Port3) will be connected to DTE (Data Terminal Equipment) . (colloquially known as PC's and Modems)
In the Main Loop, i call the class' has_data() function on all three instances. Port1.has_data(), will read data available at Port1... etc
This works, I can send and receive messages to and from all devices, but it is missing flexibility.
I want the class to have 2 (or 3) different has_data() functions. (They may have 3 different names) and be able to assign one of them when creating the instance of the class.
So that when i call Port1.has_data() it is handled by a different function in the class than when i call Port2.has_data().
Ideally, the class should have a pointer to function, that i can point to any of the 3 member functions(assign in the constuctor)
I have no idea what to google for. With some googeling i have found links to "pointers to member functions" , but it seem not exactly to provide what i need/want.
Has anybody done something similar before?