epoc32/include/stdapis/boost/graph/leda_graph.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
//=======================================================================
williamr@2
     2
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
williamr@2
     3
// Copyright 2004 The Trustees of Indiana University.
williamr@2
     4
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Douglas Gregor
williamr@2
     5
//
williamr@2
     6
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
     7
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
     8
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     9
//=======================================================================
williamr@2
    10
#ifndef BOOST_GRAPH_LEDA_HPP
williamr@2
    11
#define BOOST_GRAPH_LEDA_HPP
williamr@2
    12
williamr@2
    13
#include <boost/config.hpp>
williamr@2
    14
#include <boost/iterator/iterator_facade.hpp>
williamr@2
    15
#include <boost/graph/graph_traits.hpp>
williamr@2
    16
#include <boost/graph/properties.hpp>
williamr@2
    17
williamr@2
    18
#include <LEDA/graph.h>
williamr@2
    19
#include <LEDA/node_array.h>
williamr@2
    20
#include <LEDA/node_map.h>
williamr@2
    21
williamr@2
    22
// The functions and classes in this file allows the user to
williamr@2
    23
// treat a LEDA GRAPH object as a boost graph "as is". No
williamr@2
    24
// wrapper is needed for the GRAPH object.
williamr@2
    25
williamr@2
    26
// Remember to define LEDA_PREFIX so that LEDA types such as
williamr@2
    27
// leda_edge show up as "leda_edge" and not just "edge".
williamr@2
    28
williamr@2
    29
// Warning: this implementation relies on partial specialization
williamr@2
    30
// for the graph_traits class (so it won't compile with Visual C++)
williamr@2
    31
williamr@2
    32
// Warning: this implementation is in alpha and has not been tested
williamr@2
    33
williamr@2
    34
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
williamr@2
    35
