A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
Length

Management of lengths in real world units. More...

+ Collaboration diagram for Length:

Modules

 Demonstrates usage of the ns3::Length class
 
 Length test suite
 

Files

file  length.cc
 ns3::Length implementation
 
file  length.h
 Declaration of ns3::Length class.
 

Namespaces

namespace  anonymous_namespace{length.cc}
 Unnamed namespace.
 

Classes

class  ns3::Length
 Represents a length in meters. More...
 

Functions

int64_t ns3::Div (const Length &numerator, const Length &denominator, Length *remainder=nullptr)
 Calculate how many times numerator can be split into denominator sized pieces.
 
std::optional< Length::Unitns3::FromString (std::string unitString)
 Find the equivalent Length::Unit for a unit string.
 
Length ns3::Mod (const Length &numerator, const Length &denominator)
 Calculate the amount remaining after dividing two lengths.
 
bool ns3::operator!= (const Length &left, const Length &right)
 Compare two length objects for inequality.
 
Length ns3::operator* (const Length &l, double scalar)
 Multiply a length value by a scalar.
 
Length ns3::operator* (double scalar, const Length &l)
 Multiply a length value by a scalar.
 
Length ns3::operator+ (const Length &left, const Length &right)
 Add two length values together.
 
Length ns3::operator- (const Length &left, const Length &right)
 Subtract two length values.
 
Length ns3::operator/ (const Length &left, double scalar)
 Divide a length value by a scalar.
 
double ns3::operator/ (const Length &numerator, const Length &denominator)
 Divide a length value by another length value.
 
bool ns3::operator< (const Length &left, const Length &right)
 Check if left has a value less than right.
 
std::ostream & ns3::operator<< (std::ostream &stream, const Length &l)
 Write a length value to an output stream.
 
std::ostream & ns3::operator<< (std::ostream &stream, const Length::Quantity &q)
 Write a Quantity to an output stream.
 
std::ostream & ns3::operator<< (std::ostream &stream, Length::Unit unit)
 Write a Length::Unit to an output stream.
 
bool ns3::operator<= (const Length &left, const Length &right)
 Check if left has a value less than or equal to right.
 
bool ns3::operator== (const Length &left, const Length &right)
 Compare two length objects for equality.
 
bool ns3::operator> (const Length &left, const Length &right)
 Check if left has a value greater than right.
 
bool ns3::operator>= (const Length &left, const Length &right)
 Check if left has a value greater than or equal to right.
 
std::istream & ns3::operator>> (std::istream &stream, Length &l)
 Read a length value from an input stream.
 
std::string ns3::ToName (Length::Unit unit, bool plural=false)
 Return the name of the supplied unit.
 
std::string ns3::ToSymbol (Length::Unit unit)
 Return the symbol of the supplied unit.
 
