rippled
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 <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/AccountID.h>
25 #include <ripple/protocol/STBase.h>
26 
27 #include <string>
28 
29 namespace ripple {
30 
31 class STAccount final : public STBase, public CountedObject<STAccount>
32 {
33 private:
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.
39  bool default_;
40 
41 public:
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 
66  STAccount&
67  operator=(AccountID const& value);
68 
69  AccountID const&
70  value() const noexcept;
71 
72  void
73  setValue(AccountID const& v);
74 
75 private:
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 
84 inline STAccount&
85 STAccount::operator=(AccountID const& value)
86 {
87  setValue(value);
88  return *this;
89 }
90 
91 inline AccountID const&
92 STAccount::value() const noexcept
93 {
94  return value_;
95 }
96 
97 inline void
99 {
100  value_ = v;
101  default_ = false;
102 }
103 
104 inline bool
105 operator==(STAccount const& lhs, STAccount const& rhs)
106 {
107  return lhs.value() == rhs.value();
108 }
109 
110 inline auto
111 operator<(STAccount const& lhs, STAccount const& rhs)
112 {
113  return lhs.value() < rhs.value();
114 }
115 
116 inline bool
117 operator==(STAccount const& lhs, AccountID const& rhs)
118 {
119  return lhs.value() == rhs;
120 }
121 
122 inline auto
123 operator<(STAccount const& lhs, AccountID const& rhs)
124 {
125  return lhs.value() < rhs;
126 }
127 
128 inline auto
129 operator<(AccountID const& lhs, STAccount const& rhs)
130 {
131  return lhs < rhs.value();
132 }
133 
134 } // namespace ripple
135 
136 #endif
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
ripple::STAccount::getSType
SerializedTypeID getSType() const override
Definition: STAccount.cpp:75
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:104
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::STAccount::isDefault
bool isDefault() const override
Definition: STAccount.cpp:101
ripple::STAccount::STAccount
STAccount()
Definition: STAccount.cpp:26
ripple::STAccount::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STAccount.cpp:94
ripple::STAccount::default_
bool default_
Definition: STAccount.h:39
ripple::STAccount::setValue
void setValue(AccountID const &v)
Definition: STAccount.h:98
ripple::base_uint< 160, detail::AccountIDTag >
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::STAccount::value_
AccountID value_
Definition: STAccount.h:38
ripple::SerialIter
Definition: Serializer.h:311
ripple::STAccount::add
void add(Serializer &s) const override
Definition: STAccount.cpp:81
ripple::Serializer
Definition: Serializer.h:40
ripple::STAccount
Definition: STAccount.h:31
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STAccount::getText
std::string getText() const override
Definition: STAccount.cpp:107
ripple::SField
Identifies fields.
Definition: SField.h:139
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
std
STL namespace.
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:45
ripple::STAccount::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STAccount.cpp:63
ripple::STAccount::value
AccountID const & value() const noexcept
Definition: STAccount.h:92
ripple::STAccount::operator=
STAccount & operator=(AccountID const &value)
Definition: STAccount.h:85
ripple::STAccount::move
STBase * move(std::size_t n, void *buf) override
Definition: STAccount.cpp:69
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
string