namespace boost {
williamr@2
    36
williamr@2
    37
  struct leda_graph_traversal_category : 
williamr@2
    38
    public virtual bidirectional_graph_tag,
williamr@2
    39
    public virtual adjacency_graph_tag,
williamr@2
    40
    public virtual vertex_list_graph_tag { };
williamr@2
    41
williamr@2
    42
  template <class vtype, class etype>
williamr@2
    43
  struct graph_traits< leda::GRAPH<vtype,etype> > {
williamr@2
    44
    typedef leda_node vertex_descriptor;
williamr@2
    45
    typedef leda_edge edge_descriptor;
williamr@2
    46
williamr@2
    47
    class adjacency_iterator 
williamr@2
    48
      : public iterator_facade<adjacency_iterator,
williamr@2
    49
                               leda_node,
williamr@2
    50
                               bidirectional_traversal_tag,
williamr@2
    51
                               leda_node,
williamr@2
    52
                               const leda_node*>
williamr@2
    53
    {
williamr@2
    54
    public:
williamr@2
    55
      explicit adjacency_iterator(leda_edge edge = 0) : base(edge) {}
williamr@2
    56
williamr@2
    57
    private:
williamr@2
    58
      leda_node dereference() const { return leda::target(base); }
williamr@2
    59
williamr@2
    60
      bool equal(const adjacency_iterator& other) const
williamr@2
    61
      { return base == other.base; }
williamr@2
    62
williamr@2
    63
      void increment() { base = Succ_Adj_Edge(base, 0); }
williamr@2
    64
      void decrement() { base = Pred_Adj_Edge(base, 0); }
williamr@2
    65
williamr@2
    66
      leda_edge base;
williamr@2
    67
williamr@2
    68
      friend class iterator_core_access;
williamr@2
    69
    };
williamr@2
    70
      
williamr@2
    71
    class out_edge_iterator 
williamr@2
    72
      : public iterator_facade<out_edge_iterator,
williamr@2
    73
                               leda_edge,
williamr@2
    74
                               bidirectional_traversal_tag,
williamr@2
    75
                               const leda_edge&,
williamr@2
    76
                               const leda_edge*>
williamr@2
    77
    {
williamr@2
    78
    public:
williamr@2
    79
      explicit out_edge_iterator(leda_edge edge = 0) : base(edge) {}
williamr@2
    80
williamr@2
    81
    private:
williamr@2
    82
      const leda_edge& dereference() const { return base; }
williamr@2
    83
williamr@2
    84
      bool equal(const out_edge_iterator& other) const
williamr@2
    85
      { return base == other.base; }
williamr@2
    86
williamr@2
    87
      void increment() { base = Succ_Adj_Edge(base, 0); }
williamr@2
    88
      void decrement() { base = Pred_Adj_Edge(base, 0); }
williamr@2
    89
williamr@2
    90
      leda_edge base;
williamr@2
    91
williamr@2
    92
      friend class iterator_core_access;
williamr@2
    93
    };
williamr@2
    94
      
williamr@2
    95
    class in_edge_iterator 
williamr@2
    96
      : public iterator_facade<in_edge_iterator,
williamr@2
    97
                               leda_edge,
williamr@2
    98
                               bidirectional_traversal_tag,
williamr@2
    99
                               const leda_edge&,
williamr@2
   100
                               const leda_edge*>
williamr@2
   101
    {
williamr@2
   102
    public:
williamr@2
   103
      explicit in_edge_iterator(leda_edge edge = 0) : base(edge) {}
williamr@2
   104
williamr@2
   105
    private:
williamr@2
   106
      const leda_edge& dereference() const { return base; }
williamr@2
   107
williamr@2
   108
      bool equal(const in_edge_iterator& other) const
williamr@2
   109
      { return base == other.base; }
williamr@2
   110
williamr@2
   111
      void increment() { base = Succ_Adj_Edge(base, 1); }
williamr@2
   112
      void decrement() { base = Pred_Adj_Edge(base, 1); }
williamr@2
   113
williamr@2
   114
      leda_edge base;
williamr@2
   115
williamr@2
   116
      friend class iterator_core_access;
williamr@2
   117
    };
williamr@2
   118
williamr@2
   119
    class vertex_iterator 
williamr@2
   120
      : public iterator_facade<vertex_iterator,
williamr@2
   121
                               leda_node,
williamr@2
   122
                               bidirectional_traversal_tag,
williamr@2
   123
                               const leda_node&,
williamr@2
   124
                               const leda_node*>
williamr@2
   125
    {
williamr@2
   126
    public:
williamr@2
   127
      vertex_iterator(leda_node node = 0, 
williamr@2
   128
                      const leda::GRAPH<vtype, etype>* g = 0)
williamr@2
   129
        : base(node), g(g) {}
williamr@2
   130
williamr@2
   131
    private:
williamr@2
   132
      const leda_node& dereference() const { return base; }
williamr@2
   133
williamr@2
   134
      bool equal(const vertex_iterator& other) const
williamr@2
   135
      { return base == other.base; }
williamr@2
   136
williamr@2
   137
      void increment() { base = g->succ_node(base); }
williamr@2
   138
      void decrement() { base = g->pred_node(base); }
williamr@2
   139
williamr@2
   140
      leda_node base;
williamr@2
   141
      const leda::GRAPH<vtype, etype>* g;
williamr@2
   142
williamr@2
   143
      friend class iterator_core_access;
williamr@2
   144
    };
williamr@2
   145
williamr@2
   146
    typedef directed_tag directed_category;
williamr@2
   147
    typedef allow_parallel_edge_tag edge_parallel_category; // not sure here
williamr@2
   148
    typedef leda_graph_traversal_category traversal_category;
williamr@2
   149
    typedef int vertices_size_type;
williamr@2
   150
    typedef int edges_size_type;
williamr@2
   151
    typedef int degree_size_type;
williamr@2
   152
  };
williamr@2
   153
williamr@2
   154
  template <class vtype, class etype>
williamr@2
   155
  struct vertex_property< leda::GRAPH<vtype,etype> > {
williamr@2
   156
    typedef vtype type;
williamr@2
   157
  };
williamr@2
   158
williamr@2
   159
  template <class vtype, class etype>
williamr@2
   160
  struct edge_property< leda::GRAPH<vtype,etype> > {
williamr@2
   161
    typedef etype type;
williamr@2
   162
  };
williamr@2
   163
williamr@2
   164
} // namespace boost
williamr@2
   165
