Lumiera  0.pre.03
»edit your freedom«
buffer-local-key.hpp
Go to the documentation of this file.
1 /*
2  BUFFER-LOCAL-KEY.hpp - opaque data for BufferProvider implementation
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
29 #ifndef STEAM_ENGINE_BUFFR_LOCAL_KEY_H
30 #define STEAM_ENGINE_BUFFR_LOCAL_KEY_H
31 
32 
33 #include "lib/error.hpp"
34 #include "lib/hash-value.h"
35 
36 #include <boost/functional/hash.hpp>
37 
38 
39 namespace steam {
40 namespace engine {
41 
42  namespace metadata {
43  class Key;
44  class Entry;
45  }
46  class BufferMetadata;
47 
48  using lib::HashVal;
49 
50 
51 
58  class LocalKey
59  {
60  union OpaqueData
61  {
62  uint64_t _as_number;
63  void* _as_pointer;
64  };
65 
66  OpaqueData privateID_;
67 
68  public:
69  explicit
70  LocalKey (uint64_t opaqueValue=0)
71  {
72  privateID_._as_number = opaqueValue;
73  }
74 
75  LocalKey (void* impl_related_ptr)
76  {
77  privateID_._as_number = 0;
78  privateID_._as_pointer = impl_related_ptr;
79  }
80 
81 
82  operator uint64_t() const
83  {
84  return privateID_._as_number;
85  }
86 
87  operator void*() const
88  {
89  return privateID_._as_pointer;
90  }
91 
92  bool
93  isDefined() const
94  {
95  return bool(privateID_._as_number);
96  }
97 
98  friend size_t
99  hash_value (LocalKey const& lkey)
100  {
101  boost::hash<uint64_t> hashFunction;
102  return hashFunction(lkey.privateID_._as_number);
103  }
104 
105  friend bool
106  operator== (LocalKey const& left, LocalKey const& right)
107  {
108  return uint64_t(left) == uint64_t(right);
109  }
110  friend bool
111  operator!= (LocalKey const& left, LocalKey const& right)
112  {
113  return uint64_t(left) != uint64_t(right);
114  }
115 
116 
117  private:
119  LocalKey& operator= (LocalKey const& o)
120  {
121  privateID_ = o.privateID_;
122  return *this;
123  }
124 
126  friend class metadata::Key;
127  };
128 
129 
130 }} // namespace steam::engine
131 #endif
Steam-Layer implementation namespace root.
an opaque ID to be used by the BufferProvider implementation.
Description of a Buffer-"type".
Lumiera error handling (C++ interface).
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56