rippled
Loading...
Searching...
No Matches
STBase.cpp
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#include <xrpl/beast/utility/instrumentation.h>
21#include <xrpl/protocol/STBase.h>
22#include <boost/checked_delete.hpp>
23
24namespace ripple {
25
27{
28}
29
30STBase::STBase(SField const& n) : fName(&n)
31{
32 XRPL_ASSERT(fName, "ripple::STBase::STBase : field is set");
33}
34
35STBase&
37{
38 if (!fName->isUseful())
39 fName = t.fName;
40 return *this;
41}
42
43bool
45{
46 return (getSType() == t.getSType()) && isEquivalent(t);
47}
48
49bool
51{
52 return (getSType() != t.getSType()) || !isEquivalent(t);
53}
54
55STBase*
56STBase::copy(std::size_t n, void* buf) const
57{
58 return emplace(n, buf, *this);
59}
60
61STBase*
63{
64 return emplace(n, buf, std::move(*this));
65}
66
69{
70 return STI_NOTPRESENT;
71}
72
75{
76 std::string ret;
77
78 if (getSType() != STI_NOTPRESENT)
79 {
80 if (fName->hasName())
81 {
82 ret = fName->fieldName;
83 ret += " = ";
84 }
85
86 ret += getText();
87 }
88
89 return ret;
90}
91
94{
95 return std::string();
96}
97
99STBase::getJson(JsonOptions /*options*/) const
100{
101 return getText();
102}
103
104void
106{
107 // Should never be called
108 UNREACHABLE("ripple::STBase::add : not implemented");
109}
110
111bool
113{
114 XRPL_ASSERT(
115 getSType() == STI_NOTPRESENT,
116 "ripple::STBase::isEquivalent : type not present");
117 return t.getSType() == STI_NOTPRESENT;
118}
119
120bool
122{
123 return true;
124}
125
126void
128{
129 fName = &n;
130 XRPL_ASSERT(fName, "ripple::STBase::setFName : field is set");
131}
132
133SField const&
135{
136 return *fName;
137}
138
139void
141{
142 XRPL_ASSERT(
143 fName->isBinary(), "ripple::STBase::addFieldID : field is binary");
145}
146
147//------------------------------------------------------------------------------
148
151{
152 return out << t.getFullText();
153}
154
155} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
Identifies fields.
Definition: SField.h:144
bool hasName() const
Definition: SField.h:213
std::string const fieldName
Definition: SField.h:164
bool isBinary() const
Definition: SField.h:242
int const fieldValue
Definition: SField.h:163
bool isUseful() const
Definition: SField.h:236
SerializedTypeID const fieldType
Definition: SField.h:162
A type which can be exported to a well known binary format.
Definition: STBase.h:124
void setFName(SField const &n)
A STBase is a field.
Definition: STBase.cpp:127
virtual STBase * move(std::size_t n, void *buf)
Definition: STBase.cpp:62
virtual bool isEquivalent(STBase const &t) const
Definition: STBase.cpp:112
virtual SerializedTypeID getSType() const
Definition: STBase.cpp:68
bool operator!=(const STBase &t) const
Definition: STBase.cpp:50
virtual std::string getText() const
Definition: STBase.cpp:93
SField const & getFName() const
Definition: STBase.cpp:134
STBase & operator=(const STBase &t)
Definition: STBase.cpp:36
SField const * fName
Definition: STBase.h:125
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:222
void addFieldID(Serializer &s) const
Definition: STBase.cpp:140
virtual std::string getFullText() const
Definition: STBase.cpp:74
virtual void add(Serializer &s) const
Definition: STBase.cpp:105
bool operator==(const STBase &t) const
Definition: STBase.cpp:44
virtual STBase * copy(std::size_t n, void *buf) const
Definition: STBase.cpp:56
virtual bool isDefault() const
Definition: STBase.cpp:121
virtual Json::Value getJson(JsonOptions) const
Definition: STBase.cpp:99
int addFieldID(int type, int name)
Definition: Serializer.cpp:107
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
SerializedTypeID
Definition: SField.h:108
SField const sfGeneric
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:636
Note, should be treated as flags that can be | and &.
Definition: STBase.h:36