roo_quantity
API Documentation for roo_quantity
Loading...
Searching...
No Matches
volume_flow_rate.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4
5#include "roo_flags.h"
6#include "roo_logging.h"
7#include "roo_quantity/time.h"
9
10#if defined(ESP32) || defined(ESP8266) || defined(__linux__)
11#include <string>
12#endif
13
14#if defined(ARDUINO)
15#include <Arduino.h>
16#endif
17
18namespace roo_quantity {
19
20/// Representation of volume flow rate, internally stored as floating-point
21/// cubic meters per second.
23 public:
24 /// Creates a volume flow rate object representing an 'unknown' volume flow
25 /// rate.
26 VolumeFlowRate() : volume_flow_rate_(std::nanf("")) {}
27
28 /// Returns the volume flow rate in cubic meters per second.
29 float inCubicMetersPerSecond() const { return volume_flow_rate_; }
30
31 /// Returns the volume flow rate in liters per second.
32 float inLitersPerSecond() const { return volume_flow_rate_ * 1000.0f; }
33
34 /// Returns the volume flow rate in milliliters per second.
35 float inMillilitersPerSecond() const {
36 return volume_flow_rate_ * 1000000.0f;
37 }
38
39 /// Returns whether the object represents an unknown volume flow rate.
40 bool isUnknown() const { return std::isnan(volume_flow_rate_); }
41
42 bool operator<(const VolumeFlowRate& other) const {
43 return volume_flow_rate_ < other.volume_flow_rate_;
44 }
45
46 bool operator==(const VolumeFlowRate& other) const {
47 return volume_flow_rate_ == other.volume_flow_rate_;
48 }
49
50 bool operator>(const VolumeFlowRate& other) const {
51 return other.volume_flow_rate_ < volume_flow_rate_;
52 }
53
54 bool operator<=(const VolumeFlowRate& other) const {
55 return !(other.volume_flow_rate_ < volume_flow_rate_);
56 }
57
58 bool operator>=(const VolumeFlowRate& other) const {
59 return !(volume_flow_rate_ < other.volume_flow_rate_);
60 }
61
62 bool operator!=(const VolumeFlowRate& other) const {
63 return !(volume_flow_rate_ == other.volume_flow_rate_);
64 }
65
67 volume_flow_rate_ += other.inCubicMetersPerSecond();
68 return *this;
69 }
70
72 volume_flow_rate_ -= other.inCubicMetersPerSecond();
73 return *this;
74 }
75
76 inline VolumeFlowRate& operator*=(float multi) {
77 volume_flow_rate_ *= multi;
78 return *this;
79 }
80
81 inline VolumeFlowRate& operator/=(float div) {
82 volume_flow_rate_ /= div;
83 return *this;
84 }
85
86#if defined(ESP32) || defined(ESP8266) || defined(__linux__)
87 /// Returns the string representation of the volume flow rate.
88 std::string asString() const;
89#endif
90
91#if defined(ARDUINO)
92 String asArduinoString() const;
93#endif
94
95 private:
97
99
100 explicit VolumeFlowRate(float volume_flow_rate)
101 : volume_flow_rate_(volume_flow_rate) {}
102
103 /// Stored in cubic meters per second.
104 float volume_flow_rate_;
105};
106
107inline VolumeFlowRate VolumeFlowRateInCubicMetersPerSecond(
108 float volume_flow_rate);
109
110/// Returns a volume flow rate object representing an unknown volume flow rate.
112
113/// Returns a volume flow rate object equivalent to the specified volume flow
114/// rate expressed in cubic meters per second.
116 float volume_flow_rate) {
117 return VolumeFlowRate(volume_flow_rate);
118}
119
120/// Returns a volume flow rate object equivalent to the specified volume flow
121/// rate expressed in liters per second.
122inline VolumeFlowRate VolumeFlowRateInLitersPerSecond(float volume_flow_rate) {
123 return VolumeFlowRateInCubicMetersPerSecond(volume_flow_rate * 0.001f);
124}
125
126/// Returns a volume flow rate object equivalent to the specified volume flow
127/// rate expressed in milliliters per second.
129 float volume_flow_rate) {
130 return VolumeFlowRateInCubicMetersPerSecond(volume_flow_rate * 0.000001f);
131}
132
137
142
146
150
154
158
162
166
170
175
176roo_logging::Stream& operator<<(roo_logging::Stream& os, const VolumeFlowRate& val);
177
178} // namespace roo_quantity
Representation of elapsed, internally stored as floating-point seconds.
Definition time.h:22
float inSeconds() const
Returns the time in seconds.
Definition time.h:30
Representation of volume flow rate, internally stored as floating-point cubic meters per second.
bool isUnknown() const
Returns whether the object represents an unknown volume flow rate.
bool operator==(const VolumeFlowRate &other) const
bool operator>=(const VolumeFlowRate &other) const
VolumeFlowRate & operator+=(const VolumeFlowRate &other)
float inLitersPerSecond() const
Returns the volume flow rate in liters per second.
friend VolumeFlowRate UnknownVolumeFlowRate()
Returns a volume flow rate object representing an unknown volume flow rate.
VolumeFlowRate & operator*=(float multi)
float inMillilitersPerSecond() const
Returns the volume flow rate in milliliters per second.
bool operator<(const VolumeFlowRate &other) const
float inCubicMetersPerSecond() const
Returns the volume flow rate in cubic meters per second.
VolumeFlowRate & operator/=(float div)
VolumeFlowRate & operator-=(const VolumeFlowRate &other)
bool operator!=(const VolumeFlowRate &other) const
bool operator<=(const VolumeFlowRate &other) const
friend VolumeFlowRate VolumeFlowRateInCubicMetersPerSecond(float)
Returns a volume flow rate object equivalent to the specified volume flow rate expressed in cubic met...
bool operator>(const VolumeFlowRate &other) const
VolumeFlowRate()
Creates a volume flow rate object representing an 'unknown' volume flow rate.
Representation of volume, internally stored as floating-point cubic meters.
Definition volume.h:21
float inCubicMeters() const
Returns the volume in cubic meters.
Definition volume.h:30
For convenience conversion from roo_time::Duration.
Definition area.cpp:3
roo_logging::Stream & operator<<(roo_logging::Stream &os, const Area &val)
Definition area.cpp:57
Volume VolumeInCubicMeters(float volume)
Returns a volume object equivalent to the specified volume expressed in cubic meters.
Definition volume.h:132
VolumeFlowRate VolumeFlowRateInCubicMetersPerSecond(float volume_flow_rate)
Returns a volume flow rate object equivalent to the specified volume flow rate expressed in cubic met...
Area operator+(Area a, Area b)
Definition area.h:171
Area operator-(Area a, Area b)
Definition area.h:175
VolumeFlowRate VolumeFlowRateInLitersPerSecond(float volume_flow_rate)
Returns a volume flow rate object equivalent to the specified volume flow rate expressed in liters pe...
VolumeFlowRate VolumeFlowRateInMillilitersPerSecond(float volume_flow_rate)
Returns a volume flow rate object equivalent to the specified volume flow rate expressed in millilite...
VolumeFlowRate UnknownVolumeFlowRate()
Returns a volume flow rate object representing an unknown volume flow rate.
Area operator/(Area a, float b)
Definition area.h:191
Area operator*(Area a, float b)
Definition area.h:183