1 //  Copyright (c) 2007-2014 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef HPX_RUNTIME_NAMING_ID_TYPE_IMPL_HPP
7 #define HPX_RUNTIME_NAMING_ID_TYPE_IMPL_HPP
8 
9 #include <hpx/config.hpp>
10 #include <hpx/runtime/naming/id_type.hpp>
11 #include <hpx/runtime/naming/name.hpp>
12 
13 #include <cstdint>
14 
15 #include <hpx/config/warnings_prefix.hpp>
16 
17 ///////////////////////////////////////////////////////////////////////////////
18 namespace hpx { namespace naming
19 {
20     ///////////////////////////////////////////////////////////////////////////
21     // the local gid is actually just a wrapper around the real thing
id_type(std::uint64_t lsb_id,management_type t)22     inline id_type::id_type(std::uint64_t lsb_id, management_type t)
23         : gid_(new detail::id_type_impl(0, lsb_id,
24             static_cast<detail::id_type_management>(t)))
25     {}
26 
id_type(gid_type const & gid,management_type t)27     inline id_type::id_type(gid_type const& gid, management_type t)
28         : gid_(new detail::id_type_impl(gid,
29             static_cast<detail::id_type_management>(t)))
30     {
31         if (t == unmanaged)
32             detail::strip_internal_bits_except_dont_cache_from_gid(*gid_);
33     }
34 
id_type(std::uint64_t msb_id,std::uint64_t lsb_id,management_type t)35     inline id_type::id_type(std::uint64_t msb_id, std::uint64_t lsb_id,
36             management_type t)
37         : gid_(new detail::id_type_impl(msb_id, lsb_id,
38             static_cast<detail::id_type_management>(t)))
39     {
40         if (t == unmanaged)
41             detail::strip_internal_bits_except_dont_cache_from_gid(*gid_);
42     }
43 
get_gid()44     inline gid_type& id_type::get_gid() { return *gid_; }
get_gid() const45     inline gid_type const& id_type::get_gid() const { return *gid_; }
46 
47     // This function is used in AGAS unit tests and application code, do not
48     // remove.
get_management_type() const49     inline id_type::management_type id_type::get_management_type() const
50     {
51         return management_type(gid_->get_management_type());
52     }
53 
operator ++()54     inline id_type& id_type::operator++()       // pre-increment
55     {
56         ++(*gid_);
57         return *this;
58     }
operator ++(int)59     inline id_type id_type::operator++(int)     // post-increment
60     {
61         return id_type((*gid_)++, unmanaged);
62     }
63 
operator bool() const64     inline id_type::operator bool() const noexcept
65     {
66         return gid_ && *gid_;
67     }
68 
69     // comparison is required as well
operator ==(id_type const & lhs,id_type const & rhs)70     inline bool operator== (id_type const& lhs, id_type const& rhs)
71     {
72         if (!lhs)
73             return !rhs;
74         if (!rhs)
75             return !lhs;
76 
77         return *lhs.gid_ == *rhs.gid_;
78     }
operator !=(id_type const & lhs,id_type const & rhs)79     inline bool operator!= (id_type const& lhs, id_type const& rhs)
80     {
81         return !(lhs == rhs);
82     }
83 
operator <(id_type const & lhs,id_type const & rhs)84     inline bool operator< (id_type const& lhs, id_type const& rhs)
85     {
86         // LHS is null, rhs is not.
87         if (!lhs && rhs)
88             return true;
89 
90         // RHS is null.
91         if (!rhs)
92             return false;
93 
94         return *lhs.gid_ < *rhs.gid_;
95     }
96 
operator <=(id_type const & lhs,id_type const & rhs)97     inline bool operator<= (id_type const& lhs, id_type const& rhs)
98     {
99         // Deduced from <.
100         return !(rhs < lhs);
101     }
102 
operator >(id_type const & lhs,id_type const & rhs)103     inline bool operator> (id_type const& lhs, id_type const& rhs)
104     {
105         // Deduced from <.
106         return rhs < lhs;
107     }
108 
operator >=(id_type const & lhs,id_type const & rhs)109     inline bool operator>= (id_type const& lhs, id_type const& rhs)
110     {
111         // Deduced from <.
112         return !(lhs < rhs);
113     }
114 
115     // access the internal parts of the gid
get_msb() const116     inline std::uint64_t id_type::get_msb() const
117     {
118         return gid_->get_msb();
119     }
set_msb(std::uint64_t msb)120     inline void id_type::set_msb(std::uint64_t msb)
121     {
122         gid_->set_msb(msb);
123     }
124 
get_lsb() const125     inline std::uint64_t id_type::get_lsb() const
126     {
127         return gid_->get_lsb();
128     }
set_lsb(std::uint64_t lsb)129     inline void id_type::set_lsb(std::uint64_t lsb)
130     {
131         gid_->set_lsb(lsb);
132     }
set_lsb(void * lsb)133     inline void id_type::set_lsb(void* lsb)
134     {
135         gid_->set_lsb(lsb);
136     }
137 
make_unmanaged() const138     inline void id_type::make_unmanaged() const
139     {
140         gid_->set_management_type(detail::unmanaged);
141     }
142 }}
143 
144 #include <hpx/config/warnings_suffix.hpp>
145 
146 #endif /*HPX_RUNTIME_NAMING_ID_TYPE_IMPL_HPP*/
147