rippled
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 <ripple/protocol/STAmount.h>
24 #include <boost/operators.hpp>
25 #include <cassert>
26 #include <cstdint>
27 #include <ostream>
28 
29 namespace ripple {
30 
37 struct Rate : private boost::totally_ordered<Rate>
38 {
40 
41  Rate() = delete;
42 
43  explicit Rate(std::uint32_t rate) : value(rate)
44  {
45  }
46 };
47 
48 inline bool
49 operator==(Rate const& lhs, Rate const& rhs) noexcept
50 {
51  return lhs.value == rhs.value;
52 }
53 
54 inline bool
55 operator<(Rate const& lhs, Rate const& rhs) noexcept
56 {
57  return lhs.value < rhs.value;
58 }
59 
60 inline std::ostream&
61 operator<<(std::ostream& os, Rate const& rate)
62 {
63  os << rate.value;
64  return os;
65 }
66 
67 STAmount
68 multiply(STAmount const& amount, Rate const& rate);
69 
70 STAmount
71 multiplyRound(STAmount const& amount, Rate const& rate, bool roundUp);
72 
73 STAmount
75  STAmount const& amount,
76  Rate const& rate,
77  Issue const& issue,
78  bool roundUp);
79 
80 STAmount
81 divide(STAmount const& amount, Rate const& rate);
82 
83 STAmount
84 divideRound(STAmount const& amount, Rate const& rate, bool roundUp);
85 
86 STAmount
88  STAmount const& amount,
89  Rate const& rate,
90  Issue const& issue,
91  bool roundUp);
92 
93 namespace nft {
95 Rate
97 
98 } // namespace nft
99 
101 extern Rate const parityRate;
102 
103 } // namespace ripple
104 
105 #endif
ripple::Rate
Represents a transfer rate.
Definition: Rate.h:37
ripple::nft::transferFeeAsRate
Rate transferFeeAsRate(std::uint16_t fee)
Given a transfer fee (in basis points) convert it to a transfer rate.
Definition: Rate2.cpp:39
ripple::multiplyRound
STAmount multiplyRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition: Rate2.cpp:58
ripple::divideRound
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition: Rate2.cpp:97
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:242
ripple::parityRate
const Rate parityRate(QUALITY_ONE)
A transfer rate signifying a 1:1 exchange.
Definition: Rate.h:101
ripple::operator==
bool operator==(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:165
ripple::divide
STAmount divide(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:86
ripple::Rate::Rate
Rate(std::uint32_t rate)
Definition: Rate.h:43
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
std::ostream
STL class.
cstdint
std::uint32_t
ripple::multiply
STAmount multiply(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:47
ripple::Rate::value
std::uint32_t value
Definition: Rate.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
cassert
ripple::Rate::Rate
Rate()=delete
ostream