rippled
SHAMapItem.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED
21 #define RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED
22 
23 #include <ripple/basics/Buffer.h>
24 #include <ripple/basics/CountedObject.h>
25 #include <ripple/basics/Slice.h>
26 #include <ripple/basics/base_uint.h>
27 
28 namespace ripple {
29 
30 // an item stored in a SHAMap
31 class SHAMapItem : public CountedObject<SHAMapItem>
32 {
33 private:
36 
37 public:
38  SHAMapItem() = delete;
39 
40  SHAMapItem(uint256 const& tag, Slice data) : tag_(tag), data_(data)
41  {
42  }
43 
44  uint256 const&
45  key() const
46  {
47  return tag_;
48  }
49 
50  Slice
51  slice() const
52  {
53  return static_cast<Slice>(data_);
54  }
55 
57  size() const
58  {
59  return data_.size();
60  }
61 
62  void const*
63  data() const
64  {
65  return data_.data();
66  }
67 };
68 
69 } // namespace ripple
70 
71 #endif
ripple::SHAMapItem::data
void const * data() const
Definition: SHAMapItem.h:63
ripple::SHAMapItem::SHAMapItem
SHAMapItem()=delete
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::SHAMapItem::data_
Buffer data_
Definition: SHAMapItem.h:35
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::SHAMapItem::key
uint256 const & key() const
Definition: SHAMapItem.h:45
ripple::base_uint< 256 >
ripple::SHAMapItem::tag_
uint256 tag_
Definition: SHAMapItem.h:34
ripple::SHAMapItem
Definition: SHAMapItem.h:31
ripple::Buffer::size
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Definition: Buffer.h:126
ripple::SHAMapItem::size
std::size_t size() const
Definition: SHAMapItem.h:57
ripple::Buffer::data
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Definition: Buffer.h:150
ripple::SHAMapItem::slice
Slice slice() const
Definition: SHAMapItem.h:51
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::size_t
ripple::SHAMapItem::SHAMapItem
SHAMapItem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:40