rippled
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 <ripple/protocol/STBase.h>
21 #include <boost/checked_delete.hpp>
22 #include <cassert>
23 #include <memory>
24 
25 namespace ripple {
26 
28 {
29 }
30 
31 STBase::STBase(SField const& n) : fName(&n)
32 {
33  assert(fName);
34 }
35 
36 STBase&
38 {
39  if (!fName->isUseful())
40  fName = t.fName;
41  return *this;
42 }
43 
44 bool
45 STBase::operator==(const STBase& t) const
46 {
47  return (getSType() == t.getSType()) && isEquivalent(t);
48 }
49 
50 bool
51 STBase::operator!=(const STBase& t) const
52 {
53  return (getSType() != t.getSType()) || !isEquivalent(t);
54 }
55 
58 {
59  return STI_NOTPRESENT;
60 }
61 
64 {
65  std::string ret;
66 
67  if (getSType() != STI_NOTPRESENT)
68  {
69  if (fName->hasName())
70  {
71  ret = fName->fieldName;
72  ret += " = ";
73  }
74 
75  ret += getText();
76  }
77 
78  return ret;
79 }
80 
83 {
84  return std::string();
85 }
86 
88 {
89  return getText();
90 }
91 
92 void
94 {
95  // Should never be called
96  assert(false);
97 }
98 
99 bool
101 {
102  assert(getSType() == STI_NOTPRESENT);
103  return t.getSType() == STI_NOTPRESENT;
104 }
105 
106 bool
108 {
109  return true;
110 }
111 
112 void
114 {
115  fName = &n;
116  assert(fName);
117 }
118 
119 SField const&
121 {
122  return *fName;
123 }
124 
125 void
127 {
128  assert(fName->isBinary());
130 }
131 
132 //------------------------------------------------------------------------------
133 
136 {
137  return out << t.getFullText();
138 }
139 
140 } // namespace ripple
ripple::STBase::operator=
STBase & operator=(const STBase &t)
Definition: STBase.cpp:37
ripple::STBase::STBase
STBase()
Definition: STBase.cpp:27
ripple::STBase::getSType
virtual SerializedTypeID getSType() const
Definition: STBase.cpp:57
std::string
STL class.
ripple::STBase::isEquivalent
virtual bool isEquivalent(STBase const &t) const
Definition: STBase.cpp:100
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::sfGeneric
const SField sfGeneric(access, 0)
Definition: SField.h:332
ripple::SField::fieldValue
const int fieldValue
Definition: SField.h:128
ripple::Serializer::addFieldID
int addFieldID(int type, int name)
Definition: Serializer.cpp:124
ripple::SField::isBinary
bool isBinary() const
Definition: SField.h:210
ripple::STBase::add
virtual void add(Serializer &s) const
Definition: STBase.cpp:93
ripple::STBase::addFieldID
void addFieldID(Serializer &s) const
Definition: STBase.cpp:126
ripple::SField::fieldName
const std::string fieldName
Definition: SField.h:129
ripple::SField::hasName
bool hasName() const
Definition: SField.h:178
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::SField::isUseful
bool isUseful() const
Definition: SField.h:200
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:242
ripple::SField::fieldType
const SerializedTypeID fieldType
Definition: SField.h:127
ripple::STBase::isDefault
virtual bool isDefault() const
Definition: STBase.cpp:107
ripple::QualityDirection::out
@ out
std::ostream
STL class.
ripple::STBase::setFName
void setFName(SField const &n)
A STBase is a field.
Definition: STBase.cpp:113
memory
ripple::STBase::getText
virtual std::string getText() const
Definition: STBase.cpp:82
ripple::STBase::getFullText
virtual std::string getFullText() const
Definition: STBase.cpp:63
ripple::STBase::getFName
SField const & getFName() const
Definition: STBase.cpp:120
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SField
Identifies fields.
Definition: SField.h:109
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:62
ripple::STBase::operator!=
bool operator!=(const STBase &t) const
Definition: STBase.cpp:51
cassert
ripple::STBase::fName
SField const * fName
Definition: STBase.h:145
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:45
ripple::STBase::getJson
virtual Json::Value getJson(JsonOptions) const
Definition: STBase.cpp:87
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::STI_NOTPRESENT
@ STI_NOTPRESENT
Definition: SField.h:56