src/work/marci_property_vector.hh
author marci
Fri, 16 Jan 2004 11:20:09 +0000
changeset 15 e41c71268807
child 19 3151a1026db9
permissions -rw-r--r--
new method for making invalid iterators: make_invalid()
marci@9
     1
#ifndef MARCI_PROPERTY_VECTOR_HH
marci@9
     2
#define MARCI_PROPERTY_VECTOR_HH
marci@9
     3
marci@9
     4
#include <vector>
marci@9
     5
marci@9
     6
#include <marci_graph_traits.hh>
marci@9
     7
marci@9
     8
namespace marci {
marci@9
     9
marci@9
    10
  template <typename iterator>
marci@9
    11
  int number_of(iterator _it) { 
marci@9
    12
    int i=0;
marci@9
    13
    for( ; _it.is_valid(); ++_it) { ++i; } 
marci@9
    14
    return i;
marci@9
    15
  }
marci@9
    16
  
marci@9
    17
  template <typename graph_type, typename T>
marci@9
    18
  class node_property_vector {
marci@9
    19
    typedef typename graph_traits<graph_type>::node_iterator node_iterator;
marci@9
    20
    typedef typename graph_traits<graph_type>::each_node_iterator each_node_iterator;
marci@9
    21
    graph_type& G; 
marci@9
    22
    std::vector<T> container;
marci@9
    23
  public:
marci@9
    24
    node_property_vector(graph_type& _G) : G(_G) {
marci@9
    25
      int i=0;
marci@9
    26
      for(each_node_iterator it=G.first_node(); it.is_valid(); ++it) ++i;
marci@9
    27
      container.resize(i); 
marci@9
    28
    }
marci@9
    29
    node_property_vector(graph_type& _G, T a) : G(_G) {
marci@9
    30
      for(each_node_iterator it=G.first_node(); it.is_valid(); ++it) { container.push_back(a); }
marci@9
    31
    }
marci@9
    32
    void put(node_iterator nit, const T& a) { container[G.id(nit)]=a; }
marci@9
    33
    T get(node_iterator nit) { return container[G.id(nit)]; }
marci@9
    34
  };
marci@9
    35
marci@9
    36
  template <typename graph_type, typename T>
marci@9
    37
  class edge_property_vector {
marci@9
    38
    typedef typename graph_traits<graph_type>::edge_iterator edge_iterator;
marci@9
    39
    typedef typename graph_traits<graph_type>::each_edge_iterator each_edge_iterator;
marci@9
    40
    graph_type& G; 
marci@9
    41
    std::vector<T> container;
marci@9
    42
  public:
marci@9
    43
    edge_property_vector(graph_type& _G) : G(_G) {
marci@9
    44
      int i=0;
marci@9
    45
      for(each_edge_iterator it=G.first_edge(); it.is_valid(); ++it) ++i;
marci@9
    46
      container.resize(i); 
marci@9
    47
    }
marci@9
    48
    edge_property_vector(graph_type& _G, T a) : G(_G) {
marci@9
    49
      for(each_edge_iterator it=G.first_edge(); it.is_valid(); ++it) { 
marci@9
    50
	container.push_back(a); 
marci@9
    51
      }
marci@9
    52
    }
marci@9
    53
    void put(edge_iterator eit, const T& a) { container[G.id(eit)]=a; }
marci@9
    54
    T get(edge_iterator eit) { return container[G.id(eit)]; }
marci@9
    55
  };
marci@9
    56
marci@9
    57
} // namespace marci
marci@9
    58
marci@9
    59
#endif //MARCI_PROPERTY_VECTOR_HH