rippled
NodeObject.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_NODESTORE_NODEOBJECT_H_INCLUDED
21 #define RIPPLE_NODESTORE_NODEOBJECT_H_INCLUDED
22 
23 #include <ripple/basics/Blob.h>
24 #include <ripple/basics/CountedObject.h>
25 #include <ripple/protocol/Protocol.h>
26 
27 // VFALCO NOTE Intentionally not in the NodeStore namespace
28 
29 namespace ripple {
30 
34  hotLEDGER = 1,
37  hotDUMMY = 512 // an invalid or missing object
38 };
39 
49 class NodeObject : public CountedObject<NodeObject>
50 {
51 public:
52  static constexpr std::size_t keyBytes = 32;
53 
54 private:
55  // This hack is used to make the constructor effectively private
56  // except for when we use it in the call to make_shared.
57  // There's no portable way to make make_shared<> a friend work.
59  {
60  explicit PrivateAccess() = default;
61  };
62 
63 public:
64  // This constructor is private, use createObject instead.
65  NodeObject(
66  NodeObjectType type,
67  Blob&& data,
68  uint256 const& hash,
70 
83  createObject(NodeObjectType type, Blob&& data, uint256 const& hash);
84 
87  getType() const;
88 
90  uint256 const&
91  getHash() const;
92 
94  Blob const&
95  getData() const;
96 
97 private:
99  uint256 const mHash;
100  Blob const mData;
101 };
102 
103 } // namespace ripple
104 
105 #endif
ripple::hotUNKNOWN
@ hotUNKNOWN
Definition: NodeObject.h:33
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::shared_ptr< NodeObject >
ripple::hotACCOUNT_NODE
@ hotACCOUNT_NODE
Definition: NodeObject.h:35
std::vector< unsigned char >
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
ripple::NodeObject::createObject
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
Definition: NodeObject.cpp:37
ripple::NodeObject::mHash
const uint256 mHash
Definition: NodeObject.h:99
ripple::NodeObject::PrivateAccess::PrivateAccess
PrivateAccess()=default
ripple::hotTRANSACTION_NODE
@ hotTRANSACTION_NODE
Definition: NodeObject.h:36
ripple::NodeObject::mData
const Blob mData
Definition: NodeObject.h:100
ripple::NodeObject::getData
Blob const & getData() const
Returns the underlying data.
Definition: NodeObject.cpp:56
ripple::NodeObject::getType
NodeObjectType getType() const
Returns the type of this object.
Definition: NodeObject.cpp:44
ripple::base_uint< 256 >
ripple::hotDUMMY
@ hotDUMMY
Definition: NodeObject.h:37
std::uint32_t
ripple::NodeObject::mType
const NodeObjectType mType
Definition: NodeObject.h:98
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeObject::keyBytes
static constexpr std::size_t keyBytes
Definition: NodeObject.h:52
ripple::NodeObject::getHash
uint256 const & getHash() const
Returns the hash of the data.
Definition: NodeObject.cpp:50
std::size_t
ripple::hotLEDGER
@ hotLEDGER
Definition: NodeObject.h:34
ripple::NodeObject
A simple object that the Ledger uses to store entries.
Definition: NodeObject.h:49
ripple::NodeObject::NodeObject
NodeObject(NodeObjectType type, Blob &&data, uint256 const &hash, PrivateAccess)
Definition: NodeObject.cpp:27
ripple::NodeObject::PrivateAccess
Definition: NodeObject.h:58