A Discrete-Event Network Simulator
API
ns3::Length Class Reference



Represents a length in meters More...

#include "length.h"

Classes

class  Quantity
 An immutable class which represents a value in a specific length unit. More...
 

Public Types

enum  Unit : uint16_t {
  Nanometer = 1, Micrometer, Millimeter, Centimeter,
  Meter, Kilometer, NauticalMile, Inch,
  Foot, Yard, Mile
}
 Units of length in various measurement systems that are supported by the Length class. More...
 

Public Member Functions

 Length ()
 Default Constructor. More...
 
 Length (const std::string &text)
 String Constructor. More...
 
 Length (double value, const std::string &unit)
 Construct a Length object from a value and a unit string. More...
 
 Length (double value, Length::Unit unit)
 Construct a Length object from a value and a unit. More...
 
 Length (Quantity quantity)
 Construct a Length object from a Quantity. More...
 
 Length (const Length &other)=default
 Copy Constructor. More...
 
 Length (Length &&other)=default
 Move Constructor. More...
 
 ~Length ()=default
 Destructor. More...
 
Quantity As (Unit unit) const
 Create a Quantity in a specific unit from a Length. More...
 
double GetDouble () const
 
Current length value More...
 
bool IsEqual (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 Check if other is equal in value to this instance. More...
 
bool IsGreater (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 
Check if other is less in value than this instance. More...
 
bool IsGreaterOrEqual (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 
Check if other is equal or less in value than this instance. More...
 
bool IsLess (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 Check if other is greater in value than this instance. More...
 
bool IsLessOrEqual (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 
Check if other is greater or equal in value than this instance. More...
 
bool IsNotEqual (const Length &other, double tolerance=DEFAULT_TOLERANCE) const
 Check if other is not equal in value to this instance. More...
 
Lengthoperator= (const Length &other)=default
 Copy Assignment operator. More...
 
Lengthoperator= (Length &&other)=default
 Move Assignment operator. More...
 
Lengthoperator= (const Length::Quantity &q)
 Assignment operator. More...
 
void swap (Length &other)
 
Swap values with another object More...
 

Static Public Member Functions

static std::tuple< bool, LengthTryParse (double value, const std::string &unit)
 Attempt to construct a Length object from a value and a unit string. More...
 

Static Public Attributes

static constexpr double DEFAULT_TOLERANCE = std::numeric_limits<double>::epsilon ()
 Default tolerance value used for the member comparison functions (IsEqual, IsLess, etc.) More...
 

Private Attributes

double m_value
 Length in meters. More...
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description



Represents a length in meters

The purpose of this class is to replace the use of raw numbers (ints, doubles) that have implicit lengths with a class that represents lengths with an explicit unit. Using raw values with implicit units can lead to bugs when a value is assumed to represent one unit but actually represents another. For example, assuming a value represents a length in meters when it in fact represents a length in kilometers.

The Length class prevents this confusion by storing values internally as doubles representing lengths in Meters and providing conversion functions to convert to/from other length units (kilometers, miles, etc.).

Conversion to and from meters is supported for the following units:

  • nanometer
  • micrometer
  • millimeter
  • centimeter
  • meter
  • kilometer
  • nautical mile
  • inch
  • foot
  • yard
  • mile

Length objects can be constructed in a number of different ways

The string constructor parses strings with the format <number><unit> or <number> <unit> and creates the equivalent Length value in meters. <unit> can be the full name of the unit (nanometer, kilometer, foot, etc.) or the abbreviated name (nm, km, ft, etc.).

//construct lengths from strings
Length foot ("1foot");
Length cm ("1cm");
Length mile ("1 mile");
Length km ("1 km");
//nautical mile is special because it is two words
Length nautmile ("1 nautical mile");
Length nmi ("1 nmi");

Quantity is a class that describes a value and a unit type. For example, meter is a unit while 5 meters is a quantity. The Length constructor takes the quantity instance and converts it to the equivalent value in meters.

//construct a Length representing 2 kilometers
Length::Quantity q (2, Length::Unit::Kilometer);
Length km(q);

Two constructors are provided which take a value and a unit as separate parameters. The difference between the two constructors is that one takes the unit as a string and the other takes the unit as a Length::Unit value. An assertion is triggered if the string does not map to a valid Length::Unit

//These two contructors are equivalent
Length l1 (1, "cm");
Length l2 (1, Length::Unit::Centimeter);

If the boost::units library is discovered during ns-3 configuration an additional constructor is enabled which allows constructing Length objects from boost::unit quantities.

//construct length from a boost::units quantitiy
boost::units::quantity<boost::units::si::length> q = 5 * boost::units::si::meter;
Length meters (q);

The following arithmetic operations are supported:

Addition is between two Length instances

std::cout << Length(1, Length::Unit::Meter) + Length (2, Length::Unit::Meter); // output: "3 m"

Subtraction is between two Length instances

std::cout << Length(3, Length::Unit::Meter) - Length (2, Length::Unit::Meter); // output: "1 m"

Multiplication is only supported between a Length and a unitless scalar value

std::cout << Length(1, Length::Unit::Meter) * 5; // output: "5 m"
std::cout << 5 * Length (1, Length::Unit::Meter); // output: "5 m"

Division can be between a Length and a scalar or two Length objects.

Division between a Length and a scalar returns a new Length.

Division between two Length objects returns a unitless value.

std::cout << Length(5, Length::Unit::Meter) / 5; // output: "1 m"
std::cout << Length (5, Length::Unit::Meter) / Length (5, Length::Unit::Meter); // output: 1

All the usual arithmetic comparison operations (=, !=, <, <=, >, >=) are supported. There are two forms of comparison operators: free function and member function. The free functions define =, !=, <, <=, >, >= and perform exact comparisons of the underlying double values. The Length class provides comparison operator functions (IsEqual, IsLess, IsGreater, etc.) which accept an additional tolerance value to control how much the underlying double values must match when performing the comparison.

//check for exact match
Length l (5, Length::Unit::Meter);
bool match = (l == l); // match is true
Length v1 (0.02, Length::Unit::Meter);
Length v2 (0.022, Length::Unit::Meter);
match = (v1 == v2); // match is false
double tolerance = 0.01;
bool mostly_match = v1.IsEqual (v2, tolerance); // mostly_match is true

The Length class supports serialization using the << and >> operators. By default the output serialization is in meters. Use Length::As to output the Length value in a different unit.

Length m(5, Length::Unit::Meter);
//output: 5 m, 0.005 km, 16.4042 ft
std::cout << m << ", " << m.As(Length::Unit::Kilometer) << ", " << m.As(Length::Unit::Foot);

Definition at line 238 of file length.h.

Member Enumeration Documentation

◆ Unit

enum ns3::Length::Unit : uint16_t

Units of length in various measurement systems that are supported by the Length class.

Enumerator
Nanometer 

1e-9 meters

Micrometer 

1e-6 meters

Millimeter 

1e-3 meters

Centimeter 

1e-2 meters

Meter 

Base length unit in metric system.

Kilometer 

1e3 meters

NauticalMile 

1,852 meters

Inch 

1/12 of a foot

Foot 

Base length unit in US customary system.

Yard 

3 feet

Mile 

5,280 feet

Definition at line 245 of file length.h.

Constructor & Destructor Documentation

◆ Length() [1/7]

ns3::Length::Length ( )

Default Constructor.

Initialize with a value of 0 meters.

Definition at line 258 of file length.cc.

References NS_LOG_FUNCTION.

Referenced by TryParse().

+ Here is the caller graph for this function:

◆ Length() [2/7]

ns3::Length::Length ( const std::string &  text)

String Constructor.

Parses text and initializes the value with the parsed result.

The expected format of text is <number> <unit> or <number><unit>

Parameters
textSerialized length value

Definition at line 264 of file length.cc.

References NS_LOG_FUNCTION.

◆ Length() [3/7]

ns3::Length::Length ( double  value,
const std::string &  unit 
)

Construct a Length object from a value and a unit string.

unit can either be the full name of the unit (meter, kilometer, mile, etc.) or the symbol of the unit (m, km, mi, etc.)

Warning
NS_FATAL_ERROR is called if unit is not a valid unit string.
Use Length::TryParse to parse potentially bad values without terminating.
Parameters
valueNumeric value of the new length
unitUnit that the value represents

Definition at line 274 of file length.cc.

References anonymous_namespace{length.cc}::Convert(), FromString(), m_value, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Length() [4/7]

ns3::Length::Length ( double  value,
Length::Unit  unit 
)

Construct a Length object from a value and a unit.

Warning
NS_FATAL_ERROR is called if unit is not valid.
Use Length::TryParse to parse potentially bad values without terminating.
Parameters
valueNumeric value of the new length
unitLength unit of the value

Definition at line 294 of file length.cc.

References anonymous_namespace{length.cc}::Convert(), m_value, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Length() [5/7]

ns3::Length::Length ( Quantity  quantity)

Construct a Length object from a Quantity.

Parameters
quantityQuantity representing a length value and unit

Definition at line 302 of file length.cc.

References NS_LOG_FUNCTION.

◆ Length() [6/7]

ns3::Length::Length ( const Length other)
default

Copy Constructor.

Initialize an object with the value from other.

Parameters
otherLength object to copy

◆ Length() [7/7]

ns3::Length::Length ( Length &&  other)
default

Move Constructor.

Initialize an object with the value from other.

After the move completes, other is left in an undefined but useable state.

Parameters
otherLength object to move

◆ ~Length()

ns3::Length::~Length ( )
default

Destructor.

Member Function Documentation

◆ As()

Length::Quantity ns3::Length::As ( Length::Unit  unit) const

Create a Quantity in a specific unit from a Length.

Converts the current length value to the equivalent value specified by unit and returns a Quantity object with the converted value and unit

Parameters
unitThe desired unit of the returned Quantity
Returns
A quantity representing the length in the requested unit

Definition at line 388 of file length.cc.

References anonymous_namespace{length.cc}::Convert(), m_value, and NS_LOG_FUNCTION.

Referenced by Conversions(), DivAndMod(), ns3::operator<<(), LengthTestCase::TestLengthSerialization(), and LengthValueTestCase::TestSetAttributeUsingStringValue().

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

◆ GetDouble()

◆ IsEqual()

bool ns3::Length::IsEqual ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const

Check if other is equal in value to this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal
Returns
true if the absolute difference between lengths is less than or equal to tolerance

Definition at line 319 of file length.cc.

References m_value, and NS_LOG_FUNCTION.

Referenced by IsLessOrEqual(), IsNotEqual(), LengthTestCase::TestIsEqualReturnsFalse(), LengthTestCase::TestIsEqualReturnsTrue(), LengthTestCase::TestIsEqualWithToleranceReturnsFalse(), and LengthTestCase::TestIsEqualWithToleranceReturnsTrue().

+ Here is the caller graph for this function:

◆ IsGreater()

bool ns3::Length::IsGreater ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const


Check if other is less in value than this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal

Equivalent to:

!(IsLessOrEqual(other, tolerance))
Returns
true if the values are not equal and other is less in value

Definition at line 358 of file length.cc.

References IsLessOrEqual(), m_value, and NS_LOG_FUNCTION.

Referenced by LengthTestCase::TestIsGreaterReturnsFalse(), LengthTestCase::TestIsGreaterReturnsTrue(), and LengthTestCase::TestIsGreaterWithToleranceReturnsFalse().

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

◆ IsGreaterOrEqual()

bool ns3::Length::IsGreaterOrEqual ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const


Check if other is equal or less in value than this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal

Equivalent to:

!IsLess(other, tolerance)
Returns
true if the values are equal or other is less in value

Definition at line 366 of file length.cc.

References IsLess(), m_value, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ IsLess()

bool ns3::Length::IsLess ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const

Check if other is greater in value than this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal
Returns
true if the values are not equal and other is greater in value

Definition at line 342 of file length.cc.

References IsNotEqual(), m_value, and NS_LOG_FUNCTION.

Referenced by IsGreaterOrEqual(), LengthTestCase::TestIsLessReturnsFalse(), LengthTestCase::TestIsLessReturnsTrue(), and LengthTestCase::TestIsLessWithToleranceReturnsFalse().

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

◆ IsLessOrEqual()

bool ns3::Length::IsLessOrEqual ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const


Check if other is greater or equal in value than this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal

Equivalent to:

IsEqual(other, tolerance) || IsLess(other, tolerance)
Returns
true if the values are equal or other is greater in value

Definition at line 350 of file length.cc.

References IsEqual(), m_value, and NS_LOG_FUNCTION.

Referenced by IsGreater().

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

◆ IsNotEqual()

bool ns3::Length::IsNotEqual ( const Length other,
double  tolerance = DEFAULT_TOLERANCE 
) const

Check if other is not equal in value to this instance.

Parameters
otherValue to compare against
toleranceSmallest difference allowed between the two values to still be considered equal
Returns
true if the absolute difference between lengths is greater than tolerance

Definition at line 334 of file length.cc.

References IsEqual(), m_value, and NS_LOG_FUNCTION.

Referenced by IsLess(), LengthTestCase::TestIsNotEqualReturnsFalse(), LengthTestCase::TestIsNotEqualReturnsTrue(), LengthTestCase::TestIsNotEqualWithToleranceReturnsFalse(), and LengthTestCase::TestIsNotEqualWithToleranceReturnsTrue().

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

◆ operator=() [1/3]

Length& ns3::Length::operator= ( const Length other)
default

Copy Assignment operator.

Replace the current value with the value from other

Parameters
otherLength object to copy
Returns
Reference to the updated object

◆ operator=() [2/3]

Length& ns3::Length::operator= ( Length &&  other)
default

Move Assignment operator.

Replace the current value with the value from other After the move, other is left in an undefined but valid state

Parameters
otherLength object to move
Returns
Reference to the updated object

◆ operator=() [3/3]

Length & ns3::Length::operator= ( const Length::Quantity q)

Assignment operator.

Replace the current value with the value from q

Parameters
qQuantity holding the value to assign
Returns
Reference to the updated object

Definition at line 309 of file length.cc.

References anonymous_namespace{length.cc}::Convert(), m_value, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ swap()

void ns3::Length::swap ( Length other)


Swap values with another object

Swap the current value with the value in other.

Equivalent to:

Length temp(*this);
*this = other;
other = temp;
Parameters
otherLength object to swap

Definition at line 374 of file length.cc.

References m_value.

Referenced by ns3::operator>>().

+ Here is the caller graph for this function:

◆ TryParse()

std::tuple< bool, Length > ns3::Length::TryParse ( double  value,
const std::string &  unit 
)
static

Attempt to construct a Length object from a value and a unit string.

unit can either be the full name of the unit (meter, kilometer, mile, etc.) or the symbol of the unit (m, km, mi, etc.)

This function will return false if unit does not map to a known type.

Parameters
valueNumeric value of the new length
unitUnit that the value represents
Returns
A tuple containing the success or failure of the parsing and a Length object. If the boolean element is true, then the Length element contains the parsed result. If the boolean element is false, the value of the Length element is undefined.

Definition at line 239 of file length.cc.

References FromString(), Length(), and NS_LOG_FUNCTION.

Referenced by LengthTestCase::TestTryParseReturnsFalse(), and LengthTestCase::TestTryParseReturnsTrue().

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

Friends And Related Function Documentation

◆ Div()

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

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 488 of file length.cc.

◆ FromString()

std::tuple< bool, Length::Unit > FromString ( std::string  unitString)
related

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 tuple containing a boolean and a Length::Unit. When the boolean is true, the Length::Unit contains a valid value. When the boolean is false, a match for the string could not be found and the Length::Unit value is undefined

Definition at line 586 of file length.cc.

Referenced by Length(), and TryParse().

+ Here is the caller graph for this function:

◆ Mod()

Length Mod ( const Length numerator,
const Length denominator 
)
related

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 507 of file length.cc.

◆ operator!=()

bool operator!= ( const Length l,
const Length r 
)
related

Compare two length objects for inequality.

Equivalent to:

l.IsNotEqual(r, 0);
Parameters
lLeft length object
rRight length object
Returns
true if l and r do not have the same value

Definition at line 409 of file length.cc.

◆ operator*() [1/2]

Length operator* ( double  scalar,
const Length right 
)
related

Multiply a length value by a scalar.

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

Parameters
scalarMultiplication factor
rightLength value
Returns
A newly constructed Length object containing the result of right * scalar.

Definition at line 460 of file length.cc.

◆ operator*() [2/2]

Length operator* ( const Length left,
double  scalar 
)
related

Multiply a length value by a scalar.

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

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

Definition at line 453 of file length.cc.

◆ operator+()

Length operator+ ( const Length first,
const Length second 
)
related

Add two length values together.

Adds the values of first to second and returns a new Length object containing the result.

Parameters
firstA Length object
secondA Length object
Returns
A newly constructed Length object containing the result of first + second

Definition at line 439 of file length.cc.

◆ operator-()

Length operator- ( const Length first,
const Length second 
)
related

Subtract two length values.

Subtracts the value of second from first and returns a new Length object containing the result.

Parameters
firstA Length object
secondA Length object
Returns
A newly constructed Length object containing the result of first - second

Definition at line 446 of file length.cc.

◆ operator/() [1/2]

Length operator/ ( const Length left,
double  scalar 
)
related

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 466 of file length.cc.

◆ operator/() [2/2]

double operator/ ( const Length numerator,
const Length denominator 
)
related

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 477 of file length.cc.

◆ operator<()

bool operator< ( const Length l,
const Length r 
)
related

Check if l has a value less than r.

Equivalent to:

l.IsLess(r, 0);
Parameters
lLeft length object
rRight length object
Returns
true if l is less than r

Definition at line 415 of file length.cc.

◆ operator<<() [1/3]

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

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 675 of file length.cc.

◆ operator<<() [2/3]

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


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());
Parameters
streamOutput stream
qQuantity to write to the output stream
Returns
Reference to the output stream

Definition at line 683 of file length.cc.

◆ operator<<() [3/3]

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


Write a Length::Unit to an output stream.

Writes the name of unit to the output stream

Equivalent to:

stream << ToName (unit);
Parameters
streamOutput stream
unitLength unit to output
Returns
Reference to the output stream

Definition at line 691 of file length.cc.

◆ operator<=()

bool operator<= ( const Length l,
const Length r 
)
related

Check if l has a value less than or equal to r.

Equivalent to:

l.IsLessOrEqual(r, 0);
Parameters
lLeft length object
rRight length object
Returns
true if l is less than or equal to r

Definition at line 421 of file length.cc.

◆ operator==()

bool operator== ( const Length left,
const Length right 
)
related

Compare two length objects for equality.

Equivalent to:

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

Definition at line 403 of file length.cc.

◆ operator>()

bool operator> ( const Length l,
const Length r 
)
related

Check if l has a value greater than r.

Equivalent to:

l.IsGreater(r, 0);
Parameters
lLeft length object
rRight length object
Returns
true if l is greater than r

Definition at line 427 of file length.cc.

◆ operator>=()

bool operator>= ( const Length l,
const Length r 
)
related

Check if l has a value greater than or equal to r.

Equivalent to:

l.IsGreaterOrEqual(r, 0);
Parameters
lLeft length object
rRight length object
Returns
true if l is greater than or equal to r

Definition at line 433 of file length.cc.

◆ operator>>()

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

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 750 of file length.cc.

◆ ToName()

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

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 550 of file length.cc.

◆ ToSymbol()

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

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 520 of file length.cc.

Member Data Documentation

◆ DEFAULT_TOLERANCE

constexpr double ns3::Length::DEFAULT_TOLERANCE = std::numeric_limits<double>::epsilon ()
static

Default tolerance value used for the member comparison functions (IsEqual, IsLess, etc.)

The default tolerance is set to epsilon which is defined as the difference between 1.0 and the next value that can be represented by a double.

Definition at line 337 of file length.h.

◆ m_value

double ns3::Length::m_value
private

The documentation for this class was generated from the following files: