os/ossrv/ossrv_pub/boost_apis/boost/pending/property.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//  (C) Copyright Jeremy Siek 2004 
sl@0
     2
//  Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
//  accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
//  http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
sl@0
     6
#ifndef BOOST_PROPERTY_HPP
sl@0
     7
#define BOOST_PROPERTY_HPP
sl@0
     8
sl@0
     9
#include <boost/pending/ct_if.hpp>
sl@0
    10
sl@0
    11
namespace boost {
sl@0
    12
sl@0
    13
  struct no_property { 
sl@0
    14
    typedef no_property tag_type;
sl@0
    15
    typedef no_property next_type;
sl@0
    16
    typedef no_property value_type;
sl@0
    17
    enum { num = 0 };
sl@0
    18
    typedef void kind;
sl@0
    19
  };
sl@0
    20
sl@0
    21
  template <class Tag, class T, class Base = no_property>
sl@0
    22
  struct property : public Base {
sl@0
    23
    typedef Base next_type;
sl@0
    24
    typedef Tag tag_type;
sl@0
    25
    typedef T value_type;
sl@0
    26
#if BOOST_WORKAROUND (__GNUC__, < 3)
sl@0
    27
    property() { }
sl@0
    28
#else
sl@0
    29
    property() : m_value() { }
sl@0
    30
#endif
sl@0
    31
    property(const T& v) : m_value(v) { }
sl@0
    32
    property(const T& v, const Base& b) : Base(b), m_value(v) { }
sl@0
    33
    // copy constructor and assignment operator will be generated by compiler
sl@0
    34
sl@0
    35
    T m_value;
sl@0
    36
  };
sl@0
    37
sl@0
    38
  // The BGL properties specialize property_kind and
sl@0
    39
  // property_num, and use enum's for the Property type (see
sl@0
    40
  // graph/properties.hpp), but the user may want to use a class
sl@0
    41
  // instead with a nested kind type and num.  Also, we may want to
sl@0
    42
  // switch BGL back to using class types for properties at some point.
sl@0
    43
sl@0
    44
  template <class PropertyTag>
sl@0
    45
  struct property_kind {
sl@0
    46
    typedef typename PropertyTag::kind type;
sl@0
    47
  };
sl@0
    48
sl@0
    49
  template <class P>
sl@0
    50
  struct has_property { 
sl@0
    51
    BOOST_STATIC_CONSTANT(bool, value = true);
sl@0
    52
    typedef true_type type;
sl@0
    53
  };
sl@0
    54
  template <>
sl@0
    55
  struct has_property<no_property> { 
sl@0
    56
    BOOST_STATIC_CONSTANT(bool, value = false); 
sl@0
    57
    typedef false_type type; 
sl@0
    58
  };
sl@0
    59
sl@0
    60
} // namespace boost
sl@0
    61
sl@0
    62
#include <boost/pending/detail/property.hpp>
sl@0
    63
sl@0
    64
namespace boost {
sl@0
    65
sl@0
    66
  template <class PropertyList, class Tag>
sl@0
    67
  struct property_value {
sl@0
    68
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
    69
    typedef typename detail::build_property_tag_value_alist<PropertyList>::type AList;
sl@0
    70
    typedef typename detail::extract_value<AList,Tag>::type type;
sl@0
    71
#else
sl@0
    72
    typedef typename detail::build_property_tag_value_alist<PropertyList>::type AList;
sl@0
    73
    typedef typename detail::ev_selector<AList>::type Extractor;
sl@0
    74
    typedef typename Extractor::template bind_<AList,Tag>::type type;
sl@0
    75
#endif  
sl@0
    76
  };
sl@0
    77
sl@0
    78
  template <class Tag1, class Tag2, class T1, class Base>
sl@0
    79
  inline typename property_value<property<Tag1,T1,Base>, Tag2>::type& 
sl@0
    80
  get_property_value(property<Tag1,T1,Base>& p, Tag2 tag2) {
sl@0
    81
    BOOST_STATIC_CONSTANT(bool, 
sl@0
    82
                          match = (detail::same_property<Tag1,Tag2>::value));
sl@0
    83
    typedef property<Tag1,T1,Base> Prop;
sl@0
    84
    typedef typename property_value<Prop, Tag2>::type T2;
sl@0
    85
    T2* t2 = 0;
sl@0
    86
    typedef detail::property_value_dispatch<match> Dispatcher;
sl@0
    87
    return Dispatcher::get_value(p, t2, tag2);
sl@0
    88
  }
sl@0
    89
  template <class Tag1, class Tag2, class T1, class Base>
sl@0
    90
  inline
sl@0
    91
  const typename property_value<property<Tag1,T1,Base>, Tag2>::type& 
sl@0
    92
  get_property_value(const property<Tag1,T1,Base>& p, Tag2 tag2) {
sl@0
    93
    BOOST_STATIC_CONSTANT(bool, 
sl@0
    94
                          match = (detail::same_property<Tag1,Tag2>::value));
sl@0
    95
    typedef property<Tag1,T1,Base> Prop;
sl@0
    96
    typedef typename property_value<Prop, Tag2>::type T2;
sl@0
    97
    T2* t2 = 0;
sl@0
    98
    typedef detail::property_value_dispatch<match> Dispatcher;
sl@0
    99
    return Dispatcher::const_get_value(p, t2, tag2);
sl@0
   100
  }
sl@0
   101
sl@0
   102
 namespace detail {
sl@0
   103
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
sl@0
   104
   template<typename FinalTag, typename FinalType>
sl@0
   105
   struct retag_property_list
sl@0
   106
   {
sl@0
   107
     typedef property<FinalTag, FinalType> type;
sl@0
   108
     typedef FinalType retagged;
sl@0
   109
   };
sl@0
   110
sl@0
   111
   template<typename FinalTag, typename Tag, typename T, typename Base>
sl@0
   112
   struct retag_property_list<FinalTag, property<Tag, T, Base> >
sl@0
   113
   {
sl@0
   114
   private:
sl@0
   115
     typedef retag_property_list<FinalTag, Base> next;
sl@0
   116
sl@0
   117
   public:
sl@0
   118
     typedef property<Tag, T, typename next::type> type;
sl@0
   119
     typedef typename next::retagged retagged;
sl@0
   120
   };
sl@0
   121
sl@0
   122
   template<typename FinalTag>
sl@0
   123
   struct retag_property_list<FinalTag, no_property>
sl@0
   124
   {
sl@0
   125
     typedef no_property type;
sl@0
   126
     typedef no_property retagged;
sl@0
   127
   };
sl@0
   128
#endif
sl@0
   129
  }
sl@0
   130
} // namesapce boost
sl@0
   131
sl@0
   132
#endif /* BOOST_PROPERTY_HPP */