Boost logo

Boost Users :

From: Jens Müller (jens.mueller_at_[hidden])
Date: 2007-01-04 10:19:16


Jens Müller wrote:
> leda_graph.hpp has an adapter for leda::node_array's as property maps.
>
> Could the same code (replacing node by edge, where appropriate) be used
> to make an adapter for leda::edge_array's?
>
> Well, I'll try this out right now ...

The code in the attached file indeed seems to work ...

Unfortunately, I cannot really test this at the moment - the graphml
reader from graph-tool does not seem to work with LEDA graphs.

Either I'm too stupid to use the LEDA adapter, or all kinds of types in
graph_traits are not defined for LEDA graphs.

/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:26:
error: no type named `vertex_descriptor' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:27:
error: no type named `edge_descriptor' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:28:
error: no type named `adjacency_iterator' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:29:
error: no type named `out_edge_iterator' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:30:
error: no type named `in_edge_iterator' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:31:
error: no type named `vertex_iterator' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:32:
error: no type named `edge_iterator' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:34:
error: no type named `directed_category' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:35:
error: no type named `edge_parallel_category' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:36:
error: no type named `traversal_category' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:38:
error: no type named `vertices_size_type' in `class main(char,
char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:39:
error: no type named `edges_size_type' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:40:
error: no type named `degree_size_type' in `class main(char, char**)::Graph'
/home/jmueller/software-gcc34/boost/include/boost-1_33_1/boost/graph/graph_traits.hpp:48:
error: no type named `vertex_descriptor' in `struct
boost::graph_traits<main(char, char**)::Graph>'


#include <boost/config.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>

#include <LEDA/graph.h>
#include <LEDA/node_array.h>
#include <LEDA/node_map.h>

namespace boost {
  // property map interface to the LEDA edge_array class

  template <class E, class ERef, class EdgeMapPtr>
  class leda_edge_property_map
    : public put_get_helper<ERef, leda_edge_property_map<E, ERef, EdgeMapPtr> >
  {
  public:
    typedef E value_type;
    typedef ERef reference;
    typedef leda_edge key_type;
    typedef lvalue_property_map_tag category;
    leda_edge_property_map(EdgeMapPtr a) : m_array(a) { }
    ERef operator[](leda_edge n) const { return (*m_array)[n]; }
  protected:
    EdgeMapPtr m_array;
  };
  template <class E>
  leda_edge_property_map<E, const E&, const leda_edge_array<E>*>
  make_leda_node_property_map(const leda_node_array<E>& a)
  {
    typedef leda_edge_property_map<E, const E&, const leda_node_array<E>*>
      pmap_type;
    return pmap_type(&a);
  }
  template <class E>
  leda_edge_property_map<E, E&, leda_edge_array<E>*>
  make_leda_edge_property_map(leda_edge_array<E>& a)
  {
    typedef leda_edge_property_map<E, E&, leda_edge_array<E>*> pmap_type;
    return pmap_type(&a);
  }

  template <class E>
  leda_edge_property_map<E, const E&, const leda_edge_map<E>*>
  make_leda_edge_property_map(const leda_edge_map<E>& a)
  {
    typedef leda_edge_property_map<E,const E&,const leda_edge_map<E>*>
      pmap_type;
    return pmap_type(&a);
  }
  template <class E>
  leda_edge_property_map<E, E&, leda_edge_map<E>*>
  make_leda_edge_property_map(leda_edge_map<E>& a)
  {
    typedef leda_edge_property_map<E, E&, leda_edge_map<E>*> pmap_type;
    return pmap_type(&a);
  }

/* // g++ 'enumeral_type' in template unification not implemented workaround
  template <class vtype, class etype, class Tag>
  struct property_map<leda::GRAPH<vtype, etype>, Tag> {
    typedef typename
      leda_property_map<Tag>::template bind_<vtype, etype> map_gen;
    typedef typename map_gen::type type;
    typedef typename map_gen::const_type const_type;
  };

  template <class vtype, class etype, class PropertyTag, class Key>
  inline
  typename boost::property_traits<
    typename boost::property_map<leda::GRAPH<vtype, etype>,PropertyTag>::const_type
>::value_type
  get(PropertyTag p, const leda::GRAPH<vtype, etype>& g, const Key& key) {
    return get(get(p, g), key);
  }
  
  template <class vtype, class etype, class PropertyTag, class Key,class Value>
  inline void
  put(PropertyTag p, leda::GRAPH<vtype, etype>& g,
      const Key& key, const Value& value)
  {
    typedef typename property_map<leda::GRAPH<vtype, etype>, PropertyTag>::type Map;
    Map pmap = get(p, g);
    put(pmap, key, value);
  }
*/

} // namespace boost


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net