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/Blob.h>
24 #include <ripple/basics/CountedObject.h>
25 #include <ripple/basics/Slice.h>
26 #include <ripple/basics/base_uint.h>
27 #include <ripple/beast/utility/Journal.h>
28 #include <ripple/protocol/Serializer.h>
29 
30 #include <cstddef>
31 
32 namespace ripple {
33 
34 // an item stored in a SHAMap
35 class SHAMapItem : public CountedObject<SHAMapItem>
36 {
37 private:
40 
41 public:
42  SHAMapItem(uint256 const& tag, Blob const& data);
43  SHAMapItem(uint256 const& tag, Serializer const& s);
44  SHAMapItem(uint256 const& tag, Serializer&& s);
45 
46  Slice
47  slice() const;
48 
49  uint256 const&
50  key() const;
51 
52  Blob const&
53  peekData() const;
54 
56  size() const;
57  void const*
58  data() const;
59 };
60 
61 //------------------------------------------------------------------------------
62 
63 inline Slice
65 {
66  return {data_.data(), data_.size()};
67 }
68 
69 inline std::size_t
71 {
72  return data_.size();
73 }
74 
75 inline void const*
77 {
78  return data_.data();
79 }
80 
81 inline uint256 const&
83 {
84  return tag_;
85 }
86 
87 inline Blob const&
89 {
90  return data_;
91 }
92 
93 } // namespace ripple
94 
95 #endif
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
std::vector< unsigned char >
std::vector::size
T size(T... args)
ripple::SHAMapItem::SHAMapItem
SHAMapItem(uint256 const &tag, Blob const &data)
Definition: SHAMapItem.cpp:27
ripple::SHAMapItem::data_
Blob data_
Definition: SHAMapItem.h:39
ripple::base_uint< 256 >
ripple::SHAMapItem::tag_
uint256 tag_
Definition: SHAMapItem.h:38
ripple::SHAMapItem::key
uint256 const & key() const
Definition: SHAMapItem.h:82
ripple::SHAMapItem
Definition: SHAMapItem.h:35
cstddef
ripple::SHAMapItem::size
std::size_t size() const
Definition: SHAMapItem.h:70
ripple::SHAMapItem::data
void const * data() const
Definition: SHAMapItem.h:76
ripple::SHAMapItem::slice
Slice slice() const
Definition: SHAMapItem.h:64
ripple::Serializer
Definition: Serializer.h:39
ripple::SHAMapItem::peekData
Blob const & peekData() const
Definition: SHAMapItem.h:88
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::size_t
std::vector::data
T data(T... args)