21 #include "ns3/core-module.h"
22 #include "ns3/length.h"
45 std::cout <<
"\nConstructors:"
46 <<
"\nLength (" << input <<
", Unit::Meter) = " <<
Length (input, Length::Unit::Meter)
47 <<
"\nLength (" << input <<
", \"m\") = " <<
Length (input,
"m")
48 <<
"\nLength (" << input <<
", \"meter\") = " <<
Length (input,
"meter")
49 <<
"\nLength (Quantity(" << input <<
", Unit::Meter)) = " <<
Length (quantity)
50 <<
"\nLength (\"5m\") = " <<
Length (
"5m")
51 <<
"\nLength (\"5 m\") = " <<
Length (
"5 m")
52 <<
"\nLength (\"5meter\") = " <<
Length (
"5meter")
53 <<
"\nLength (\"5 meter\") = " <<
Length (
"5 meter")
54 <<
"\nLength (\"5meters\") = " <<
Length (
"5meters")
55 <<
"\nLength (\"5 meters\") = " <<
Length (
"5 meters")
67 Length moonDistance (3.84402e8, Length::Unit::Meter);
70 std::cout <<
"\nConversions: "
71 <<
"\nDistance to moon = " << moonDistance
72 <<
"\nIn Feet: " << moonDistance.
As (Length::Unit::Foot)
73 <<
"\nIn Miles: " << moonDistance.
As (Length::Unit::Mile)
74 <<
"\nIn Kilometers: " << moonDistance.
As (Length::Unit::Kilometer)
91 std::cout <<
"\nArithmetic Operations:"
92 <<
"\nAddition: " << oneMeter <<
" + " << oneMeter <<
" = "
93 << (oneMeter + oneMeter)
94 <<
"\nSubtraction: " << oneMeter <<
" - " << oneMeter <<
" = "
95 << (oneMeter - oneMeter)
96 <<
"\nMultiplication By Scalar: " << oneMeter <<
" * " << scale <<
" = "
98 <<
"\nDivision: " << oneMeter <<
" / " << twoMeter <<
" = "
99 << (oneMeter / twoMeter)
100 <<
"\nDivision By Scalar: " << oneMeter <<
" / " << scale <<
" = "
101 << (oneMeter / scale)
117 std::cout <<
"\nComparison Operations:" << std::boolalpha
118 <<
"\nEquality: " << oneMeter <<
" == " << oneMeter <<
" is "
119 << (oneMeter == oneMeter)
120 <<
"\nEquality: " << oneMeter <<
" == " << twoMeter <<
" is "
121 << (oneMeter == twoMeter)
122 <<
"\nInequality: " << oneMeter <<
" != " << oneMeter <<
" is "
123 << (oneMeter != oneMeter)
124 <<
"\nInequality: " << oneMeter <<
" != " << twoMeter <<
" is "
125 << (oneMeter != twoMeter)
126 <<
"\nLesser: " << oneMeter <<
" < " << oneMeter <<
" is "
127 << (oneMeter < oneMeter)
128 <<
"\nLesser: " << oneMeter <<
" < " << twoMeter <<
" is "
129 << (oneMeter < twoMeter)
130 <<
"\nLesser: " << threeMeter <<
" < " << oneMeter <<
" is "
131 << (threeMeter < oneMeter)
132 <<
"\nGreater: " << oneMeter <<
" > " << oneMeter <<
" is "
133 << (oneMeter > oneMeter)
134 <<
"\nGreater: " << oneMeter <<
" > " << twoMeter <<
" is "
135 << (oneMeter > twoMeter)
136 <<
"\nGreater: " << threeMeter <<
" > " << oneMeter <<
" is "
137 << (threeMeter > oneMeter)
153 int64_t count =
Div (totalLen, pieceLen, &remainder);
155 std::cout <<
"\nHow many times can a " << totalLen.
As (Length::Unit::Foot) <<
" length "
156 <<
"be split into " << pieceLen.
As (Length::Unit::Foot) <<
" sized pieces? "
158 <<
"\nremainder: " << remainder.
As (Length::Unit::Foot)
161 std::cout <<
"\nHow much remains after splitting a "
162 << totalLen.
As (Length::Unit::Foot) <<
" length into "
163 << pieceLen.
As (Length::Unit::Foot) <<
" sized pieces? "
164 <<
Mod (totalLen, pieceLen).
As (Length::Unit::Foot)
168 int 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.
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.
void Conversions()
Demonstrates the use of ns3::Length conversions.
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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.