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 ((t.fName != fName) && fName->isUseful() && t.fName->isUseful())
40  {
41  // VFALCO We shouldn't be logging at this low a level
42  /*
43  WriteLog ((t.getSType () == STI_AMOUNT) ? lsTRACE : lsWARNING, STBase)
44  // This is common for amounts
45  << "Caution: " << t.fName->getName () << " not replacing " <<
46  fName->getName ();
47  */
48  }
49  if (!fName->isUseful())
50  fName = t.fName;
51  return *this;
52 }
53 
54 bool
55 STBase::operator==(const STBase& t) const
56 {
57  return (getSType() == t.getSType()) && isEquivalent(t);
58 }
59 
60 bool
61 STBase::operator!=(const STBase& t) const
62 {
63  return (getSType() != t.getSType()) || !isEquivalent(t);
64 }
65 
68 {
69  return STI_NOTPRESENT;
70 }
71 
74 {
75  std::string ret;
76 
77  if (getSType() != STI_NOTPRESENT)
78  {
79  if (fName->hasName())
80  {
81  ret = fName->fieldName;
82  ret += " = ";
83  }
84 
85  ret += getText();
86  }
87 
88  return ret;
89 }
90 
93 {
94  return std::string();
95 }
96 
98 {
99  return getText();
100 }
101 
102 void
104 {
105  // Should never be called
106  assert(false);
107 }
108 
109 bool
111 {
112  assert(getSType() == STI_NOTPRESENT);
113  if (t.getSType() == STI_NOTPRESENT)
114  return true;
115  // VFALCO We shouldn't be logging at this low a level
116  // WriteLog (lsDEBUG, STBase) << "notEquiv " << getFullText() << " not
117  // STI_NOTPRESENT";
118  return false;
119 }
120 
121 bool
123 {
124  return true;
125 }
126 
127 void
129 {
130  fName = &n;
131  assert(fName);
132 }
133 
134 SField const&
136 {
137  return *fName;
138 }
139 
140 void
142 {
143  assert(fName->isBinary());
145 }
146 
147 //------------------------------------------------------------------------------
148 
151 {
152  return out << t.getFullText();
153 }
154 
155 } // 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:67
std::string
STL class.
ripple::STBase::isEquivalent
virtual bool isEquivalent(STBase const &t) const
Definition: STBase.cpp:110
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:103
ripple::STBase::addFieldID
void addFieldID(Serializer &s) const
Definition: STBase.cpp:141
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:122
ripple::QualityDirection::out
@ out
std::ostream
STL class.
ripple::STBase::setFName
void setFName(SField const &n)
A STBase is a field.
Definition: STBase.cpp:128
memory
ripple::STBase::getText
virtual std::string getText() const
Definition: STBase.cpp:92
ripple::STBase::getFullText
virtual std::string getFullText() const
Definition: STBase.cpp:73
ripple::STBase::getFName
SField const & getFName() const
Definition: STBase.cpp:135
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:61
cassert
ripple::STBase::fName
SField const * fName
Definition: STBase.h:145
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:55
ripple::STBase::getJson
virtual Json::Value getJson(JsonOptions) const
Definition: STBase.cpp:97
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::STI_NOTPRESENT
@ STI_NOTPRESENT
Definition: SField.h:56