Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2003-12-12 16:24:19


Neat! It will be fun to look at. I admire your bravery... porting to a
language without generics. We did a prototype port to C# with generics,
and found that to be challenging.

Cheers,
Jeremy

On Fri, 12 Dec 2003, Jonathan de Halleux wrote:
dehall> Hi all,
dehall>
dehall> (This thread is a bit out of topic since boost is a C++ library but it is
dehall> worth to mention. If you have nothing to do with C#, please do not mind
dehall> this post)
dehall>
dehall> The QuickGraph library is an attempt to port the BGL library to C#. It has
dehall> now reached a stable form and therefore I am sending this mail to the BGL
dehall> C++ users.
dehall>
dehall> A large part of the concept and structure of the library is directly
dehall> takened from the BGL. Here below, I discuss some major points about porting
dehall> the BGL to C#.
dehall>
dehall> 1) No templates in C#:
dehall> -----------------------------
dehall>
dehall> This is, for sure, the biggest issue: the C# does not support templates...
dehall> yet. So class templates, function templates, partial template
dehall> specialization could not be used. At first, without templates, genericity
dehall> of the library is seriously compromised.
dehall>
dehall> 2) Concepts and C# interface: natural friends
dehall> ----------------------------------------------------------
dehall>
dehall> The C# interfaces come to the rescue. Indeed, they are the natural C#
dehall> equivalent of the concepts. In fact, turning a BGL concept into a C#
dehall> interface is just a matter of ... writing the valid expressions into an
dehall> interface.
dehall>
dehall> For example, the VertexListConcept defines the add_vertex and remove_vertex
dehall> methods. The corresponding interface is:
dehall>
dehall> public interface IVertexListGraph
dehall> {
dehall> IVertex AddVertex();
dehall> void RemoveVertex(IVertex u);
dehall> }
dehall>
dehall> A model of the VertexListConcept will have to implement the
dehall> IVertexListGraph interface. For example, the AdjacencyGraph class will
dehall> derive from IVertexListGraph which will oblige it to implement the desired
dehall> methods.
dehall> public class AdjacencyGraph : ..., IVertexListGraph
dehall>
dehall> All the QuickGraph concepts are centralized in the QuickGraph.Concepts
dehall> namespace (in the ''QuickGraph.Concepts.dll'' assembly) which in fact
dehall> contains interfaces only.
dehall>
dehall> 3) ConceptChecking and C# interface: natural friends
dehall> ---------------------------------------------------------------
dehall>
dehall> C# interface have a lot of advantages. In fact, they enforce the
dehall> implementation of their defined methods wich is implicitely a form of
dehall> ConceptChecking.
dehall>
dehall> 4) Visitors ... no Events!
dehall> --------------------------------
dehall>
dehall> The BGL adds greate flexibility and reusability through the use of visitors
dehall> (see the VisitorPattern of the GoF).
dehall>
dehall> In the BGL, to define visitors, you must first create a visitor class that
dehall> defines a number of method. For instance, in the DepthFirstSearchAlgorithm,
dehall> the visitor must implement 5 methods discover_vertex, tree_edge, back_egde,
dehall> forward_or_cross_edge and finish_vertex.
dehall>
dehall> In QuickGraph, the decision could be done to reused the BGL visitor pattern
dehall> but it turned out that C# provided a much flexible solution: events. In C#,
dehall> events are delegates, function calls dispatcher, to which static functions
dehall> or instance binded methods (handlers) can be attached. Whenever this event
dehall> is fired, the handlers are called. Therefore, the BGL visitor methods
dehall> naturally transtate into events where visitor can attach handlers.
dehall>
dehall> Another interresting advantage about delegates is that they are multi-cast.
dehall> Therefore, multiple visitor can be attached to the same algorithm
dehall> out-of-the-box.
dehall>
dehall> 5) Vertex, edge descriptors... Providers
dehall> ---------------------------------------------------
dehall>
dehall> In the BGL, the choice of vertex and edge descriptor comes out-of-the-box
dehall> with the use of templates. To tackle this problem, QuickGraph asks the user
dehall> to provide "Provider" classes that generate the vertex and edges on demand.
dehall> Therefore, you can use any object as vertex or edge as long as it derives
dehall> from IVertex or IEdge. Providers are detailled in the ProviderConcepts section.
dehall>
dehall>
dehall> If interrested, you can downlaod it at
dehall> QuickGraph homepage: http://www.dotnetwiki.org
dehall>
dehall> About licensing: QuickGraph is licensed under the zlib/png license.
dehall>
dehall>
dehall> -----------------------------------------------------------------------------------
dehall> Jonathan de Halleux, Research Assistant
dehall> Center for Systems Engineering and Applied Mechanics (CESAME)
dehall> Universite catholique de Louvain
dehall> Batiment Euler , Av. Georges Lemaitre, 4 Tel : +32-10-47 2595
dehall> B-1348 Louvain-la-Neuve Belgium
dehall> E-mail : dehalleux_at_[hidden]
dehall> -----------------------------------------------------------------------------------
dehall>
dehall> _______________________________________________
dehall> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
dehall>

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 856-1820
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk