epoc32/include/stdapis/boost/graph/detail/indexed_properties.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright 2005 The Trustees of Indiana University.
williamr@2
     2
williamr@2
     3
// Distributed under the Boost Software License, Version 1.0.
williamr@2
     4
// (See accompanying file LICENSE_1_0.txt or copy at
williamr@2
     5
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     6
williamr@2
     7
//  Authors: Jeremiah Willcock
williamr@2
     8
//           Douglas Gregor
williamr@2
     9
//           Andrew Lumsdaine
williamr@2
    10
williamr@2
    11
// Indexed properties -- used for CSR and CSR-like graphs
williamr@2
    12
williamr@2
    13
#ifndef BOOST_GRAPH_INDEXED_PROPERTIES_HPP
williamr@2
    14
#define BOOST_GRAPH_INDEXED_PROPERTIES_HPP
williamr@2
    15
williamr@2
    16
#include <vector>
williamr@2
    17
#include <utility>
williamr@2
    18
#include <algorithm>
williamr@2
    19
#include <climits>
williamr@2
    20
#include <iterator>
williamr@2
    21
#include <boost/graph/graph_traits.hpp>
williamr@2
    22
#include <boost/graph/properties.hpp>
williamr@2
    23
#include <boost/iterator/counting_iterator.hpp>
williamr@2
    24
#include <boost/integer.hpp>
williamr@2
    25
#include <boost/iterator/iterator_facade.hpp>
williamr@2
    26
#include <boost/mpl/if.hpp>
williamr@2
    27
williamr@2
    28
