Object Oriented C programming style » History » Version 7
Graham Hudspith, 23.08.2011 17:26
Correct xine url
h1. Object Oriented C programming style
For new code in strongSwan, we use an object oriented programming style. This allows us to employ modern programming paradigms, but still use the standard C compiler and toolset.
This object oriented design is achieved by heavy use of function pointers. Interfaces of classes are defined as a struct with function pointers, and an implementation extends the struct by including the Interface as its first struct member. The idea is based on the coding style of the "xine project":http://www.xine-project.org/hackersguide#id324430.
To get an idea of the whole concept we recommend to examine the code directly.
h2. Type safety
To achieve type safety without casting the _this_ parameter in each method, we have introduced some special helper macros. The METHOD macro helps in implementing a method that is compatible to both the public and the private interfaces automatically. The INIT macro initializes objects using readable Designated Initializers. Not all code has been migrated to the new macros yet, but new code should use them.
h2. Gedit Snippets
Being a gedit user, I created some snippets (attachment:gedit-snippets-strongswan.tar.gz) to create interfaces, methods (including implementations and pointer assignement) and class implementations.