rippled
Loading...
Searching...
No Matches
Charge.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 <xrpl/resource/Charge.h>
21
22#include <compare>
23#include <ostream>
24#include <sstream>
25#include <string>
26
27namespace ripple {
28namespace Resource {
29
31 : m_cost(cost), m_label(label)
32{
33}
34
35std::string const&
37{
38 return m_label;
39}
40
43{
44 return m_cost;
45}
46
49{
51 ss << m_label << " ($" << m_cost << ")";
52 return ss.str();
53}
54
56operator<<(std::ostream& os, Charge const& v)
57{
58 os << v.to_string();
59 return os;
60}
61
62bool
64{
65 return c.m_cost == m_cost;
66}
67
69Charge::operator<=>(Charge const& c) const
70{
71 return m_cost <=> c.m_cost;
72}
73
76{
77 return Charge(m_cost * m, m_label);
78}
79
80} // namespace Resource
81} // namespace ripple
A consumption charge.
Definition Charge.h:30
int value_type
The type used to hold a consumption charge.
Definition Charge.h:33
Charge operator*(value_type m) const
Definition Charge.cpp:75
std::string m_label
Definition Charge.h:64
std::string to_string() const
Converts this charge into a human readable string.
Definition Charge.cpp:48
bool operator==(Charge const &) const
Definition Charge.cpp:63
value_type cost() const
Return the cost of the charge in Resource::Manager units.
Definition Charge.cpp:42
std::strong_ordering operator<=>(Charge const &) const
Definition Charge.cpp:69
std::string const & label() const
Return the human readable label associated with the charge.
Definition Charge.cpp:36
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition Charge.cpp:56
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
T str(T... args)