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