#endif
williamr@2
   166
williamr@2
   167
namespace boost {
williamr@2
   168
williamr@2
   169
  template <class vtype, class etype>
williamr@2
   170
  typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
williamr@2
   171
  source(typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
williamr@2
   172
         const leda::GRAPH<vtype,etype>& g)
williamr@2
   173
  {
williamr@2
   174
    return source(e);
williamr@2
   175
  }
williamr@2
   176
williamr@2
   177
  template <class vtype, class etype>
williamr@2
   178
  typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
williamr@2
   179
  target(typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
williamr@2
   180
         const leda::GRAPH<vtype,etype>& g)
williamr@2
   181
  {
williamr@2
   182
    return target(e);
williamr@2
   183
  }
williamr@2
   184
williamr@2
   185
  template <class vtype, class etype>
williamr@2
   186
  inline std::pair<
williamr@2
   187
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator,
williamr@2
   188
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator >  
williamr@2
   189
  vertices(const leda::GRAPH<vtype,etype>& g)
williamr@2
   190
  {
williamr@2
   191
    typedef typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_iterator
williamr@2
   192
      Iter;
williamr@2
   193
    return std::make_pair( Iter(g.first_node(),&g), Iter(0,&g) );
williamr@2
   194
  }
williamr@2
   195
williamr@2
   196
  // no edges(g) function
williamr@2
   197
williamr@2
   198
  template <class vtype, class etype>
williamr@2
   199
  inline std::pair<
williamr@2
   200
    typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator,
williamr@2
   201
    typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator >  
williamr@2
   202
  out_edges(
williamr@2
   203
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   204
    const leda::GRAPH<vtype,etype>& g)
williamr@2
   205
  {
williamr@2
   206
    typedef typename graph_traits< leda::GRAPH<vtype,etype> >
williamr@2
   207
      ::out_edge_iterator Iter;
williamr@2
   208
    return std::make_pair( Iter(First_Adj_Edge(u,0)), Iter(0) );
williamr@2
   209
  }
williamr@2
   210
williamr@2
   211
  template <class vtype, class etype>
williamr@2
   212
  inline std::pair<
williamr@2
   213
    typename graph_traits< leda::GRAPH<vtype,etype> >::in_edge_iterator,
williamr@2
   214
    typename graph_traits< leda::GRAPH<vtype,etype> >::in_edge_iterator >  
williamr@2
   215
  in_edges(
williamr@2
   216
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   217
    const leda::GRAPH<vtype,etype>& g)
williamr@2
   218
  {
williamr@2
   219
    typedef typename graph_traits< leda::GRAPH<vtype,etype> >
williamr@2
   220
      ::in_edge_iterator Iter;
williamr@2
   221
    return std::make_pair( Iter(First_Adj_Edge(u,1)), Iter(0) );
williamr@2
   222
  }
williamr@2
   223
williamr@2
   224
  template <class vtype, class etype>
williamr@2
   225
  inline std::pair<
williamr@2
   226
    typename graph_traits< leda::GRAPH<vtype,etype> >::adjacency_iterator,
williamr@2
   227
    typename graph_traits< leda::GRAPH<vtype,etype> >::adjacency_iterator >  
williamr@2
   228
  adjacent_vertices(
williamr@2
   229
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   230
    const leda::GRAPH<vtype,etype>& g)
williamr@2
   231
  {
williamr@2
   232
    typedef typename graph_traits< leda::GRAPH<vtype,etype> >
williamr@2
   233
      ::adjacency_iterator Iter;
williamr@2
   234
    return std::make_pair( Iter(First_Adj_Edge(u,0)), Iter(0) );
williamr@2
   235
  }
williamr@2
   236
williamr@2
   237
  template <class vtype, class etype>
williamr@2
   238
  typename graph_traits< leda::GRAPH<vtype,etype> >::vertices_size_type
williamr@2
   239
  num_vertices(const leda::GRAPH<vtype,etype>& g)
williamr@2
   240
  {
williamr@2
   241
    return g.number_of_nodes();
williamr@2
   242
  }  
williamr@2
   243
williamr@2
   244
  template <class vtype, class etype>
williamr@2
   245
  typename graph_traits< leda::GRAPH<vtype,etype> >::edges_size_type
williamr@2
   246
  num_edges(const leda::GRAPH<vtype,etype>& g)
williamr@2
   247
  {
williamr@2
   248
    return g.number_of_edges();
williamr@2
   249
  }  
williamr@2
   250
williamr@2
   251
  template <class vtype, class etype>
williamr@2
   252
  typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
williamr@2
   253
  out_degree(
williamr@2
   254
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   255
    const leda::GRAPH<vtype,etype>&)
williamr@2
   256
  {
williamr@2
   257
    return outdeg(u);
williamr@2
   258
  }
williamr@2
   259
williamr@2
   260
  template <class vtype, class etype>
williamr@2
   261
  typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
williamr@2
   262
  in_degree(
williamr@2
   263
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   264
    const leda::GRAPH<vtype,etype>&)
williamr@2
   265
  {
williamr@2
   266
    return indeg(u);
williamr@2
   267
  }
williamr@2
   268
williamr@2
   269
  template <class vtype, class etype>
williamr@2
   270
  typename graph_traits< leda::GRAPH<vtype,etype> >::degree_size_type
williamr@2
   271
  degree(
williamr@2
   272
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u, 
williamr@2
   273
    const leda::GRAPH<vtype,etype>&)
williamr@2
   274
  {
williamr@2
   275
    return outdeg(u) + indeg(u);
williamr@2
   276
  }
williamr@2
   277
  
williamr@2
   278
  template <class vtype, class etype>
williamr@2
   279
  typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
williamr@2
   280
  add_vertex(leda::GRAPH<vtype,etype>& g)
williamr@2
   281
  {
williamr@2
   282
    return g.new_node();
williamr@2
   283
  }
williamr@2
   284
williamr@2
   285
  template <class vtype, class etype>
williamr@2
   286
  typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor
williamr@2
   287
  add_vertex(const vtype& vp, leda::GRAPH<vtype,etype>& g)
williamr@2
   288
  {
williamr@2
   289
    return g.new_node(vp);
williamr@2
   290
  }
williamr@2
   291
williamr@2
   292
  // Hmm, LEDA doesn't have the equivalent of clear_vertex() -JGS
williamr@2
   293
  // need to write an implementation
williamr@2
   294
  template <class vtype, class etype>
williamr@2
   295
  void clear_vertex(
williamr@2
   296
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
williamr@2
   297
    leda::GRAPH<vtype,etype>& g)
williamr@2
   298
  {
williamr@2
   299
    g.del_node(u);
williamr@2
   300
  }
williamr@2
   301
williamr@2
   302
  template <class vtype, class etype>
williamr@2
   303
  void remove_vertex(
williamr@2
   304
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
williamr@2
   305
    leda::GRAPH<vtype,etype>& g)
williamr@2
   306
  {
williamr@2
   307
    g.del_node(u);
williamr@2
   308
  }
williamr@2
   309
williamr@2
   310
  template <class vtype, class etype>
williamr@2
   311
  std::pair<
williamr@2
   312
    typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor,
williamr@2
   313
    bool>
williamr@2
   314
  add_edge(
williamr@2
   315
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
williamr@2
   316
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
williamr@2
   317
    leda::GRAPH<vtype,etype>& g)
williamr@2
   318
  {
williamr@2
   319
    return std::make_pair(g.new_edge(u, v), true);
williamr@2
   320
  }
williamr@2
   321
williamr@2
   322
  template <class vtype, class etype>
williamr@2
   323
  std::pair<
williamr@2
   324
    typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor,
williamr@2
   325
    bool>
williamr@2
   326
  add_edge(
williamr@2
   327
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
williamr@2
   328
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
williamr@2
   329
    const etype& et, 
williamr@2
   330
    leda::GRAPH<vtype,etype>& g)
williamr@2
   331
  {
williamr@2
   332
    return std::make_pair(g.new_edge(u, v, et), true);
williamr@2
   333
  }
williamr@2
   334
williamr@2
   335
  template <class vtype, class etype>
williamr@2
   336
  void
williamr@2
   337
  remove_edge(
williamr@2
   338
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor u,
williamr@2
   339
    typename graph_traits< leda::GRAPH<vtype,etype> >::vertex_descriptor v,
williamr@2
   340
    leda::GRAPH<vtype,etype>& g)
williamr@2
   341
  {
williamr@2
   342
    typename graph_traits< leda::GRAPH<vtype,etype> >::out_edge_iterator 
williamr@2
   343
      i,iend;
williamr@2
   344
    for (boost::tie(i,iend) = out_edges(u,g); i != iend; ++i)
williamr@2
   345
      if (target(*i,g) == v)
williamr@2
   346
        g.del_edge(*i);
williamr@2
   347
  }
williamr@2
   348
williamr@2
   349
  template <class vtype, class etype>
williamr@2
   350
  void
williamr@2
   351
  remove_edge(
williamr@2
   352
    typename graph_traits< leda::GRAPH<vtype,etype> >::edge_descriptor e,
williamr@2
   353
    leda::GRAPH<vtype,etype>& g)
williamr@2
   354
  {
williamr@2
   355
    g.del_edge(e);
williamr@2
   356
  }
williamr@2
   357
williamr@2
   358
  //===========================================================================
williamr@2
   359
  // property maps
williamr@2
   360
  
williamr@2
   361
  class leda_graph_id_map
williamr@2
   362
    : public put_get_helper<int, leda_graph_id_map>
williamr@2
   363
  {
williamr@2
   364
  public:
williamr@2
   365
    typedef readable_property_map_tag category;
williamr@2
   366
    typedef int value_type;
williamr@2
   367
    typedef int reference;
williamr@2
   368
    typedef leda_node key_type;
williamr@2
   369
    leda_graph_id_map() { }
williamr@2
   370
    template <class T>
williamr@2
   371
    long operator[](T x) const { return x->id(); }
williamr@2
   372
  };
williamr@2
   373
  template <class vtype, class etype>
williamr@2
   374
  inline leda_graph_id_map
williamr@2
   375
  get(vertex_index_t, const leda::GRAPH<vtype, etype>& g) {
williamr@2
   376
    return leda_graph_id_map();
williamr@2
   377
  }
williamr@2
   378
  template <class vtype, class etype>
williamr@2
   379
  inline leda_graph_id_map
williamr@2
   380
  get(edge_index_t, const leda::GRAPH<vtype, etype>& g) {
williamr@2
   381
    return leda_graph_id_map();
williamr@2
   382
  }
williamr@2
   383
williamr@2
   384
  template <class Tag>
williamr@2
   385
  struct leda_property_map { };
williamr@2
   386
williamr@2
   387
  template <>
williamr@2
   388
  struct leda_property_map<vertex_index_t> {
williamr@2
   389
    template <class vtype, class etype>
williamr@2
   390
    struct bind_ {
williamr@2
   391
      typedef leda_graph_id_map type;
williamr@2
   392
      typedef leda_graph_id_map const_type;
williamr@2
   393
    };
williamr@2
   394
  };
williamr@2
   395
  template <>
williamr@2
   396
  struct leda_property_map<edge_index_t> {
williamr@2
   397
    template <class vtype, class etype>
williamr@2
   398
    struct bind_ {
williamr@2
   399
      typedef leda_graph_id_map type;
williamr@2
   400
      typedef leda_graph_id_map const_type;
williamr@2
   401
    };
williamr@2
   402
  };
williamr@2
   403
williamr@2
   404
williamr@2
   405
  template <class Data, class DataRef, class GraphPtr>
williamr@2
   406
  class leda_graph_data_map
williamr@2
   407
    : public put_get_helper<DataRef, 
williamr@2
   408
                            leda_graph_data_map<Data,DataRef,GraphPtr> >
williamr@2
   409
  {
williamr@2
   410
  public:
williamr@2
   411
    typedef Data value_type;
williamr@2
   412
    typedef DataRef reference;
williamr@2
   413
    typedef void key_type;
williamr@2
   414
    typedef lvalue_property_map_tag category;
williamr@2
   415
    leda_graph_data_map(GraphPtr g) : m_g(g) { }
williamr@2
   416
    template <class NodeOrEdge>
williamr@2
   417
    DataRef operator[](NodeOrEdge x) const { return (*m_g)[x]; }
williamr@2
   418
  protected:
williamr@2
   419
    GraphPtr m_g;
williamr@2
   420
  };
williamr@2
   421
williamr@2
   422
  template <>
williamr@2
   423
  struct leda_property_map<vertex_all_t> {
williamr@2
   424
    template <class vtype, class etype>
williamr@2
   425
    struct bind_ {
williamr@2
   426
      typedef leda_graph_data_map<vtype, vtype&, leda::GRAPH<vtype, etype>*> type;
williamr@2
   427
      typedef leda_graph_data_map<vtype, const vtype&, 
williamr@2
   428
        const leda::GRAPH<vtype, etype>*> const_type;
williamr@2
   429
    };
williamr@2
   430
  };  
williamr@2
   431
  template <class vtype, class etype >
williamr@2
   432
  inline typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::type
williamr@2
   433
  get(vertex_all_t, leda::GRAPH<vtype, etype>& g) {
williamr@2
   434
    typedef typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::type 
williamr@2
   435
      pmap_type;
williamr@2
   436
    return pmap_type(&g);
williamr@2
   437
  }
williamr@2
   438
  template <class vtype, class etype >
williamr@2
   439
  inline typename property_map< leda::GRAPH<vtype, etype>, vertex_all_t>::const_type
williamr@2
   440
  get(vertex_all_t, const leda::GRAPH<vtype, etype>& g) {
williamr@2
   441
    typedef typename property_map< leda::GRAPH<vtype, etype>, 
williamr@2
   442
      vertex_all_t>::const_type pmap_type;
williamr@2
   443
    return pmap_type(&g);
williamr@2
   444
  }
williamr@2
   445
williamr@2
   446
  template <>
williamr@2
   447
  struct leda_property_map<edge_all_t> {
williamr@2
   448
    template <class vtype, class etype>
williamr@2
   449
    struct bind_ {
williamr@2
   450
      typedef leda_graph_data_map<etype, etype&, leda::GRAPH<vtype, etype>*> type;
williamr@2
   451
      typedef leda_graph_data_map<etype, const etype&, 
williamr@2
   452
        const leda::GRAPH<vtype, etype>*> const_type;
williamr@2
   453
    };
williamr@2
   454
  };
williamr@2
   455
  template <class vtype, class etype >
williamr@2
   456
  inline typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::type
williamr@2
   457
  get(edge_all_t, leda::GRAPH<vtype, etype>& g) {
williamr@2
   458
    typedef typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::type 
williamr@2
   459
      pmap_type;
williamr@2
   460
    return pmap_type(&g);
williamr@2
   461
  }
williamr@2
   462
  template <class vtype, class etype >
williamr@2
   463
  inline typename property_map< leda::GRAPH<vtype, etype>, edge_all_t>::const_type
williamr@2
   464
  get(edge_all_t, const leda::GRAPH<vtype, etype>& g) {
williamr@2
   465
    typedef typename property_map< leda::GRAPH<vtype, etype>, 
williamr@2
   466
      edge_all_t>::const_type pmap_type;
williamr@2
   467
    return pmap_type(&g);
williamr@2
   468
  }
williamr@2
   469
williamr@2
   470
  // property map interface to the LEDA node_array class
williamr@2
   471
williamr@2
   472
  template <class E, class ERef, class NodeMapPtr>
williamr@2
   473
  class leda_node_property_map
williamr@2
   474
    : public put_get_helper<ERef, leda_node_property_map<E, ERef, NodeMapPtr> >
williamr@2
   475
  {
williamr@2
   476
  public:
williamr@2
   477
    typedef E value_type;
williamr@2
   478
    typedef ERef reference;
williamr@2
   479
    typedef leda_node key_type;
williamr@2
   480
    typedef lvalue_property_map_tag category;
williamr@2
   481
    leda_node_property_map(NodeMapPtr a) : m_array(a) { }
williamr@2
   482
    ERef operator[](leda_node n) const { return (*m_array)[n]; }
williamr@2
   483
  protected:
williamr@2
   484
    NodeMapPtr m_array;
williamr@2
   485
  };
williamr@2
   486
  template <class E>
williamr@2
   487
  leda_node_property_map<E, const E&, const leda_node_array<E>*>
williamr@2
   488
  make_leda_node_property_map(const leda_node_array<E>& a)
williamr@2
   489
  {
williamr@2
   490
    typedef leda_node_property_map<E, const E&, const leda_node_array<E>*>
williamr@2
   491
      pmap_type;
williamr@2
   492
    return pmap_type(&a);
williamr@2
   493
  }
williamr@2
   494
  template <class E>
williamr@2
   495
  leda_node_property_map<E, E&, leda_node_array<E>*>
williamr@2
   496
  make_leda_node_property_map(leda_node_array<E>& a)
williamr@2
   497
  {
williamr@2
   498
    typedef leda_node_property_map<E, E&, leda_node_array<E>*> pmap_type;
williamr@2
   499
    return pmap_type(&a);
williamr@2
   500
  }
williamr@2
   501
williamr@2
   502
  template <class E>
williamr@2
   503
  leda_node_property_map<E, const E&, const leda_node_map<E>*>
williamr@2
   504
  make_leda_node_property_map(const leda_node_map<E>& a)
williamr@2
   505
  {
williamr@2
   506
    typedef leda_node_property_map<E,const E&,const leda_node_map<E>*> 
williamr@2
   507
      pmap_type;
williamr@2
   508
    return pmap_type(&a);
williamr@2
   509
  }
williamr@2
   510
  template <class E>
williamr@2
   511
  leda_node_property_map<E, E&, leda_node_map<E>*>
williamr@2
   512
  make_leda_node_property_map(leda_node_map<E>& a)
williamr@2
   513
  {
williamr@2
   514
    typedef leda_node_property_map<E, E&, leda_node_map<E>*> pmap_type;
williamr@2
   515
    return pmap_type(&a);
williamr@2
   516
  }
williamr@2
   517
williamr@2
   518
  // g++ 'enumeral_type' in template unification not implemented workaround
williamr@2
   519
  template <class vtype, class etype, class Tag>
williamr@2
   520
  struct property_map<leda::GRAPH<vtype, etype>, Tag> {
williamr@2
   521
    typedef typename 
williamr@2
   522
      leda_property_map<Tag>::template bind_<vtype, etype> map_gen;
williamr@2
   523
    typedef typename map_gen::type type;
williamr@2
   524
    typedef typename map_gen::const_type const_type;
williamr@2
   525
  };
williamr@2
   526
williamr@2
   527
  template <class vtype, class etype, class PropertyTag, class Key>
williamr@2
   528
  inline
williamr@2
   529
  typename boost::property_traits<
williamr@2
   530
    typename boost::property_map<leda::GRAPH<vtype, etype>,PropertyTag>::const_type
williamr@2
   531
  >::value_type
williamr@2
   532
  get(PropertyTag p, const leda::GRAPH<vtype, etype>& g, const Key& key) {
williamr@2
   533
    return get(get(p, g), key);
williamr@2
   534
  }
williamr@2
   535
  
williamr@2
   536
  template <class vtype, class etype, class PropertyTag, class Key,class Value>
williamr@2
   537
  inline void
williamr@2
   538
  put(PropertyTag p, leda::GRAPH<vtype, etype>& g, 
williamr@2
   539
      const Key& key, const Value& value)
williamr@2
   540
  {
williamr@2
   541
    typedef typename property_map<leda::GRAPH<vtype, etype>, PropertyTag>::type Map;
williamr@2
   542
    Map pmap = get(p, g);
williamr@2
   543
    put(pmap, key, value);
williamr@2
   544
  }
williamr@2
   545
williamr@2
   546
} // namespace boost
williamr@2
   547
williamr@2
   548
williamr@2
   549
#endif // BOOST_GRAPH_LEDA_HPP