Changes between Version 7 and Version 8 of FirstMtglExample


Ignore:
Timestamp:
11/07/08 15:37:03 (10 years ago)
Author:
jberry
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FirstMtglExample

    v7 v8  
    6767}}} 
    6868 
    69 Now we have a complete, albeit small, example of a C code that implements a graph algorithm.  In order to "MTGL-ize" this code, we need to avoid any explicit use of the underlying data structure.  For example, the "print" function above uses the "index" and "end_points" fields of "static_graph," and therefore can be used only with this data structure.  To make that function generic, we instantiate an adapter object and use its API to access the graph.  The following program uses MTGL primitives to print the graph.  We'll consider it ([[media:test_static_graph1.cpp]]) first in its entirety, then dissect it. 
     69Now we have a complete, albeit small, example of a C code that implements a graph algorithm.  In order to "MTGL-ize" this code, we need to avoid any explicit use of the underlying data structure.  For example, the "print" function above uses the "index" and "end_points" fields of "static_graph," and therefore can be used only with this data structure.  To make that function generic, we instantiate an adapter object and use its API to access the graph.  The following program uses MTGL primitives to print the graph.  We'll consider it source:/trunk/test/test_static_graph1.cpp first in its entirety, then dissect it. 
    7070 
    71  [jberry@sancha test]$ more test_static_graph1.cpp 
     71{{{ 
    7272 #include "static_graph.h" 
    7373 #include <mtgl/static_graph_adapter.hpp> 
     
    106106        return 0; 
    107107 } 
    108  [jberry@sancha test]$ g++ -I/home/jberry/mtgl -I. static_graph.c test_static_graph1.cpp 
    109  [jberry@sancha test]$ ./a.out 
     108}}} 
     109 
     110To run: 
     111{{{ 
     112 g++ -I/home/jberry/mtgl -I. static_graph.c test_static_graph1.cpp 
     113 ./a.out 
    110114 0: 1  
    111115 1: 2  
    112  2: 0  
    113  [jberry@sancha test]$  
     116 2: 0 
     117}}}  
     118 
    114119 
    115120Those familiar with the Boost Graph Library (BGL) will note a Boost-like look and feel, though they will also note some usage differences.  These relate to computing on the MTA-2/XMT, and will be explained in time.  Now, let us break down the test_static_graph1.cpp example.  The MTGL include files are accessed through an "mtgl" directory, as Boost Graph Library files are accessed with "boost/graph/foo.hpp."  Perhaps some time in the future, the MTGL might be merged into BGL.  However, MTA-2/XMT compatibility issues prevent this for the moment.  The static_graph_adapter.hpp file is included in the MTGL distribution as an example, but typically users will write their own adapters and include them from user space.