Length ns3::NanoMeters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::MicroMeters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::MilliMeters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::CentiMeters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::Meters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::KiloMeters (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::NauticalMiles (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::Inches (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::Feet (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::Yards (double value)
 Construct a length from a value in the indicated unit.
 
Length ns3::Miles (double value)
 Construct a length from a value in the indicated unit.
 

Detailed Description

Management of lengths in real world units.

Function Documentation

◆ CentiMeters()

Length ns3::CentiMeters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 805 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ Div()

int64_t ns3::Div ( const Length numerator,
const Length denominator,
Length remainder = nullptr 
)

Calculate how many times numerator can be split into denominator sized pieces.

If the result of numerator / denominator is not a whole number, the result is rounded toward zero to the nearest whole number. The amount remaining after the division can be retrieved by passing a pointer to a Length in remainder. The remainder will be less than denominator and have the same sign as numerator.

NS_FATAL_ERROR is called if denominator is 0.

Parameters
numeratorThe value to split
denominatorThe length of each split
remainderLocation to store the remainder
Returns
The number of times numerator can be split into denominator sized pieces, rounded down to the nearest whole number

Definition at line 482 of file length.cc.

References ns3::Length::GetDouble(), and NS_FATAL_ERROR.

Referenced by DivAndMod(), TimeSimpleTestCase::DoTimeOperations(), ns3::Ping::StartApplication(), LengthTestCase::TestDivReturnsCorrectRemainder(), LengthTestCase::TestDivReturnsCorrectResult(), and LengthTestCase::TestDivReturnsZeroRemainder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Feet()

Length ns3::Feet ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 835 of file length.cc.

Referenced by DivAndMod(), and LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ FromString()

std::optional< Length::Unit > ns3::FromString ( std::string  unitString)

Find the equivalent Length::Unit for a unit string.

The string value can be a symbol or name (plural or singular).

The string comparison ignores case so strings like "NanoMeter", "centiMeter", "METER" will all match the correct unit.

Leading and trailing whitespace are trimmed from the string before searching for a match.

Parameters
unitStringString containing the symbol or name of a length unit
Returns
A std::optional object containing a Length::Unit if a match for the string could be found

Definition at line 580 of file length.cc.

Referenced by ns3::Length::Length(), and ns3::Length::TryParse().

+ Here is the caller graph for this function:

◆ Inches()

Length ns3::Inches ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 829 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ KiloMeters()

Length ns3::KiloMeters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 817 of file length.cc.

Referenced by LengthValueTestCase::TestAttributeConstructor(), LengthValueTestCase::TestAttributeDeserialization(), LengthValueTestCase::TestAttributeSerialization(), and LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ Meters()

Length ns3::Meters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 811 of file length.cc.

Referenced by ArithmeticOperators(), EqualityOperators(), and LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ MicroMeters()

Length ns3::MicroMeters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 793 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ Miles()

Length ns3::Miles ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 847 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ MilliMeters()

Length ns3::MilliMeters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 799 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ Mod()

Length ns3::Mod ( const Length numerator,
const Length denominator 
)

Calculate the amount remaining after dividing two lengths.

The returned value will be less than denominator and have the same sign as numerator.

NS_FATAL_ERROR is called if denominator is 0.

Parameters
numeratorThe value to split
denominatorThe length of each split
Returns
The amount remaining after splitting numerator into denominator sized pieces.

Definition at line 501 of file length.cc.

References ns3::Length::GetDouble(), and NS_FATAL_ERROR.

Referenced by DivAndMod(), LengthTestCase::TestModReturnsNonZero(), and LengthTestCase::TestModReturnsZero().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NanoMeters()

Length ns3::NanoMeters ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 787 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ NauticalMiles()

Length ns3::NauticalMiles ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 823 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function:

◆ operator!=()

bool ns3::operator!= ( const Length left,
const Length right 
)

Compare two length objects for inequality.

Equivalent to:

left.IsNotEqual(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left and right do not have the same value

Definition at line 403 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator*() [1/2]

Length ns3::operator* ( const Length l,
double  scalar 
)

Multiply a length value by a scalar.

Multiplies the value l by scalar and returns a new Length object containing the result.

Parameters
lThe Length object
scalarMultiplication factor
Returns
A newly constructed Length object containing the result of l * scalar.

Definition at line 447 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator*() [2/2]

Length ns3::operator* ( double  scalar,
const Length l 
)

Multiply a length value by a scalar.

Multiplies the value l by scalar and returns a new Length object containing the result.

Parameters
lThe Length object
scalarMultiplication factor
Returns
A newly constructed Length object containing the result of l * scalar.

Definition at line 454 of file length.cc.

◆ operator+()

Length ns3::operator+ ( const Length left,
const Length right 
)

Add two length values together.

Adds the values of left to right and returns a new Length object containing the result.

Parameters
leftA Length object
rightA Length object
Returns
A newly constructed Length object containing the result of left + right.

Definition at line 433 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator-()

Length ns3::operator- ( const Length left,
const Length right 
)

Subtract two length values.

Subtracts the value of right from left and returns a new Length object containing the result.

Parameters
leftA Length object
rightA Length object
Returns
A newly constructed Length object containing the result of left - right.

Definition at line 440 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator/() [1/2]

Length ns3::operator/ ( const Length left,
double  scalar 
)

Divide a length value by a scalar.

Divides the value left by scalar and returns a new Length object containing the result.

scalar must contain a non zero value. NS_FATAL_ERROR is called if scalar is zero

Parameters
leftLength value
scalarMultiplication factor
Returns
A newly constructed Length object containing the result of left / scalar.

Definition at line 460 of file length.cc.

References NS_FATAL_ERROR.

◆ operator/() [2/2]

double ns3::operator/ ( const Length numerator,
const Length denominator 
)

Divide a length value by another length value.

Divides the value numerator by the value denominator and returns a scalar value containing the result.

The return value will be NaN if denominator is 0.

Parameters
numeratorThe top value of the division
denominatorThe bottom value of the division
Returns
A scalar value that is the result of numerator / denominator or NaN if denominator is 0.

Definition at line 471 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator<()

bool ns3::operator< ( const Length left,
const Length right 
)

Check if left has a value less than right.

Equivalent to:

left.IsLess(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left is less than right

Definition at line 408 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator<<() [1/3]

std::ostream & ns3::operator<< ( std::ostream &  stream,
const Length l 
)

Write a length value to an output stream.

The output of the length is in meters.

Equivalent to:

stream << l.As (Meter);
Parameters
streamOutput stream
lLength value to write to the stream
Returns
Reference to the output stream

Definition at line 663 of file length.cc.

References ns3::Length::As().

+ Here is the call graph for this function:

◆ operator<<() [2/3]

std::ostream & ns3::operator<< ( std::ostream &  stream,
const Length::Quantity q 
)

Write a Quantity to an output stream.

The data written to the output stream will have the format <value> <symbol>

Equivalent to:

stream << q.Value () << ' ' << ToSymbol (q.Unit());
std::string ToSymbol(Length::Unit unit)
Return the symbol of the supplied unit.
Definition: length.cc:514
Parameters
streamOutput stream
qQuantity to write to the output stream
Returns
Reference to the output stream

Definition at line 671 of file length.cc.

References ns3::ToSymbol(), ns3::Length::Quantity::Unit(), and ns3::Length::Quantity::Value().

+ Here is the call graph for this function:

◆ operator<<() [3/3]

std::ostream & ns3::operator<< ( std::ostream &  stream,
Length::Unit  unit 
)

Write a Length::Unit to an output stream.

Writes the name of unit to the output stream

Equivalent to:

stream << ToName (unit);
std::string ToName(Length::Unit unit, bool plural)
Return the name of the supplied unit.
Definition: length.cc:544
Parameters
streamOutput stream
unitLength unit to output
Returns
Reference to the output stream

Definition at line 679 of file length.cc.

References ns3::ToName().

+ Here is the call graph for this function:

◆ operator<=()

bool ns3::operator<= ( const Length left,
const Length right 
)

Check if left has a value less than or equal to right.

Equivalent to:

left.IsLessOrEqual(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left is less than or equal to right

Definition at line 414 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator==()

bool ns3::operator== ( const Length left,
const Length right 
)

Compare two length objects for equality.

Equivalent to:

left.IsEqual(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left and right have the same value

Definition at line 397 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator>()

bool ns3::operator> ( const Length left,
const Length right 
)

Check if left has a value greater than right.

Equivalent to:

left.IsGreater(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left is greater than right

Definition at line 421 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator>=()

bool ns3::operator>= ( const Length left,
const Length right 
)

Check if left has a value greater than or equal to right.

Equivalent to:

left.IsGreaterOrEqual(right, 0);
Parameters
leftLeft length object
rightRight length object
Returns
true if left is greater than or equal to right

Definition at line 427 of file length.cc.

References ns3::Length::GetDouble().

+ Here is the call graph for this function:

◆ operator>>()

std::istream & ns3::operator>> ( std::istream &  stream,
Length l 
)

Read a length value from an input stream.

The expected format of the input is <number> <unit> or <number><unit> This function calls NS_ABORT if the input stream does not contain a valid length string

Parameters
streamInput stream
lObject where the deserialized value will be stored
Returns
Reference to the input stream

Definition at line 741 of file length.cc.

References NS_LOG_LOGIC, ns3::ParseLengthString(), and ns3::Length::swap().

+ Here is the call graph for this function:

◆ ToName()

std::string ns3::ToName ( Length::Unit  unit,
bool  plural = false 
)

Return the name of the supplied unit.

The value returned by this function is the common name of unit. The output is always lowercase.

If plural is true, then the plural form of the common name is returned instead.

Parameters
unitThe unit to name
pluralBoolean indicating if the returned string should contain the plural form of the name
Returns
String containing the full name of unit

Definition at line 544 of file length.cc.

References NS_FATAL_ERROR.

Referenced by ns3::operator<<().

+ Here is the caller graph for this function:

◆ ToSymbol()

std::string ns3::ToSymbol ( Length::Unit  unit)

Return the symbol of the supplied unit.

The symbol of the unit is the shortened form of the unit name and is usually two or three characters long

Parameters
unitThe unit to symbolize
Returns
String containing the symbol of unit

Definition at line 514 of file length.cc.

References NS_FATAL_ERROR.

Referenced by ns3::operator<<().

+ Here is the caller graph for this function:

◆ Yards()

Length ns3::Yards ( double  value)

Construct a length from a value in the indicated unit.

Parameters
valueThe numerical value.
Returns
Length object.

Definition at line 841 of file length.cc.

Referenced by LengthTestCase::TestBuilderFreeFunctions().

+ Here is the caller graph for this function: