20 #include "ns3/core-module.h"
21 #include "ns3/length.h"
49 std::cout <<
"\nConstructors:"
50 <<
"\nLength (" << input <<
", Unit::Meter) = " <<
Length(input, Length::Unit::Meter)
51 <<
"\nLength (" << input <<
", \"m\") = " <<
Length(input,
"m") <<
"\nLength ("
52 << input <<
", \"meter\") = " <<
Length(input,
"meter") <<
"\nLength (Quantity("
53 << input <<
", Unit::Meter)) = " <<
Length(quantity)
54 <<
"\nLength (\"5m\") = " <<
Length(
"5m") <<
"\nLength (\"5 m\") = " <<
Length(
"5 m")
55 <<
"\nLength (\"5meter\") = " <<
Length(
"5meter")
56 <<
"\nLength (\"5 meter\") = " <<
Length(
"5 meter")
57 <<
"\nLength (\"5meters\") = " <<
Length(
"5meters")
58 <<
"\nLength (\"5 meters\") = " <<
Length(
"5 meters") << std::endl;
69 Length moonDistance(3.84402e8, Length::Unit::Meter);
74 <<
"Distance to moon = " << moonDistance <<
"\n"
75 <<
"In Feet: " << moonDistance.
As(Length::Unit::Foot) <<
"\n"
76 <<
"In Miles: " << moonDistance.
As(Length::Unit::Mile) <<
"\n"
77 <<
"In Kilometers: " << moonDistance.
As(Length::Unit::Kilometer) << std::endl;
94 <<
"Arithmetic Operations:\n"
95 <<
"Addition: " << oneMeter <<
" + " << twoMeter <<
" = " << (oneMeter + twoMeter)
97 <<
"Subtraction: " << twoMeter <<
" - " << oneMeter <<
" = " << (twoMeter - oneMeter)
99 <<
"Multiplication By Scalar: " << oneMeter <<
" * " << scale <<
" = "
100 << (oneMeter * scale) <<
"\n"
101 <<
"Division: " << oneMeter <<
" / " << twoMeter <<
" = " << (oneMeter / twoMeter)
103 <<
"Division By Scalar: " << oneMeter <<
" / " << scale <<
" = " << (oneMeter / scale)
120 <<
"Comparison Operations:\n"
121 << std::boolalpha <<
"Equality: " << oneMeter <<
" == " << oneMeter <<
" is "
122 << (oneMeter == oneMeter) <<
"\n"
123 <<
"Equality: " << oneMeter <<
" == " << twoMeter <<
" is " << (oneMeter == twoMeter)
125 <<
"Inequality: " << oneMeter <<
" != " << oneMeter <<
" is "
126 << (oneMeter != oneMeter) <<
"\n"
127 <<
"Inequality: " << oneMeter <<
" != " << twoMeter <<
" is "
128 << (oneMeter != twoMeter) <<
"\n"
129 <<
"Lesser: " << oneMeter <<
" < " << oneMeter <<
" is " << (oneMeter < oneMeter)
131 <<
"Lesser: " << oneMeter <<
" < " << twoMeter <<
" is " << (oneMeter < twoMeter)
133 <<
"Lesser: " << threeMeter <<
" < " << oneMeter <<
" is " << (threeMeter < oneMeter)
135 <<
"Greater: " << oneMeter <<
" > " << oneMeter <<
" is " << (oneMeter > oneMeter)
137 <<
"Greater: " << oneMeter <<
" > " << twoMeter <<
" is " << (oneMeter > twoMeter)
139 <<
"Greater: " << threeMeter <<
" > " << oneMeter <<
" is " << (threeMeter > oneMeter)
156 int64_t count =
Div(totalLen, pieceLen, &remainder);
158 std::cout <<
"\nHow many times can a " << totalLen.
As(Length::Unit::Foot) <<
" length "
159 <<
"be split into " << pieceLen.
As(Length::Unit::Foot) <<
" sized pieces? " << count
160 <<
"\nremainder: " << remainder.
As(Length::Unit::Foot) << std::endl;
162 std::cout <<
"\nHow much remains after splitting a " << totalLen.
As(Length::Unit::Foot)
163 <<
" length into " << pieceLen.
As(Length::Unit::Foot) <<
" sized pieces? "
164 <<
Mod(totalLen, pieceLen).
As(Length::Unit::Foot) << std::endl;
168 main(
int argc,
char** argv)
An immutable class which represents a value in a specific length unit.
Represents a length in meters.
Quantity As(Unit unit) const
Create a Quantity in a specific unit from a Length.
void Conversions()
Demonstrates the use of ns3::Length conversions.
void Constructors()
Demonstrates the use of ns3::Length constructors.
void EqualityOperators()
Demonstrates the use of ns3::Length equality operators.
void ArithmeticOperators()
Demonstrates the use of ns3::Length arithmetic operators.
void DivAndMod()
Demonstrates the use of ns3::Length multiplications and divisions.
Length Feet(double value)
Construct a length from a value in the indicated unit.
Length Mod(const Length &numerator, const Length &denominator)
Calculate the amount remaining after dividing two lengths.
Length Meters(double value)
Construct a length from a value in the indicated unit.
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
Calculate how many times numerator can be split into denominator sized pieces.
Every class exported by the ns3 library is enclosed in the ns3 namespace.