INET Framework for OMNeT++/OMNEST
inet::physicallayer::ConstMapping Class Referenceabstract

Represents a not changeable mapping (mathematical function) from domain with at least the time to a Argument::mapped_type value. More...

#include <MappingBase.h>

Inheritance diagram for inet::physicallayer::ConstMapping:
inet::physicallayer::ConcatConstMapping< Operator > inet::physicallayer::Mapping inet::physicallayer::SimpleConstMapping inet::physicallayer::BaseDelayedMapping< Mapping > inet::physicallayer::ConstMappingWrapper inet::physicallayer::FrequencyMapping< Interpolator > inet::physicallayer::LinearIntplMapping inet::physicallayer::MultiDimMapping< Interpolator > inet::physicallayer::TimeMapping< Interpolator > inet::physicallayer::MultiDimMapping< Linear > inet::physicallayer::ConstantSimpleConstMapping inet::physicallayer::SimpleTimeConstMapping

Public Types

typedef Argument::mapped_type argument_value_t
 
typedef Argument::mapped_type_cref argument_value_cref_t
 

Public Member Functions

ConstMappingoperator= (const ConstMapping &copy)
 ConstMapping assignment operator. More...
 
void swap (ConstMapping &s)
 Swaps data with another ConstMapping. More...
 
 ConstMapping ()
 Initializes the ConstMapping with a the time dimension as domain. More...
 
 ConstMapping (const ConstMapping &o)
 
 ConstMapping (const DimensionSet &dimSet)
 Initializes the ConstMapping with the passed DimensionSet as Domain. More...
 
virtual ~ConstMapping ()
 
virtual argument_value_t getValue (const Argument &pos) const =0
 Returns the value of this Mapping at the position specified by the passed Argument. More...
 
virtual ConstMappingIteratorcreateConstIterator () const =0
 Returns a pointer of a new Iterator which is able to iterate over this Mapping. More...
 
virtual ConstMappingIteratorcreateConstIterator (const Argument &pos) const =0
 Returns a pointer of a new Iterator which is able to iterate over the function. More...
 
virtual ConstMappingconstClone () const =0
 returns a deep copy of this mapping instance. More...
 
argument_value_t operator[] (const Argument &pos) const
 Returns the value of this Mapping at the position specified by the passed Argument. More...
 
const DimensionSetgetDimensionSet () const
 Returns this Mappings domain as DimensionSet. More...
 
template<class stream >
stream & print (stream &out, argument_value_cref_t lTimeScale=argument_value_t(1), argument_value_cref_t lLeftColScale=Argument::MappedOne, const std::string &sTableHead=std::string("o\\ms"), const Dimension *const pOnlyDim=nullptr) const
 Prints the Mapping to an output stream. More...
 

Protected Attributes

DimensionSet dimensions
 The dimensions of this mappings domain. More...
 

Private Member Functions

template<class T >
std::string toString (T v, unsigned int length) const
 
std::string toString (simtime_t_cref v, unsigned int length) const
 

Friends

std::ostream & operator<< (std::ostream &out, const ConstMapping &rMapToPrint)
 

Detailed Description

Represents a not changeable mapping (mathematical function) from domain with at least the time to a Argument::mapped_type value.

This class is an interface which describes a mapping (math.) from a arbitrary dimensional domain (represented by a DimensionSet) to a Argument::mapped_type value.

Author
Karl Wessel

Member Typedef Documentation

Constructor & Destructor Documentation

inet::physicallayer::ConstMapping::ConstMapping ( )
inline

Initializes the ConstMapping with a the time dimension as domain.

935  :
static const Dimension time
Shortcut to the time Dimension, same as &#39;Dimension("time")&#39;, but spares the parsing of a string...
Definition: MappingBase.h:64
DimensionSet dimensions
The dimensions of this mappings domain.
Definition: MappingBase.h:879
inet::physicallayer::ConstMapping::ConstMapping ( const ConstMapping o)
inline
937  :
938  dimensions(o.dimensions) {}
DimensionSet dimensions
The dimensions of this mappings domain.
Definition: MappingBase.h:879
inet::physicallayer::ConstMapping::ConstMapping ( const DimensionSet dimSet)
inline

Initializes the ConstMapping with the passed DimensionSet as Domain.

The passed DimensionSet has to contain the time dimension!

946  :
947  dimensions(dimSet)
948  {
949 // assert(dimSet.hasDimension(Dimension::time));
950  }
DimensionSet dimensions
The dimensions of this mappings domain.
Definition: MappingBase.h:879
virtual inet::physicallayer::ConstMapping::~ConstMapping ( )
inlinevirtual
952 {}

Member Function Documentation

virtual ConstMappingIterator* inet::physicallayer::ConstMapping::createConstIterator ( const Argument pos) const
pure virtual

Returns a pointer of a new Iterator which is able to iterate over the function.

The iterator starts at the passed position.

See class ConstIterator for details.

Implemented in inet::physicallayer::BaseDelayedMapping< Mapping >, inet::physicallayer::ConcatConstMapping< Operator >, inet::physicallayer::SimpleConstMapping, inet::physicallayer::Mapping, and inet::physicallayer::ConstMappingWrapper.

ConstMapping& inet::physicallayer::ConstMapping::operator= ( const ConstMapping copy)
inline

ConstMapping assignment operator.

Parameters
copyA ConstMapping of identical element and allocator types.

All the elements of copy are copied.

Referenced by inet::physicallayer::Mapping::operator=(), and inet::physicallayer::SimpleConstMapping::operator=().

889  {
890  dimensions = copy.dimensions;
891  return *this;
892  }
DimensionSet dimensions
The dimensions of this mappings domain.
Definition: MappingBase.h:879
argument_value_t inet::physicallayer::ConstMapping::operator[] ( const Argument pos) const
inline

Returns the value of this Mapping at the position specified by the passed Argument.

988  {
989  return getValue(pos);
990  }
virtual argument_value_t getValue(const Argument &pos) const =0
Returns the value of this Mapping at the position specified by the passed Argument.
template<class stream >
stream& inet::physicallayer::ConstMapping::print ( stream &  out,
argument_value_cref_t  lTimeScale = argument_value_t(1),
argument_value_cref_t  lLeftColScale = Argument::MappedOne,
const std::string &  sTableHead = std::string("o\\ms"),
const Dimension *const  pOnlyDim = nullptr 
) const
inline

Prints the Mapping to an output stream.

Parameters
outThe output stream to print.
lTimeScaleThe scaling factor for the time header values (default 1000).
lLeftColScaleThe scaling factor for the left column values (default 1, unscaled).
sTableHeadThe header string for the left column (default: "o\\ms").
pOnlyDimPointer to a specific dimension which should be used as the left column (should not be the Dimension::time).

Referenced by inet::physicallayer::DimensionalSNIR::computeMin(), inet::physicallayer::DimensionalAnalogModelBase::computeNoise(), and inet::physicallayer::DimensionalAnalogModelBase::computeReceptionPower().

1015  {
1016  std::ostream::fmtflags outFlags = out.flags();
1017  const ConstMapping& m = *this;
1018  DimensionSet::value_type otherDim;
1019  const DimensionSet& dims = m.getDimensionSet();
1020  bool bOnlyDimFound = false;
1021 
1022  using std::operator<<;
1023 
1024  std::stringstream osDimHead(std::stringstream::out);
1025  bool bTimeIsIn = false;
1026  const auto dimsEnd = dims.end();
1027  for (auto it = dims.begin(); it != dimsEnd; ++it) {
1028  if (*it != Dimension::time) {
1029  if (pOnlyDim && *it == *pOnlyDim) {
1030  otherDim = *it;
1031  bOnlyDimFound = pOnlyDim != nullptr;
1032  }
1033  else if (!pOnlyDim) {
1034  otherDim = *it;
1035  }
1036  if (!osDimHead.str().empty())
1037  osDimHead << ", ";
1038  osDimHead << *it;
1039  }
1040  else
1041  bTimeIsIn = true;
1042  }
1043  if (bTimeIsIn || !osDimHead.str().empty()) {
1044  out << "Mapping domain: ";
1045  if (bTimeIsIn) {
1046  out << "time";
1047  if (!osDimHead.str().empty())
1048  out << ", ";
1049  }
1050  out << osDimHead.str() << endl;
1051  }
1052 
1053  ConstMappingIterator *it = m.createConstIterator();
1054 
1055  if (!it->inRange()) {
1056  out << "Mapping is empty." << endl;
1057  out.flags(outFlags);
1058  delete it;
1059  return out;
1060  }
1061 
1062  Argument min = it->getPosition();
1063  Argument max = it->getPosition();
1064 
1065  typedef std::set<simtime_t> t_time_container_type;
1066  typedef std::set<argument_value_t> t_value_container_type;
1067 
1068  t_time_container_type timePositions;
1069  t_value_container_type otherPositions;
1070  std::size_t iMaxHeaderItemLen = m.toString(it->getPosition().getTime() * lTimeScale, 2).length();
1071  std::size_t iMaxLeftItemLen = 5 > sTableHead.length() ? 5 : sTableHead.length();
1072  const bool bIs2Dim = dims.size() == 2;
1073 
1074  if (bIs2Dim && bOnlyDimFound)
1075  bOnlyDimFound = false; // we have only the time and the requested dimension (fallback to normal case)
1076  timePositions.insert(it->getPosition().getTime());
1077  if (bIs2Dim || bOnlyDimFound) {
1078  Argument::const_iterator posValIt;
1079  if (bOnlyDimFound && (posValIt = it->getPosition().find(otherDim)) != it->getPosition().end()) {
1080  otherPositions.insert(it->getPosition().getArgValue(otherDim));
1081  iMaxLeftItemLen = std::max(iMaxLeftItemLen, m.toString(posValIt->second * lLeftColScale, 2).length());
1082  }
1083  else if (!bOnlyDimFound) {
1084  otherPositions.insert(it->getPosition().begin()->second);
1085  iMaxLeftItemLen = std::max(iMaxLeftItemLen, m.toString(it->getPosition().begin()->second * lLeftColScale, 2).length());
1086  }
1087  }
1088 
1089  while (it->hasNext()) {
1090  it->next();
1091  const Argument& pos = it->getPosition();
1092  const Argument::const_iterator posValItEnd = pos.end();
1093  Argument::const_iterator posValIt;
1094 
1095  min.setTime(std::min(min.getTime(), pos.getTime()));
1096  max.setTime(std::max(max.getTime(), pos.getTime()));
1097 
1098  timePositions.insert(pos.getTime());
1099 
1100  iMaxHeaderItemLen = std::max(iMaxHeaderItemLen, m.toString(pos.getTime() * lTimeScale, 2).length());
1101 
1102  if (bOnlyDimFound && (posValIt = pos.find(otherDim)) != posValItEnd) {
1103  iMaxLeftItemLen = std::max(iMaxLeftItemLen, m.toString(posValIt->second * lLeftColScale, 2).length());
1104  }
1105  for (Argument::const_iterator itA = pos.begin(); itA != posValItEnd; ++itA) {
1106  if (bIs2Dim || bOnlyDimFound) {
1107  if (!bOnlyDimFound || itA->first == otherDim) {
1108  otherPositions.insert(itA->second);
1109  iMaxLeftItemLen = std::max(iMaxLeftItemLen, m.toString(itA->second * lLeftColScale, 2).length());
1110  }
1111  }
1112  min.setArgValue(itA->first, std::min(min.getArgValue(itA->first), itA->second));
1113  max.setArgValue(itA->first, std::max(max.getArgValue(itA->first), itA->second));
1114  }
1115  }
1116  delete it;
1117 
1118  if (!bIs2Dim && !bOnlyDimFound) {
1119  if (!bOnlyDimFound && pOnlyDim != nullptr) {
1120  out << "map contains no " << pOnlyDim->getName() << " dimension!" << endl;
1121  out.flags(outFlags);
1122  return out;
1123  }
1124  else
1125  out << "domain - min=" << min << " max=" << max << endl;
1126  }
1127  if (bOnlyDimFound && otherPositions.empty()) {
1128  out << "Defines no own key entries for " << pOnlyDim->getName() << " dimension! That does NOT mean it doesn't define any attenuation." << endl;
1129  out.flags(outFlags);
1130  return out;
1131  }
1132 
1133  t_time_container_type::const_iterator tIt;
1134  const t_time_container_type::const_iterator tItEnd = timePositions.end();
1135  std::stringstream osBorder(std::stringstream::out);
1136  std::stringstream osHeader(std::stringstream::out);
1137  mixim::math::mW2dBm<argument_value_t> fctor2dBm;
1138 
1139  for (tIt = timePositions.begin(); tIt != tItEnd; ++tIt) {
1140  osHeader << m.toString(*tIt * lTimeScale, iMaxHeaderItemLen) << osHeader.fill();
1141  }
1142  osBorder.fill('-');
1143  osBorder << std::setw(iMaxLeftItemLen) << "" << osBorder.fill() << "+" << osBorder.fill() << std::setw(osHeader.str().length()) << "";
1144 
1145  out << osBorder.str() << std::endl;
1146  out << std::setw(iMaxLeftItemLen) << std::left << sTableHead << out.fill() << "|" << out.fill();
1147  out << osHeader.str() << std::endl;
1148  out << osBorder.str() << std::endl;
1149 
1150  it = m.createConstIterator();
1151 
1152  if (dims.size() == 1) {
1153  out << std::setw(iMaxLeftItemLen) << "value" << out.fill() << "|" << out.fill();
1154  while (it->inRange()) {
1155  out << m.toString(fctor2dBm(it->getValue()), iMaxHeaderItemLen) << out.fill();
1156  if (!it->hasNext()) {
1157  break;
1158  }
1159  it->next();
1160  }
1161  }
1162  else {
1163  t_value_container_type::const_iterator fIt = otherPositions.begin();
1164 
1165  tIt = timePositions.begin();
1166  out << m.toString((*fIt) * lLeftColScale, iMaxLeftItemLen) << out.fill() << "|" << out.fill();
1167  while (it->inRange()) {
1168  if (*fIt != it->getPosition().getArgValue(otherDim)) {
1169  ++fIt;
1170  out << std::endl << m.toString((*fIt) * lLeftColScale, iMaxLeftItemLen) << out.fill() << "|" << out.fill();
1171  tIt = timePositions.begin();
1172  assert(*fIt == it->getPosition().getArgValue(otherDim));
1173  }
1174 
1175  while (tIt != tItEnd && *tIt < it->getPosition().getTime()) {
1176  // blank item because the header time does not match
1177  ++tIt;
1178  out << std::setw(iMaxHeaderItemLen + 1) << "";
1179  }
1180  if (tIt != tItEnd) {
1181  // jump to next header item
1182  ++tIt;
1183  }
1184 
1185  out << m.toString(fctor2dBm(it->getValue()), iMaxHeaderItemLen) << out.fill();
1186 
1187  if (!it->hasNext()) {
1188  break;
1189  }
1190  it->next();
1191  }
1192  }
1193  delete it;
1194  out << std::endl << osBorder.str() << std::endl;
1195  out.flags(outFlags);
1196  return out;
1197  }
static const Dimension time
Shortcut to the time Dimension, same as &#39;Dimension("time")&#39;, but spares the parsing of a string...
Definition: MappingBase.h:64
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
container_type::const_iterator const_iterator
Const-iterator type for this set.
Definition: MappingBase.h:444
ConstMapping()
Initializes the ConstMapping with a the time dimension as domain.
Definition: MappingBase.h:935
_Base::value_type value_type
Definition: MappingBase.h:149
value< double, units::m > m
Definition: Units.h:1047
void inet::physicallayer::ConstMapping::swap ( ConstMapping s)
inline

Swaps data with another ConstMapping.

Parameters
sA ConstMapping of the same element and allocator types.

This exchanges the elements between two DimensionSet's in constant time. Note that the global std::swap() function is specialized such that std::swap(s1,s2) will feed to this function.

Referenced by inet::physicallayer::Mapping::swap(), inet::physicallayer::SimpleConstMapping::swap(), and inet::physicallayer::ConcatConstMapping< Operator >::swap().

903  {
904  //::swap(s); // swap the base class members
905  /* Swap all D members */
906  dimensions.swap(s.dimensions);
907  }
DimensionSet dimensions
The dimensions of this mappings domain.
Definition: MappingBase.h:879
value< double, units::s > s
Definition: Units.h:1049
void swap(DimensionSet &s)
Swaps data with another DimensionSet.
Definition: MappingBase.h:201
template<class T >
std::string inet::physicallayer::ConstMapping::toString ( T  v,
unsigned int  length 
) const
inlineprivate

Referenced by print().

912  {
913  std::stringstream osToStr(std::stringstream::out);
914 
915  using std::operator<<;
916 
917  osToStr << std::fixed;
918  osToStr.precision(16);
919  osToStr.width(length);
920  osToStr << std::right << v;
921 
922  return osToStr.str();
923  }
std::string inet::physicallayer::ConstMapping::toString ( simtime_t_cref  v,
unsigned int  length 
) const
inlineprivate
926  {
927  return toString(SIMTIME_DBL(v), length);
928  }
std::string toString(T v, unsigned int length) const
Definition: MappingBase.h:911

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const ConstMapping rMapToPrint 
)
friend
1200  {
1201  return rMapToPrint.print(out);
1202  }

Member Data Documentation

DimensionSet inet::physicallayer::ConstMapping::dimensions
protected

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