rippled
Loading...
Searching...
No Matches
STAccount.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_PROTOCOL_STACCOUNT_H_INCLUDED
21#define RIPPLE_PROTOCOL_STACCOUNT_H_INCLUDED
22
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/protocol/AccountID.h>
25#include <xrpl/protocol/STBase.h>
26
27#include <string>
28
29namespace ripple {
30
31class STAccount final : public STBase, public CountedObject<STAccount>
32{
33private:
34 // The original implementation of STAccount kept the value in an STBlob.
35 // But an STAccount is always 160 bits, so we can store it with less
36 // overhead in a ripple::uint160. However, so the serialized format of the
37 // STAccount stays unchanged, we serialize and deserialize like an STBlob.
40
41public:
43
44 STAccount();
45
46 STAccount(SField const& n);
47 STAccount(SField const& n, Buffer&& v);
48 STAccount(SerialIter& sit, SField const& name);
49 STAccount(SField const& n, AccountID const& v);
50
52 getSType() const override;
53
55 getText() const override;
56
57 void
58 add(Serializer& s) const override;
59
60 bool
61 isEquivalent(const STBase& t) const override;
62
63 bool
64 isDefault() const override;
65
68
69 AccountID const&
70 value() const noexcept;
71
72 void
73 setValue(AccountID const& v);
74
75private:
76 STBase*
77 copy(std::size_t n, void* buf) const override;
78 STBase*
79 move(std::size_t n, void* buf) override;
80
81 friend class detail::STVar;
82};
83
84inline STAccount&
85STAccount::operator=(AccountID const& value)
86{
88 return *this;
89}
90
91inline AccountID const&
92STAccount::value() const noexcept
93{
94 return value_;
95}
96
97inline void
99{
100 value_ = v;
101 default_ = false;
102}
103
104inline bool
105operator==(STAccount const& lhs, STAccount const& rhs)
106{
107 return lhs.value() == rhs.value();
108}
109
110inline auto
111operator<(STAccount const& lhs, STAccount const& rhs)
112{
113 return lhs.value() < rhs.value();
114}
115
116inline bool
117operator==(STAccount const& lhs, AccountID const& rhs)
118{
119 return lhs.value() == rhs;
120}
121
122inline auto
123operator<(STAccount const& lhs, AccountID const& rhs)
124{
125 return lhs.value() < rhs;
126}
127
128inline auto
129operator<(AccountID const& lhs, STAccount const& rhs)
130{
131 return lhs < rhs.value();
132}
133
134} // namespace ripple
135
136#endif
Like std::vector<char> but better.
Definition: Buffer.h:36
Tracks the number of instances of an object.
Identifies fields.
Definition: SField.h:144
void add(Serializer &s) const override
Definition: STAccount.cpp:81
AccountID const & value() const noexcept
Definition: STAccount.h:92
bool isEquivalent(const STBase &t) const override
Definition: STAccount.cpp:97
void setValue(AccountID const &v)
Definition: STAccount.h:98
STAccount & operator=(AccountID const &value)
Definition: STAccount.h:85
friend class detail::STVar
Definition: STAccount.h:81
STBase * copy(std::size_t n, void *buf) const override
Definition: STAccount.cpp:63
SerializedTypeID getSType() const override
Definition: STAccount.cpp:75
STBase * move(std::size_t n, void *buf) override
Definition: STAccount.cpp:69
bool isDefault() const override
Definition: STAccount.cpp:104
std::string getText() const override
Definition: STAccount.cpp:110
AccountID value_
Definition: STAccount.h:38
A type which can be exported to a well known binary format.
Definition: STBase.h:124
bool operator==(const STBase &t) const
Definition: STBase.cpp:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
SerializedTypeID
Definition: SField.h:108
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition: Slice.h:222
STL namespace.