RHexLib Hardware Class Proposal
Through discussions between
JayGowdy,
UlucSaranli,
AlRizzi, and myself, we addressed the outstanding issues of the RHexLib Hardware class. A few examples of the shortcomings of the currently existing structure:
- any addition of new hardware types requires a global change to the Hardware.hh, causing a large recompile because of many dependancies on Hardware.hh
- a list of pointers has to be managed within Hardware.hh, with non-existing pieces of hardware set to NULL to prevent them from being used.
- programming interfaces for specific types of hardware are managed within Hardware.hh, and all future instances of that hardware must follow the same interface, or else modify the interface in Hardware.hh (again causing a large recompile).
In order to move towards a hardware-agnostic RHexLib core, we devised a new design. The principal advantages of this design are:
JayGowdy took the above ideas and put them into a simple example. Below is a tar.gz file which shows an example of declaring multiple hardware types and accessing them by name. There are a few key concepts from the C++ language and from software engineering that need to be noted (for the non-CS types among us):
- Template-based designs - one of the more advanced concepts in C++ is the use of templates. The core Hardware class uses a templatized design, allowing a single class to act as an interface to all of the possible hardware subclasses. Unlike RTTI (run-time type information), templates are resolved at compile time, so there is no performance loss by not hard-coding type information. Jay has abstracted all templatized interface code with macros, so the common RHexLib programmer will not even know he/she is using them.
- Singleton design pattern - the singleton is a common design pattern to ensure that only a single instance of a class exists. This is done in Jay's examples by having static methods and members in a Hardware class. For every hardware type, a single default instance will be created. No matter where you access this instance, it will always be the exact same one.
Example
This is a very simple example using the sample Hardware.hh. You simply need a RHexLib tree on your machine (with libutils compiled at the very least) to get it to work.
hardwaredemo.tar.gz:
E-mail Correspondences: a lot of e-mails were shared while discussing our options. I will try to put the more useful ones here on this page:
--
ClarkHaynes? - 29 Sep 2003