os/ossrv/ossrv_pub/boost_apis/boost/python/dict.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/dict.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,152 @@
     1.4 +// Copyright David Abrahams 2002.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +#ifndef DICT_20020706_HPP
     1.9 +#define DICT_20020706_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +#include <boost/python/object.hpp>
    1.14 +#include <boost/python/list.hpp>
    1.15 +#include <boost/python/tuple.hpp>
    1.16 +#include <boost/python/converter/pytype_object_mgr_traits.hpp>
    1.17 +
    1.18 +namespace boost { namespace python {
    1.19 +
    1.20 +class dict;
    1.21 +
    1.22 +namespace detail
    1.23 +{
    1.24 +  struct BOOST_PYTHON_DECL dict_base : object
    1.25 +  {
    1.26 +      // D.clear() -> None.  Remove all items from D.
    1.27 +      void clear();
    1.28 +
    1.29 +      // D.copy() -> a shallow copy of D
    1.30 +      dict copy();
    1.31 +
    1.32 +      // D.get(k[,d]) -> D[k] if D.has_key(k), else d.  d defaults to None.
    1.33 +      object get(object_cref k) const;
    1.34 +    
    1.35 +      object get(object_cref k, object_cref d) const;
    1.36 +
    1.37 +      // D.has_key(k) -> 1 if D has a key k, else 0
    1.38 +      bool has_key(object_cref k) const;
    1.39 +
    1.40 +      // D.items() -> list of D's (key, value) pairs, as 2-tuples
    1.41 +      list items() const;
    1.42 + 
    1.43 +      // D.iteritems() -> an iterator over the (key, value) items of D
    1.44 +      object iteritems() const;
    1.45 +
    1.46 +      // D.iterkeys() -> an iterator over the keys of D
    1.47 +      object iterkeys() const;
    1.48 +
    1.49 +      // D.itervalues() -> an iterator over the values of D
    1.50 +      object itervalues() const;
    1.51 + 
    1.52 +      // D.keys() -> list of D's keys
    1.53 +      list keys() const;
    1.54 + 
    1.55 +      // D.popitem() -> (k, v), remove and return some (key, value) pair as a
    1.56 +      // 2-tuple; but raise KeyError if D is empty
    1.57 +      tuple popitem();
    1.58 +
    1.59 +      // D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
    1.60 +      object setdefault(object_cref k);
    1.61 +
    1.62 +      object setdefault(object_cref k, object_cref d);
    1.63 +
    1.64 +      // D.update(E) -> None.  Update D from E: for k in E.keys(): D[k] = E[k]
    1.65 +      void update(object_cref E);
    1.66 +
    1.67 +      // D.values() -> list of D's values
    1.68 +      list values() const;
    1.69 +
    1.70 +   protected:
    1.71 +      // dict() -> new empty dictionary.
    1.72 +      // dict(mapping) -> new dictionary initialized from a mapping object's
    1.73 +      //     (key, value) pairs.
    1.74 +      // dict(seq) -> new dictionary initialized as if via:
    1.75 +      dict_base();   // new dict
    1.76 +      explicit dict_base(object_cref data);
    1.77 +
    1.78 +      BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict_base, object)
    1.79 +   private:
    1.80 +      static detail::new_reference call(object const&);
    1.81 +  };
    1.82 +}
    1.83 +
    1.84 +class dict : public detail::dict_base
    1.85 +{
    1.86 +    typedef detail::dict_base base;
    1.87 + public:
    1.88 +    // dict() -> new empty dictionary.
    1.89 +    // dict(mapping) -> new dictionary initialized from a mapping object's
    1.90 +    //     (key, value) pairs.
    1.91 +    // dict(seq) -> new dictionary initialized as if via:
    1.92 +    dict() {}   // new dict
    1.93 +
    1.94 +    template <class T>
    1.95 +    explicit dict(T const& data)
    1.96 +        : base(object(data))
    1.97 +    {
    1.98 +    }
    1.99 +
   1.100 +    template<class T>
   1.101 +    object get(T const& k) const 
   1.102 +    {
   1.103 +        return base::get(object(k));
   1.104 +    }
   1.105 +    
   1.106 +    template<class T1, class T2>
   1.107 +    object get(T1 const& k, T2 const& d) const 
   1.108 +    {
   1.109 +        return base::get(object(k),object(d));
   1.110 +    }
   1.111 +    
   1.112 +    template<class T>
   1.113 +    bool has_key(T const& k) const
   1.114 +    {
   1.115 +        return base::has_key(object(k));
   1.116 +    }
   1.117 +    
   1.118 +    template<class T>
   1.119 +    object setdefault(T const& k)
   1.120 +    {
   1.121 +        return base::setdefault(object(k));
   1.122 +    }
   1.123 +    
   1.124 +    template<class T1, class T2>
   1.125 +    object setdefault(T1 const& k, T2 const& d)
   1.126 +    {
   1.127 +        return base::setdefault(object(k),object(d));
   1.128 +    }
   1.129 +
   1.130 +    template<class T>
   1.131 +    void update(T const& E)
   1.132 +    {
   1.133 +        base::update(object(E));
   1.134 +    }
   1.135 +
   1.136 + public: // implementation detail -- for internal use only
   1.137 +    BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, base)
   1.138 +};
   1.139 +
   1.140 +//
   1.141 +// Converter Specializations
   1.142 +//
   1.143 +namespace converter
   1.144 +{
   1.145 +  template <>
   1.146 +  struct object_manager_traits<dict>
   1.147 +      : pytype_object_manager_traits<&PyDict_Type,dict>
   1.148 +  {
   1.149 +  };
   1.150 +}
   1.151 +
   1.152 +}}   // namespace boost::python
   1.153 +
   1.154 +#endif
   1.155 +