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/protocol/AccountID.h>
24 #include <ripple/protocol/STBase.h>
25 #include <string>
26 
27 namespace ripple {
28 
29 class STAccount final : public STBase
30 {
31 private:
32  // The original implementation of STAccount kept the value in an STBlob.
33  // But an STAccount is always 160 bits, so we can store it with less
34  // overhead in a ripple::uint160. However, so the serialized format of the
35  // STAccount stays unchanged, we serialize and deserialize like an STBlob.
37  bool default_;
38 
39 public:
41 
42  STAccount();
43 
44  STAccount(SField const& n);
45  STAccount(SField const& n, Buffer&& v);
46  STAccount(SerialIter& sit, SField const& name);
47  STAccount(SField const& n, AccountID const& v);
48 
50  getSType() const override;
51 
53  getText() const override;
54 
55  void
56  add(Serializer& s) const override;
57 
58  bool
59  isEquivalent(const STBase& t) const override;
60 
61  bool
62  isDefault() const override;
63 
64  STAccount&
65  operator=(AccountID const& value);
66 
67  AccountID
68  value() const noexcept;
69 
70  void
71  setValue(AccountID const& v);
72 
73 private:
74  STBase*
75  copy(std::size_t n, void* buf) const override;
76  STBase*
77  move(std::size_t n, void* buf) override;
78 
79  friend class detail::STVar;
80 };
81 
82 inline STAccount&
83 STAccount::operator=(AccountID const& value)
84 {
85  setValue(value);
86  return *this;
87 }
88 
89 inline AccountID
90 STAccount::value() const noexcept
91 {
92  return value_;
93 }
94 
95 inline void
97 {
98  value_ = v;
99  default_ = false;
100 }
101 
102 } // namespace ripple
103 
104 #endif
std::string
STL class.
ripple::STAccount::getSType
SerializedTypeID getSType() const override
Definition: STAccount.cpp:75
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
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:37
ripple::STAccount::setValue
void setValue(AccountID const &v)
Definition: STAccount.h:96
ripple::base_uint< 160, detail::AccountIDTag >
ripple::STAccount::value_
AccountID value_
Definition: STAccount.h:36
ripple::SerialIter
Definition: Serializer.h:310
ripple::STAccount::add
void add(Serializer &s) const override
Definition: STAccount.cpp:81
ripple::STAccount::value
AccountID value() const noexcept
Definition: STAccount.h:90
ripple::Serializer
Definition: Serializer.h:39
ripple::STAccount
Definition: STAccount.h:29
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:112
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
std
STL namespace.
ripple::STAccount::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STAccount.cpp:63
ripple::STAccount::operator=
STAccount & operator=(AccountID const &value)
Definition: STAccount.h:83
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:47
string