//------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled Copyright (c) 2012, 2013 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #ifndef RIPPLE_PROTOCOL_STINTEGER_H_INCLUDED #define RIPPLE_PROTOCOL_STINTEGER_H_INCLUDED #include #include namespace ripple { template class STInteger : public STBase, public CountedObject> { public: using value_type = Integer; private: Integer value_; public: explicit STInteger(Integer v); STInteger(SField const& n, Integer v = 0); STInteger(SerialIter& sit, SField const& name); SerializedTypeID getSType() const override; Json::Value getJson(JsonOptions) const override; std::string getText() const override; void add(Serializer& s) const override; bool isDefault() const override; bool isEquivalent(const STBase& t) const override; STInteger& operator=(value_type const& v); value_type value() const noexcept; void setValue(Integer v); operator Integer() const; private: STBase* copy(std::size_t n, void* buf) const override; STBase* move(std::size_t n, void* buf) override; friend class ripple::detail::STVar; }; using STUInt8 = STInteger; using STUInt16 = STInteger; using STUInt32 = STInteger; using STUInt64 = STInteger; template inline STInteger::STInteger(Integer v) : value_(v) { } template inline STInteger::STInteger(SField const& n, Integer v) : STBase(n), value_(v) { } template inline STBase* STInteger::copy(std::size_t n, void* buf) const { return emplace(n, buf, *this); } template inline STBase* STInteger::move(std::size_t n, void* buf) { return emplace(n, buf, std::move(*this)); } template inline void STInteger::add(Serializer& s) const { XRPL_ASSERT( getFName().isBinary(), "ripple::STInteger::add : field is binary"); XRPL_ASSERT( getFName().fieldType == getSType(), "ripple::STInteger::add : field type match"); s.addInteger(value_); } template inline bool STInteger::isDefault() const { return value_ == 0; } template inline bool STInteger::isEquivalent(const STBase& t) const { const STInteger* v = dynamic_cast(&t); return v && (value_ == v->value_); } template inline STInteger& STInteger::operator=(value_type const& v) { value_ = v; return *this; } template inline typename STInteger::value_type STInteger::value() const noexcept { return value_; } template inline void STInteger::setValue(Integer v) { value_ = v; } template inline STInteger::operator Integer() const { return value_; } } // namespace ripple #endif