rippled
Loading...
Searching...
No Matches
Rate.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2015 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_RATE_H_INCLUDED
21#define RIPPLE_PROTOCOL_RATE_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/protocol/STAmount.h>
25
26#include <boost/operators.hpp>
27
28#include <cstdint>
29#include <ostream>
30
31namespace ripple {
32
39struct Rate : private boost::totally_ordered<Rate>
40{
42
43 Rate() = delete;
44
45 explicit Rate(std::uint32_t rate) : value(rate)
46 {
47 }
48};
49
50inline bool
51operator==(Rate const& lhs, Rate const& rhs) noexcept
52{
53 return lhs.value == rhs.value;
54}
55
56inline bool
57operator<(Rate const& lhs, Rate const& rhs) noexcept
58{
59 return lhs.value < rhs.value;
60}
61
63operator<<(std::ostream& os, Rate const& rate)
64{
65 os << rate.value;
66 return os;
67}
68
69STAmount
70multiply(STAmount const& amount, Rate const& rate);
71
72STAmount
73multiplyRound(STAmount const& amount, Rate const& rate, bool roundUp);
74
75STAmount
77 STAmount const& amount,
78 Rate const& rate,
79 Asset const& asset,
80 bool roundUp);
81
82STAmount
83divide(STAmount const& amount, Rate const& rate);
84
85STAmount
86divideRound(STAmount const& amount, Rate const& rate, bool roundUp);
87
88STAmount
90 STAmount const& amount,
91 Rate const& rate,
92 Asset const& asset,
93 bool roundUp);
94
95namespace nft {
97Rate
99
100} // namespace nft
101
103extern Rate const parityRate;
104
105} // namespace ripple
106
107#endif
Rate transferFeeAsRate(std::uint16_t fee)
Given a transfer fee (in basis points) convert it to a transfer rate.
Definition Rate2.cpp:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
STAmount divide(STAmount const &amount, Rate const &rate)
Definition Rate2.cpp:93
STAmount multiply(STAmount const &amount, Rate const &rate)
Definition Rate2.cpp:53
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition base_uint.h:647
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition Rate2.cpp:104
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:223
STAmount multiplyRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition Rate2.cpp:64
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition base_uint.h:585
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
Represents a transfer rate.
Definition Rate.h:40
Rate(std::uint32_t rate)
Definition Rate.h:45
std::uint32_t value
Definition Rate.h:41
Rate()=delete