I have only rudimentary knowledge in C ++. I am trying to implement a hardware abstraction layer (HAL) in C ++. Suppose I want to implement this Data class. Based on the platform, data can be sent wired or wireless.
class Data() { public Data() { //create random data } public sendData() { // send data } public platform_action1() { // do some platform specific action }
}
// My HAL int HAL() { Data myData; myData.platform_action1(); myData.sendData(); return 0; }
Now, if I have two wired and wireless platforms, how can I extend this class and organize my files so that HAL() does not change.
Also, I do not need dynamic binding using the keyword "virtual". In my case, the platform is known at compile time.
//I do not want to do this:)...
int HAL() { Data* data = new WiredData(); data.sendData(); data = new WirelessData(); data.sendData(); }
In my case, the platform is known at compile time.
From world C, this is a simple task, like filling pointers to specific platforms.
Take, for example, the thread class in the Boost C ++ API. The class automatically spawns threads by calling either the Windows threading API or the platform-based Linux threading API. So my HAL is really platform independent.
c ++
user1715819
source share