A Discrete-Event Network Simulator
API
length.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 Lawrence Livermore National Laboratory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathew Bielejeski <bielejeski1@llnl.gov>
19  */
20 
21 #include "length.h"
22 
23 #include "ns3/log.h"
24 
25 #include <algorithm>
26 #include <array>
27 #include <cctype>
28 #include <cmath>
29 #include <functional>
30 #include <limits>
31 #include <map>
32 #include <ratio>
33 #include <sstream>
34 #include <string>
35 #include <tuple>
36 #include <type_traits>
37 #include <unordered_map>
38 #include <vector>
39 
50 namespace {
60 template<class R>
61 double ScaleValue (double value)
62 {
63  return (value * R::num) / static_cast<double> (R::den);
64 }
65 
73 double FootToMeter (double value)
74 {
75  return value * 0.3048;
76 }
77 
85 double MeterToFoot (double value)
86 {
87  return value * 3.28084;
88 }
89 
101 template<class R>
102 double USToMeter (double value)
103 {
104  return FootToMeter ( ScaleValue<R> (value) );
105 }
106 
118 template<class R>
119 double MeterToUS (double value)
120 {
121  return ScaleValue<R> ( MeterToFoot (value) );
122 }
123 
133 double Convert (double value, ns3::Length::Unit fromUnit, ns3::Length::Unit toUnit)
134 {
135  using Unit = ns3::Length::Unit;
136  using Key = std::pair<Unit, Unit>;
137  using Conversion = std::function<double (double)>;
138 
142  struct KeyHash
143  {
144  std::size_t operator () (const Key& key) const noexcept
145  {
146  static_assert (sizeof(Unit) < sizeof(std::size_t),
147  "sizeof(Length::Unit) changed, it must be less than "
148  "sizeof(std::size_t)");
149 
150  int shift = sizeof(Unit) * 8;
151  return static_cast<std::size_t> (key.first) << shift |
152  static_cast<std::size_t> (key.second);
153  }
154 
155  };
156 
157  using ConversionTable = std::unordered_map<Key, Conversion, KeyHash>;
158 
159  static ConversionTable CONVERSIONS {
160  { {Unit::Nanometer, Unit::Meter}, ScaleValue<std::nano> },
161  { {Unit::Meter, Unit::Nanometer}, ScaleValue<std::giga> },
162  { {Unit::Micrometer, Unit::Meter}, ScaleValue<std::micro> },
163  { {Unit::Meter, Unit::Micrometer}, ScaleValue<std::mega> },
164  { {Unit::Millimeter, Unit::Meter}, ScaleValue<std::milli> },
165  { {Unit::Meter, Unit::Millimeter}, ScaleValue<std::kilo> },
166  { {Unit::Centimeter, Unit::Meter}, ScaleValue<std::centi> },
167  { {Unit::Meter, Unit::Centimeter}, ScaleValue<std::hecto> },
168  { {Unit::Meter, Unit::Meter}, ScaleValue<std::ratio<1,1> > },
169  { {Unit::Kilometer, Unit::Meter}, ScaleValue<std::kilo> },
170  { {Unit::Meter, Unit::Kilometer}, ScaleValue<std::milli> },
171  { {Unit::NauticalMile, Unit::Meter}, ScaleValue<std::ratio<1852, 1> > },
172  { {Unit::Meter, Unit::NauticalMile}, ScaleValue<std::ratio<1, 1852> > },
173  { {Unit::Inch, Unit::Meter}, USToMeter<std::ratio<1, 12> > },
174  { {Unit::Meter, Unit::Inch}, MeterToUS<std::ratio<12, 1> > },
175  { {Unit::Foot, Unit::Meter}, FootToMeter },
176  { {Unit::Meter, Unit::Foot}, MeterToFoot },
177  { {Unit::Yard, Unit::Meter}, USToMeter<std::ratio<3, 1> > },
178  { {Unit::Meter, Unit::Yard}, MeterToUS<std::ratio<1, 3> > },
179  { {Unit::Mile, Unit::Meter}, USToMeter<std::ratio<5280, 1> > },
180  { {Unit::Meter, Unit::Mile}, MeterToUS<std::ratio<1, 5280> > }
181  };
182 
183  auto iter = CONVERSIONS.find ( Key {fromUnit, toUnit} );
184 
185  if (iter == CONVERSIONS.end ())
186  {
187  NS_FATAL_ERROR ("No conversion defined for " << fromUnit
188  << " -> " << toUnit);
189  }
190 
191  return iter->second (value);
192 }
193 
202 double Convert (const ns3::Length::Quantity& from, ns3::Length::Unit toUnit)
203 {
204  return Convert (from.Value (), from.Unit (), toUnit);
205 }
206 
213 class EnumHash
214 {
215 public:
223  std::size_t operator () (ns3::Length::Unit u) const noexcept
224  {
225  return static_cast<std::size_t> (u);
226  }
227 };
228 
229 } // unnamed namespace
230 
231 namespace ns3 {
232 
233 NS_LOG_COMPONENT_DEFINE ("Length");
234 
235 // Implement the attribute helper
237 
238 std::tuple<bool, Length>
239 Length::TryParse (double value, const std::string& unitString)
240 {
241  NS_LOG_FUNCTION (value << unitString);
242 
243  bool validUnit = false;
244  Length::Unit unit;
245 
246  std::tie (validUnit, unit) = FromString (unitString);
247 
248  Length length;
249 
250  if (validUnit)
251  {
252  length = Length (value, unit);
253  }
254 
255  return std::make_tuple (validUnit, length);
256 }
257 
259  : m_value (0)
260 {
261  NS_LOG_FUNCTION (this);
262 }
263 
264 Length::Length (const std::string& input)
265  : m_value (0)
266 {
267  NS_LOG_FUNCTION (this << input);
268 
269  std::istringstream stream (input);
270 
271  stream >> *this;
272 }
273 
274 Length::Length (double value, const std::string& unitString)
275  : m_value (0)
276 {
277  NS_LOG_FUNCTION (this << value << unitString);
278 
279  bool validUnit;
280  Length::Unit unit;
281 
282  std::tie (validUnit, unit) = FromString (unitString);
283 
284  if (!validUnit)
285  {
286  NS_FATAL_ERROR ("A Length object could not be constructed from the unit "
287  "string '" << unitString << "', because the string is not associated "
288  "with a Length::Unit entry");
289  }
290 
291  m_value = Convert (value, unit, Length::Unit::Meter);
292 }
293 
294 Length::Length (double value, Length::Unit unit)
295  : m_value (0)
296 {
297  NS_LOG_FUNCTION (this << value << unit);
298 
299  m_value = Convert (value, unit, Length::Unit::Meter);
300 }
301 
303  : Length (quantity.Value (), quantity.Unit ())
304 {
305  NS_LOG_FUNCTION (this << quantity);
306 }
307 
308 Length&
310 {
311  NS_LOG_FUNCTION (this << q);
312 
313  m_value = Convert (q, Length::Unit::Meter);
314 
315  return *this;
316 }
317 
318 bool
319 Length::IsEqual (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
320 {
321  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
322 
323  if ( m_value == other.m_value )
324  {
325  return true;
326  }
327 
328  auto diff = std::abs (m_value - other.m_value);
329 
330  return diff <= tolerance;
331 }
332 
333 bool
334 Length::IsNotEqual (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
335 {
336  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
337 
338  return !IsEqual (other, tolerance);
339 }
340 
341 bool
342 Length::IsLess (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
343 {
344  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
345 
346  return m_value < other.m_value && IsNotEqual (other, tolerance);
347 }
348 
349 bool
350 Length::IsLessOrEqual (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
351 {
352  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
353 
354  return m_value < other.m_value || IsEqual (other, tolerance);
355 }
356 
357 bool
358 Length::IsGreater (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
359 {
360  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
361 
362  return !IsLessOrEqual (other, tolerance);
363 }
364 
365 bool
366 Length::IsGreaterOrEqual (const Length& other, double tolerance /*=DEFAULT_TOLERANCE*/) const
367 {
368  NS_LOG_FUNCTION (this << m_value << other.m_value << tolerance);
369 
370  return !IsLess (other, tolerance);
371 }
372 
373 void
375 {
376  using std::swap;
377 
378  swap (m_value, other.m_value);
379 }
380 
381 double
383 {
384  return m_value;
385 }
386 
389 {
390  NS_LOG_FUNCTION (this << unit);
391 
392  double value = Convert (m_value, Length::Unit::Meter, unit);
393 
394  return Quantity (value, unit);
395 }
396 
397 //silence doxygen warnings about undocumented functions
402 bool
403 operator== (const Length& left, const Length& right)
404 {
405  return left.GetDouble () == right.GetDouble ();
406 }
407 
408 bool
409 operator!= (const Length& left, const Length& right)
410 {
411  return left.GetDouble () != right.GetDouble ();
412 }
413 
414 bool
415 operator< (const Length& left, const Length& right)
416 {
417  return left.GetDouble () < right.GetDouble ();
418 }
419 
420 bool
421 operator<= (const Length& left, const Length& right)
422 {
423  return left.GetDouble () <= right.GetDouble ();
424 }
425 
426 bool
427 operator> (const Length& left, const Length& right)
428 {
429  return left.GetDouble () > right.GetDouble ();
430 }
431 
432 bool
433 operator>= (const Length& left, const Length& right)
434 {
435  return left.GetDouble () >= right.GetDouble ();
436 }
437 
438 Length
439 operator+ (const Length& left, const Length& right)
440 {
441  double value = left.GetDouble () + right.GetDouble ();
442  return Length ( value, Length::Unit::Meter );
443 }
444 
445 Length
446 operator- (const Length& left, const Length& right)
447 {
448  double value = left.GetDouble () - right.GetDouble ();
449  return Length ( value, Length::Unit::Meter );
450 }
451 
452 Length
453 operator* (const Length& left, double scalar)
454 {
455  double value = left.GetDouble () * scalar;
456  return Length ( value, Length::Unit::Meter );
457 }
458 
459 Length
460 operator* (double scalar, const Length & right)
461 {
462  return right * scalar;
463 }
464 
465 Length
466 operator/ (const Length & left, double scalar)
467 {
468  if (scalar == 0)
469  {
470  NS_FATAL_ERROR ("Attempted to divide Length by 0");
471  }
472 
473  return left * (1.0 / scalar);
474 }
475 
476 double
477 operator/ (const Length & numerator, const Length& denominator)
478 {
479  if (denominator.GetDouble () == 0)
480  {
481  return std::numeric_limits<double>::quiet_NaN ();
482  }
483 
484  return numerator.GetDouble () / denominator.GetDouble ();
485 }
486 
487 int64_t
488 Div (const Length& numerator, const Length& denominator, Length* remainder)
489 {
490  double value = numerator / denominator;
491 
492  if (std::isnan (value))
493  {
494  NS_FATAL_ERROR ("numerator / denominator return NaN");
495  }
496 
497  if ( remainder )
498  {
499  double rem = std::fmod (numerator.GetDouble (), denominator.GetDouble ());
500  *remainder = Length (rem, Length::Unit::Meter);
501  }
502 
503  return static_cast<int64_t> (std::trunc (value));
504 }
505 
506 Length
507 Mod (const Length& numerator, const Length& denominator)
508 {
509  double rem = std::fmod (numerator.GetDouble (), denominator.GetDouble ());
510 
511  if (std::isnan (rem))
512  {
513  NS_FATAL_ERROR ("numerator / denominator return NaN");
514  }
515 
516  return Length (rem, Length::Unit::Meter);
517 }
518 
519 std::string
521 {
522  using StringTable = std::unordered_map<Length::Unit, std::string, EnumHash>;
523 
524  static const StringTable STRINGS {
525  {Length::Unit::Nanometer, "nm"},
526  {Length::Unit::Micrometer, "um"},
527  {Length::Unit::Millimeter, "mm"},
528  {Length::Unit::Centimeter, "cm"},
529  {Length::Unit::Meter, "m"},
530  {Length::Unit::Kilometer, "km"},
531  {Length::Unit::NauticalMile, "nmi"},
532  {Length::Unit::Inch, "in"},
533  {Length::Unit::Foot, "ft"},
534  {Length::Unit::Yard, "yd"},
535  {Length::Unit::Mile, "mi"}
536  };
537 
538  auto iter = STRINGS.find (unit);
539 
540  if (iter == STRINGS.end ())
541  {
542  NS_FATAL_ERROR ("A symbol could not be found for Length::Unit with value "
543  << EnumHash ()(unit));
544  }
545 
546  return iter->second;
547 }
548 
549 std::string
550 ToName (Length::Unit unit, bool plural /*=false*/)
551 {
552  using Entry = std::tuple<std::string, std::string>;
553  using StringTable = std::unordered_map<Length::Unit, Entry, EnumHash>;
554 
555  static const StringTable STRINGS {
556  {Length::Unit::Nanometer, Entry{"nanometer", "nanometers"}},
557  {Length::Unit::Micrometer, Entry{"micrometer", "micrometer"}},
558  {Length::Unit::Millimeter, Entry{"millimeter", "millimeters"}},
559  {Length::Unit::Centimeter, Entry{"centimeter", "centimeters"}},
560  {Length::Unit::Meter, Entry{"meter", "meters"}},
561  {Length::Unit::Kilometer, Entry{"kilometer", "kilometers"}},
562  {Length::Unit::NauticalMile, Entry{"nautical mile", "nautical miles"}},
563  {Length::Unit::Inch, Entry{"inch", "inches"}},
564  {Length::Unit::Foot, Entry{"foot", "feet"}},
565  {Length::Unit::Yard, Entry{"yard", "yards"}},
566  {Length::Unit::Mile, Entry{"mile", "miles"}}
567  };
568 
569  auto iter = STRINGS.find (unit);
570 
571  if (iter == STRINGS.end ())
572  {
573  NS_FATAL_ERROR ("A symbol could not be found for Length::Unit with value "
574  << EnumHash ()(unit));
575  }
576 
577  if (plural)
578  {
579  return std::get<1> (iter->second);
580  }
581 
582  return std::get<0> (iter->second);
583 }
584 
585 std::tuple<bool, Length::Unit>
586 FromString (std::string unitString)
587 {
588  using UnitTable = std::unordered_map<std::string, Length::Unit>;
589 
590  static const UnitTable UNITS {
591  { "nm", Length::Unit::Nanometer },
592  { "nanometer", Length::Unit::Nanometer },
593  { "nanometers", Length::Unit::Nanometer },
594  { "nanometre", Length::Unit::Nanometer },
595  { "nanometres", Length::Unit::Nanometer },
596  { "um", Length::Unit::Micrometer },
597  { "micrometer", Length::Unit::Micrometer },
598  { "micrometers", Length::Unit::Micrometer },
599  { "micrometre", Length::Unit::Micrometer },
600  { "micrometres", Length::Unit::Micrometer },
601  { "mm", Length::Unit::Millimeter },
602  { "millimeter", Length::Unit::Millimeter },
603  { "millimeters", Length::Unit::Millimeter },
604  { "millimetre", Length::Unit::Millimeter },
605  { "millimetres", Length::Unit::Millimeter },
606  { "cm", Length::Unit::Centimeter },
607  { "centimeter", Length::Unit::Centimeter },
608  { "centimeters", Length::Unit::Centimeter },
609  { "centimetre", Length::Unit::Centimeter },
610  { "centimetres", Length::Unit::Centimeter },
611  { "m", Length::Unit::Meter },
612  { "meter", Length::Unit::Meter },
613  { "metre", Length::Unit::Meter },
614  { "meters", Length::Unit::Meter },
615  { "metres", Length::Unit::Meter },
616  { "km", Length::Unit::Kilometer },
617  { "kilometer", Length::Unit::Kilometer },
618  { "kilometers", Length::Unit::Kilometer },
619  { "kilometre", Length::Unit::Kilometer },
620  { "kilometres", Length::Unit::Kilometer },
621  { "nmi", Length::Unit::NauticalMile },
622  { "nauticalmile", Length::Unit::NauticalMile },
623  { "nauticalmiles", Length::Unit::NauticalMile },
624  { "in", Length::Unit::Inch },
625  { "inch", Length::Unit::Inch },
626  { "inches", Length::Unit::Inch },
627  { "ft", Length::Unit::Foot },
628  { "foot", Length::Unit::Foot },
629  { "feet", Length::Unit::Foot },
630  { "yd", Length::Unit::Yard },
631  { "yard", Length::Unit::Yard },
632  { "yards", Length::Unit::Yard },
633  { "mi", Length::Unit::Mile },
634  { "mile", Length::Unit::Mile },
635  { "miles", Length::Unit::Mile }
636  };
637 
638  //function to trim whitespace and convert to lowercase in one pass
639  static auto Normalize = [] (const std::string& str)
640  {
641  std::string output;
642  output.reserve (str.size ());
643 
644  for (unsigned char c : str)
645  {
646  //this strips all spaces not just beg/end but is fine for our purposes
647  if (std::isspace (c) )
648  {
649  continue;
650  }
651 
652  output.push_back (std::tolower (c));
653  }
654 
655  return output;
656  };
657 
658  unitString = Normalize (unitString);
659 
660  auto iter = UNITS.find (unitString);
661 
662  bool valid = false;
663  Length::Unit unit;
664 
665  if (iter != UNITS.end ())
666  {
667  valid = true;
668  unit = iter->second;
669  }
670 
671  return std::make_tuple (valid, unit);
672 }
673 
674 std::ostream&
675 operator<< (std::ostream& stream, const Length& l)
676 {
677  stream << l.As (Length::Unit::Meter);
678 
679  return stream;
680 }
681 
682 std::ostream&
683 operator<< (std::ostream& stream, const Length::Quantity& q)
684 {
685  stream << q.Value () << ' ' << ToSymbol (q.Unit ());
686 
687  return stream;
688 }
689 
690 std::ostream&
691 operator<< (std::ostream& stream, Length::Unit unit)
692 {
693  stream << ToName (unit);
694 
695  return stream;
696 }
697 
714 std::tuple<bool, double, std::string>
715 ParseLengthString (const std::string& input)
716 {
717  NS_LOG_FUNCTION (input);
718 
719  double value = 0;
720  std::size_t pos = 0;
721  std::string symbol;
722 
723  try
724  {
725  value = std::stod(input, &pos);
726  }
727  catch (const std::exception& e)
728  {
729  NS_LOG_ERROR ("Caught exception while parsing double: " << e.what());
730 
731  return std::make_tuple(false, 0, "");
732  }
733 
734  //skip any whitespace between value and symbol
735  while (pos < input.size () && std::isspace(input[pos]))
736  ++pos;
737 
738  if (pos < input.size ())
739  {
740  NS_LOG_LOGIC ("String has value and symbol, extracting symbol");
741 
742  //input has a double followed by a string
743  symbol = input.substr(pos);
744  }
745 
746  return std::make_tuple(true, value, symbol);
747 }
748 
749 std::istream&
750 operator>> (std::istream& stream, Length& l)
751 {
752  bool success = false;
753  double value = 0;
754  std::string symbol;
755  std::string temp;
756 
757  //configure stream to skip whitespace in case it was disabled
758  auto origFlags = stream.flags ();
759  std::skipws (stream);
760 
761  //Read the contents into a temporary string and parse it manually
762  stream >> temp;
763 
764  std::tie(success, value, symbol) = ParseLengthString (temp);
765 
766  if (success && symbol.empty ())
767  {
768  NS_LOG_LOGIC ("Temp string only contained value, extracting unit symbol from stream");
769 
770  //temp only contained the double
771  //still need to read the symbol from the stream
772  stream >> symbol;
773  }
774 
775  //special handling for nautical mile which is two words
776  if (symbol == "nautical")
777  {
778  stream >> temp;
779 
780  if (!temp.empty ())
781  {
782  symbol.push_back (' ');
783  symbol.append (temp);
784  }
785  }
786 
787  Length (value, symbol).swap (l);
788 
789  //restore original flags
790  stream.flags (origFlags);
791 
792  return stream;
793 }
794 
795 Length
796 NanoMeters (double value)
797 {
798  return Length (value, Length::Unit::Nanometer);
799 }
800 
801 Length
802 MicroMeters (double value)
803 {
804  return Length (value, Length::Unit::Micrometer);
805 }
806 
807 Length
808 MilliMeters (double value)
809 {
810  return Length (value, Length::Unit::Millimeter);
811 }
812 
813 Length
814 CentiMeters (double value)
815 {
816  return Length (value, Length::Unit::Centimeter);
817 }
818 
819 Length
820 Meters (double value)
821 {
822  return Length (value, Length::Unit::Meter);
823 }
824 
825 Length
826 KiloMeters (double value)
827 {
828  return Length (value, Length::Unit::Kilometer);
829 }
830 
831 Length
832 NauticalMiles (double value)
833 {
834  return Length (value, Length::Unit::NauticalMile);
835 }
836 
837 Length
838 Inches (double value)
839 {
840  return Length (value, Length::Unit::Inch);
841 }
842 
843 Length
844 Feet (double value)
845 {
846  return Length (value, Length::Unit::Foot);
847 }
848 
849 Length
850 Yards (double value)
851 {
852  return Length (value, Length::Unit::Yard);
853 }
854 
855 Length
856 Miles (double value)
857 {
858  return Length (value, Length::Unit::Mile);
859 }
860 
863 } // namespace ns3
Quantity As(Unit unit) const
Create a Quantity in a specific unit from a Length.
Definition: length.cc:388
Length KiloMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:826
bool IsLessOrEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is greater or equal in value than this instance.
Definition: length.cc:350
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Declaration of ns3::Length class.
Length Feet(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:844
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition: int64x64-128.h:491
std::string ToSymbol(Length::Unit unit)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:520
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
Length CentiMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:814
double USToMeter(double value)
Convert a value from a US Customary unit (inches, feet, yards etc.) to meters.
Definition: length.cc:102
int64x64_t operator-(const int64x64_t &lhs)
Unary negation operator (change sign operator).
Definition: int64x64-128.h:501
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:160
double m_value
Length in meters.
Definition: length.h:611
double GetDouble() const
Current length value
Definition: length.cc:382
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:166
std::tuple< bool, double, std::string > ParseLengthString(const std::string &input)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:715
Length NanoMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:796
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
Unit
Units of length in various measurement systems that are supported by the Length class.
Definition: length.h:245
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:155
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition: int64x64.h:117
Length Mod(const Length &numerator, const Length &denominator)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:507
Length NauticalMiles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:832
Length Yards(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:850
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:488
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition: int64x64.h:131
Length()
Default Constructor.
Definition: length.cc:258
Length MilliMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:808
Length & operator=(const Length &other)=default
Copy Assignment operator.
bool IsGreaterOrEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is equal or less in value than this instance.
Definition: length.cc:366
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1606
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void swap(Length &other)
Swap values with another object
Definition: length.cc:374
bool IsNotEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is not equal in value to this instance.
Definition: length.cc:334
bool IsGreater(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is less in value than this instance.
Definition: length.cc:358
bool IsLess(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is greater in value than this instance.
Definition: length.cc:342
static std::tuple< bool, Length > TryParse(double value, const std::string &unit)
Attempt to construct a Length object from a value and a unit string.
Definition: length.cc:239
bool IsEqual(const Length &other, double tolerance=DEFAULT_TOLERANCE) const
Check if other is equal in value to this instance.
Definition: length.cc:319
Length Inches(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:838
An immutable class which represents a value in a specific length unit.
Definition: length.h:266
std::tuple< bool, Length::Unit > FromString(std::string unitString)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:586
Length MicroMeters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:802
double Value() const
The value of the quantity.
Definition: length.h:310
Length::Unit Unit
Length::Unit Unit() const
The unit of the quantity.
Definition: length.h:320
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:431
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:142
double MeterToFoot(double value)
Convert a value in meters to the equivalent value in feet.
Definition: length.cc:85
Functor for hashing Length::Unit values.
Definition: length.cc:213
Length Miles(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:856
double MeterToUS(double value)
Convert a value from meters to a US Customary unit (inches, feet, yards etc.)
Definition: length.cc:119
double ScaleValue(double value)
Helper function to scale an input value by a given ratio.
Definition: length.cc:61
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
Represents a length in meters
Definition: length.h:238
double FootToMeter(double value)
Convert a value in feet to the equivalent value in meters.
Definition: length.cc:73
double Convert(const ns3::Length::Quantity &from, ns3::Length::Unit toUnit)
Convert a Length::Quantity to the equivalent value in another unit.
Definition: length.cc:202
std::string ToName(Length::Unit unit, bool plural)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:550
Length Meters(double value)
This function provides a string parsing method that does not rely on istream, which has been found to...
Definition: length.cc:820
std::tuple< bool, Length::Unit > FromString(std::string unitString)
Find the equivalent Length::Unit for a unit string.
Definition: length.cc:586