ext_8103: (Default)
posted by [identity profile] ewx.livejournal.com at 11:24am on 30/05/2005

For your library you can decorate the functions with the representation and the user-facing header file can pick the right implementation for the selected algorithm by defining the publicly visible function name to the appropriate decorated one.

However, having callers know the representation, at the level of having macros that need to understand it, etc, is going to lose you type-safety at link time.

My usual approach for differing types with a common interface is the same as that used by Berkeley DB; the object representing the graph contains, or contains a pointer to, a table of function pointers, and all the knowledge of the underlying representation is hidden behind that. The only time your program ever knows the representation is when it requests the library to create it a new graph.

ext_8103: (Default)
posted by [identity profile] ewx.livejournal.com at 11:25am on 30/05/2005
...I see IWJ is suggesting the same idea as my final paragraph on IRC in fact l-)
emperor: (Default)
posted by [personal profile] emperor at 11:31am on 30/05/2005
Indeed. I'm about to stick their remarks into a comment here.

October

SunMonTueWedThuFriSat
      1
 
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
 
10
 
11
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
26
 
27
 
28
 
29
 
30
 
31