MADNESS  0.10.1
uniqueid.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 */
31 
32 /**
33  \file uniqueid.h
34  \brief \todo Brief description needed.
35  \ingroup world
36 */
37 
38 #ifndef MADNESS_WORLD_UNIQUEID_H__INCLUDED
39 #define MADNESS_WORLD_UNIQUEID_H__INCLUDED
40 
41 #include <cstddef>
42 #include <iostream>
44 
45 namespace madness {
46 
47  class World;
48 
49  /// \addtogroup world
50  /// @{
51 
52  /// Class for unique global IDs.
53  class uniqueidT {
54  friend class World;
55  private:
56  unsigned long worldid; ///< ID of the \c World the object belongs to.
57  unsigned long objid; ///< ID of the object.
58 
59  public:
60  /// Default constructor.
62  : worldid(0), objid(0) {};
63 
64  /// Constructor that uses the world and object IDs.
65 
66  /// \param[in] worldid The ID of the \c World the object belongs to.
67  /// \param[in] objid The ID of the object.
68  uniqueidT(unsigned long worldid, unsigned long objid)
69  : worldid(worldid), objid(objid) {};
70 
71  /// nonnull state tester
72 
73  /// \return return true if non-default initialized
74  explicit operator bool() const {
75  return objid!=0;
76  }
77 
78  /// Serialize a unique ID object.
79 
80  /// \tparam Archive The archive type.
81  /// \param[in,out] ar The archive.
82  template <typename Archive>
83  void serialize(Archive& ar) {
84  ar & worldid & objid;
85  }
86 
87  /// Access the \c World ID.
88 
89  /// \return The \c World ID.
90  unsigned long get_world_id() const {
91  return worldid;
92  }
93 
94  /// Access the object ID.
95 
96  /// \return The object ID.
97  unsigned long get_obj_id() const {
98  return objid;
99  }
100 
101  /// Stream insertion function for a \c uniqueidT.
102 
103  /// \tparam CharT a character type
104  /// \tparam Traits a traits type describing \p CharT
105  /// \param[in,out] s The output stream.
106  /// \param[in] id The \c uniqueidT to be output.
107  /// \return The output stream (for chaining).
108  template <typename CharT, typename Traits>
109  friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& s, const uniqueidT& id) {
110  s << "{" << id.get_world_id() << "," << id.get_obj_id() << "}";
111  return s;
112  }
113  }; // class uniqueidT
114 
115  /// Equality comparison operator
116 
117  /// \param[in] a a \c uniqueidT object
118  /// \param[in] b a \c uniqueidT object
119  /// \return True if \p a and \b b refer to the same object in the same world
120  inline bool operator==(const uniqueidT& a, const uniqueidT& b) {
121  return a.get_obj_id() == b.get_obj_id() && a.get_world_id() == b.get_world_id();
122  }
123 
124  /// Inequality comparison operator
125 
126  /// \param[in] a a \c uniqueidT object
127  /// \param[in] b a \c uniqueidT object
128  /// \return True if \c a==b is false
129  inline bool operator!=(const uniqueidT& a, const uniqueidT& b) {
130  return !(a == b);
131  }
132 
133  /// Ordering operator
134 
135  /// \param[in] a a \c uniqueidT object
136  /// \param[in] b a \c uniqueidT object
137  /// \return True if \c a.get_world_id()<b.get_world_id() or \c a.get_world_id()==b.get_world_id()&&a.get_obj_id()<b.get_obj_id()
138  inline bool operator<(const uniqueidT& a, const uniqueidT& b) {
139  return a.get_world_id() < b.get_world_id() || (a.get_world_id() == b.get_world_id() && a.get_obj_id() < b.get_obj_id());
140  }
141 
142  /// Hash a \c uniqueidT.
143 
144  /// \param[in] id The \c uniqueidT.
145  /// \return The hash.
146  inline hashT hash_value(const uniqueidT& id) {
147  hashT seed = hash_value(id.get_world_id());
148  detail::combine_hash(seed, hash_value(id.get_obj_id()));
149 
150  return seed;
151  }
152 
153  /// @}
154 
155 } // namespace madness
156 
157 
158 #endif // MADNESS_WORLD_UNIQUEID_H__INCLUDED
A parallel world class.
Definition: world.h:132
Class for unique global IDs.
Definition: uniqueid.h:53
uniqueidT()
Default constructor.
Definition: uniqueid.h:61
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &s, const uniqueidT &id)
Stream insertion function for a uniqueidT.
Definition: uniqueid.h:109
unsigned long get_obj_id() const
Access the object ID.
Definition: uniqueid.h:97
unsigned long objid
ID of the object.
Definition: uniqueid.h:57
uniqueidT(unsigned long worldid, unsigned long objid)
Constructor that uses the world and object IDs.
Definition: uniqueid.h:68
unsigned long worldid
ID of the World the object belongs to.
Definition: uniqueid.h:56
unsigned long get_world_id() const
Access the World ID.
Definition: uniqueid.h:90
void serialize(Archive &ar)
Serialize a unique ID object.
Definition: uniqueid.h:83
bool operator<(const uniqueidT &a, const uniqueidT &b)
Ordering operator.
Definition: uniqueid.h:138
void combine_hash(hashT &seed, hashT hash)
Internal use only.
Definition: worldhash.h:248
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
bool operator!=(const ResponseParameters &p1, const ResponseParameters &p2)
Definition: response_parameters.cpp:17
bool operator==(const ResponseParameters &p1, const ResponseParameters &p2)
Definition: response_parameters.cpp:12
std::size_t hashT
The hash value type.
Definition: worldhash.h:145
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition: array_addons.h:78
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
Defines hash functions for use in distributed containers.