namespace boost {
williamr@2
    29
namespace detail {
williamr@2
    30
williamr@2
    31
template<typename Derived, typename Property, typename Descriptor>
williamr@2
    32
class indexed_vertex_properties
williamr@2
    33
{
williamr@2
    34
public:
williamr@2
    35
  typedef no_property vertex_property_type;
williamr@2
    36
  typedef Property vertex_bundled;
williamr@2
    37
williamr@2
    38
  // Directly access a vertex or edge bundle
williamr@2
    39
  Property& operator[](Descriptor v)
williamr@2
    40
  { return m_vertex_properties[get(vertex_index, derived(), v)]; }
williamr@2
    41
williamr@2
    42
  const Property& operator[](Descriptor v) const
williamr@2
    43
  { return m_vertex_properties[get(vertex_index, derived(), v)]; }
williamr@2
    44
williamr@2
    45
protected:
williamr@2
    46
  // Default-construct with no property values
williamr@2
    47
  indexed_vertex_properties() {}
williamr@2
    48
williamr@2
    49
  // Initialize with n default-constructed property values
williamr@2
    50
  indexed_vertex_properties(std::size_t n) : m_vertex_properties(n) { }
williamr@2
    51
williamr@2
    52
  // Resize the properties vector
williamr@2
    53
  void resize(std::size_t n)
williamr@2
    54
  {
williamr@2
    55
    m_vertex_properties.resize(n);
williamr@2
    56
  }
williamr@2
    57
williamr@2
    58
  // Reserve space in the vector of properties
williamr@2
    59
  void reserve(std::size_t n)
williamr@2
    60
  {
williamr@2
    61
    m_vertex_properties.reserve(n);
williamr@2
    62
  }
williamr@2
    63
williamr@2
    64
  // Add a new property value to the back
williamr@2
    65
  void push_back(const Property& prop)
williamr@2
    66
  {
williamr@2
    67
    m_vertex_properties.push_back(prop);
williamr@2
    68
  }
williamr@2
    69
williamr@2
    70
  // Access to the derived object
williamr@2
    71
  Derived& derived() { return *static_cast<Derived*>(this); }
williamr@2
    72
williamr@2
    73
  const Derived& derived() const
williamr@2
    74
  { return *static_cast<const Derived*>(this); }
williamr@2
    75
williamr@2
    76
public: // should be private, but friend templates not portable
williamr@2
    77
  std::vector<Property> m_vertex_properties;
williamr@2
    78
};
williamr@2
    79
williamr@2
    80
template<typename Derived, typename Descriptor>
williamr@2
    81
class indexed_vertex_properties<Derived, void, Descriptor>
williamr@2
    82
{
williamr@2
    83
  struct secret {};
williamr@2
    84
williamr@2
    85
 public:
williamr@2
    86
  typedef no_property vertex_property_type;
williamr@2
    87
  typedef void vertex_bundled;
williamr@2
    88
williamr@2
    89
  secret operator[](secret) { return secret(); }
williamr@2
    90
williamr@2
    91
 protected:
williamr@2
    92
  // All operations do nothing.
williamr@2
    93
  indexed_vertex_properties() { }
williamr@2
    94
  indexed_vertex_properties(std::size_t) { }
williamr@2
    95
  void resize(std::size_t) { }
williamr@2
    96
  void reserve(std::size_t) { }
williamr@2
    97
};
williamr@2
    98
williamr@2
    99
template<typename Derived, typename Property, typename Descriptor>
williamr@2
   100
class indexed_edge_properties
williamr@2
   101
{
williamr@2
   102
public:
williamr@2
   103
  typedef no_property edge_property_type;
williamr@2
   104
  typedef Property edge_bundled;
williamr@2
   105
  typedef Property edge_push_back_type;
williamr@2
   106
williamr@2
   107
  // Directly access a edge or edge bundle
williamr@2
   108
  Property& operator[](Descriptor v)
williamr@2
   109
  { return m_edge_properties[get(edge_index, derived(), v)]; }
williamr@2
   110
williamr@2
   111
  const Property& operator[](Descriptor v) const
williamr@2
   112
  { return m_edge_properties[get(edge_index, derived(), v)]; }
williamr@2
   113
williamr@2
   114
protected:
williamr@2
   115
  // Default-construct with no property values
williamr@2
   116
  indexed_edge_properties() {}
williamr@2
   117
williamr@2
   118
  // Initialize with n default-constructed property values
williamr@2
   119
  indexed_edge_properties(std::size_t n) : m_edge_properties(n) { }
williamr@2
   120
williamr@2
   121
  // Resize the properties vector
williamr@2
   122
  void resize(std::size_t n)
williamr@2
   123
  {
williamr@2
   124
    m_edge_properties.resize(n);
williamr@2
   125
  }
williamr@2
   126
williamr@2
   127
  // Reserve space in the vector of properties
williamr@2
   128
  void reserve(std::size_t n)
williamr@2
   129
  {
williamr@2
   130
    m_edge_properties.reserve(n);
williamr@2
   131
  }
williamr@2
   132
williamr@2
   133
 public:
williamr@2
   134
  // Add a new property value to the back
williamr@2
   135
  void push_back(const Property& prop)
williamr@2
   136
  {
williamr@2
   137
    m_edge_properties.push_back(prop);
williamr@2
   138
  }
williamr@2
   139
williamr@2
   140
 private:
williamr@2
   141
  // Access to the derived object
williamr@2
   142
  Derived& derived() { return *static_cast<Derived*>(this); }
williamr@2
   143
williamr@2
   144
  const Derived& derived() const
williamr@2
   145
  { return *static_cast<const Derived*>(this); }
williamr@2
   146
williamr@2
   147
public: // should be private, but friend templates not portable
williamr@2
   148
  std::vector<Property> m_edge_properties;
williamr@2
   149
};
williamr@2
   150
williamr@2
   151
template<typename Derived, typename Descriptor>
williamr@2
   152
class indexed_edge_properties<Derived, void, Descriptor>
williamr@2
   153
{
williamr@2
   154
  struct secret {};
williamr@2
   155
williamr@2
   156
 public:
williamr@2
   157
  typedef no_property edge_property_type;
williamr@2
   158
  typedef void edge_bundled;
williamr@2
   159
  typedef void* edge_push_back_type;
williamr@2
   160
williamr@2
   161
  secret operator[](secret) { return secret(); }
williamr@2
   162
williamr@2
   163
 protected:
williamr@2
   164
  // All operations do nothing.
williamr@2
   165
  indexed_edge_properties() { }
williamr@2
   166
  indexed_edge_properties(std::size_t) { }
williamr@2
   167
  void resize(std::size_t) { }
williamr@2
   168
  void reserve(std::size_t) { }
williamr@2
   169
williamr@2
   170
 public:
williamr@2
   171
  void push_back(const edge_push_back_type&) { }
williamr@2
   172
};
williamr@2
   173
williamr@2
   174
}
williamr@2
   175
}
williamr@2
   176
williamr@2
   177
#endif // BOOST_GRAPH_INDEXED_PROPERTIES_HPP