Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

Argument Class Reference
[mapping - classes representing mathematical mappings]

Defines an argument for a mapping. More...

#include <MappingBase.h>

List of all members.

Public Types

typedef std::pair< Dimension,
double > * 
iterator
 Iterator type for this set.
typedef const std::pair
< Dimension, double > * 
const_iterator
 Const-iterator type for this set.

Public Member Functions

 Argument (simtime_t timeVal=0)
 Initialize this argument with the passed value for the time dimension.
 Argument (const DimensionSet &dims, simtime_t timeVal=0)
 Initializes the Argument with the dimensions of the passed DimensionSet set to zero, and the passed value for the time (or zero, if omitted).
simtime_t getTime () const
 Returns the time value of this argument.
void setTime (simtime_t time)
 Changes the time value of this argument.
bool hasArgVal (const Dimension &dim) const
 Returns true if this Argument has a value for the passed Dimension.
double getArgValue (const Dimension &dim) const
 Returns the value for the specified dimension.
void setArgValue (const Dimension &dim, double value)
 Changes the value for the specified dimension.
void setArgValues (const Argument &o, bool ignoreUnknown=false)
 Update the values of this Argument with the values of the passed Argument.
bool isSamePosition (const Argument &other) const
 Returns true if the passed Argument points to the same position.
bool operator== (const Argument &o) const
 Two Arguments are compared equal if they have the same dimensions and the same values.
bool isClose (const Argument &o, double epsilon=0.000001) const
 Two Arguments are compared close if they have the same dimensions and their values don't differ more then a specific epsilon.
bool operator< (const Argument &o) const
 Returns true if this Argument is smaller then the passed Argument. The dimensions of the Arguments have to be the same.
double compare (const Argument &o, const DimensionSet &dims) const
 Compares this Argument with the passed Argument in the dimensions of the passed DimensionsSet. (Every other Dimension is asserted equal).
DimensionSet getDimensions () const
 Returns the dimensions this argument is defined over.
void operator= (const Argument &o)
 Fast implementation of the copy-operator then the default implementation.
iterator begin ()
 Returns an iterator to the first argument value in this Argument.
const_iterator begin () const
 Returns an iterator to the first argument value in this Argument.
iterator end ()
 Returns an iterator to the value behind the last argument value.
const_iterator end () const
 Returns an iterator to the value behind the last argument value.
iterator find (const Dimension &dim)
 Returns an iterator to the Argument value for the passed Dimension.
const_iterator find (const Dimension &dim) const
 Returns an iterator to the Argument value for the passed Dimension.
iterator lower_bound (const Dimension &dim)
 Returns an iterator to the first Argument value which dimension compares greater or equal to the passed Dimension.
const_iterator lower_bound (const Dimension &dim) const
 Returns an iterator to the first Argument value which dimension compares greater or equal to the passed Dimension.

Protected Member Functions

iterator insertValue (iterator pos, const Dimension &dim, double value, bool ignoreUnknown=false)
 Inserts the passed value for the passed Dimension into this Argument.

Protected Attributes

simtime_t time
 Stores the time dimension in Omnets time type.
std::pair< Dimension, double > values [10]
 Maps the dimensions of this Argument to their values.
unsigned int count
 The number of Dimensions this Argument has.

Friends

std::ostream & operator<< (std::ostream &out, const Argument &d)
 Output operator for Arguments.

Detailed Description

Defines an argument for a mapping.

Defines values for a specified set of dimensions, but at least for the time dimension.

Note: Currently an Argument can be maximal defined over ten Dimensions plus the time dimension!

Author:
Karl Wessel

Definition at line 279 of file MappingBase.h.


Member Function Documentation

double Argument::compare ( const Argument o,
const DimensionSet dims 
) const

Compares this Argument with the passed Argument in the dimensions of the passed DimensionsSet. (Every other Dimension is asserted equal).

Returns:
< 0 - passed Argument is bigger = 0 - Arguments are equal > 0 - passed Argument is smaller

See "operator<" for definition of smaller, equal and bigger.

Definition at line 316 of file MappingBase.cc.

References count, time, and values.

Referenced by MappingUtils::findMax(), and MappingUtils::findMin().

                                                                         {
  DimensionSet::const_reverse_iterator rIt = dims.rbegin();

  int ind = (int)count - 1;
  int indO = (int)o.count - 1;

  //iterate through passed dimensions and compare arguments in these dimensions
  while(rIt != dims.rend()){
    const Dimension& dim = *rIt;

    //catch special case time (after which we can abort)
    if(dim == Dimension::time)
    {
      return SIMTIME_DBL(time - o.time);
    }

    //iterate indices to the passed dimensions or the next smaller
    while(ind >= 0 && dim < values[ind].first)
      --ind;
    while(indO >= 0 && dim < o.values[indO].first)
      --indO;

    //if the last dimensions could not be found compare the time
    if(ind < 0 || indO < 0)
    {
      return SIMTIME_DBL(time - o.time);
    }

    //if both Arguments are defined in the current dimensions
    //compare them (otherwise we assume them equal and continue)
    if(values[ind].first == dim && o.values[indO].first == dim){
      double diff = values[ind].second - o.values[indO].second;

      //if(fabs(diff) > 0.000001)
      if(diff != 0)
        return diff;
    }
    ++rIt;
  }
  return 0;
}

Argument::iterator Argument::find ( const Dimension dim  ) 

Returns an iterator to the Argument value for the passed Dimension.

Returns end() if there is no Argument for that dimension.

Definition at line 111 of file MappingBase.cc.

References begin(), end(), and Dimension::time_static().

Referenced by getArgValue(), and hasArgVal().

                                                   {
  assert(!(dim == Dimension::time_static()));

  for(iterator it = begin(); it != end() && it->first <= dim; ++it){
    if(it->first == dim)
      return it;
  }

  return end();
}

Argument::const_iterator Argument::find ( const Dimension dim  )  const

Returns an iterator to the Argument value for the passed Dimension.

Returns end() if there is no Argument for that dimension.

Definition at line 121 of file MappingBase.cc.

References begin(), end(), and Dimension::time_static().

                                                               {
  assert(!(dim == Dimension::time_static()));

  for(const_iterator it = begin(); it != end() && it->first <= dim; ++it){
    if(it->first == dim)
      return it;
  }

  return end();
}

double Argument::getArgValue ( const Dimension dim  )  const

Returns the value for the specified dimension.

Note: Don't use this function to get the time value! Use "getTime()" instead.

Returns zero if no value with the specified dimension is set for this argument.

Definition at line 155 of file MappingBase.cc.

References end(), and find().

Referenced by FilledUpMapping::appendValue(), SimpleConstMapping::createKeyEntries(), MappingUtils::findMax(), MappingUtils::findMin(), SimplePathlossConstMapping::getValue(), MultiDimMapping< Linear >::getValue(), MultiDimMappingIterator< Linear >::iterateTo(), MultiDimMappingIterator< Linear >::jumpTo(), ConstMapping::print(), ThresholdDecider::printMapping(), and MultiDimMapping< Linear >::setValue().

{
  const_iterator it = find(dim);

  if(it == end())
    return double();

  return it->second;
}

DimensionSet Argument::getDimensions (  )  const [inline]

Returns the dimensions this argument is defined over.

Note: this method has linear complexity over the number of dimensions, since the DimensionSet has to be created from the values and their dimensions inside this Argument.

Definition at line 437 of file MappingBase.h.

References DimensionSet::addDimension(), count, Dimension::time_static(), and values.

Referenced by MappingUtils::findMax(), MappingUtils::findMin(), operator<(), and SimpleConstMappingIterator::SimpleConstMappingIterator().

                                     {
    DimensionSet res(Dimension::time_static());

    for(unsigned int i = 0; i < count; i++)
      res.addDimension(values[i].first);

    return res;
  }

Argument::iterator Argument::insertValue ( iterator  pos,
const Dimension dim,
double  value,
bool  ignoreUnknown = false 
) [protected]

Inserts the passed value for the passed Dimension into this Argument.

The parameter "pos" defines the position inside the Dimension<->Value-pair array to start searching for the dimension to set.

If the "ignoreUnknown"-parameter is set to true the new value is only set if the Dimension was defined in this Argument before (means, no new DImensions are added to the Argument).

The method returns the position inside the array the value was inserted.

Definition at line 172 of file MappingBase.cc.

References count, and end().

Referenced by setArgValue(), and setArgValues().

                                                                                                          {
  while(pos != end() && !(dim < pos->first)){

    if(pos->first == dim){
      pos->second = value;
      return pos;
    }
    ++pos;
  }

  if(ignoreUnknown)
    return pos;

  if(pos == end()){
    count++;
    *pos = std::pair<Dimension, double>(dim, value);
  } else {
    count++;
    iterator tmpPos = pos;
    std::pair<Dimension, double> n = *tmpPos;
    *tmpPos = std::pair<Dimension, double>(dim, value);
    while(++tmpPos != end()){
      std::pair<Dimension, double> tmp = *tmpPos;
      *tmpPos = n;
      n = tmp;
    }
  }

  return pos;
}

bool Argument::isSamePosition ( const Argument other  )  const

Returns true if the passed Argument points to the same position.

The functions returns true if every Dimension in the passed Argument exists in this Argument and their values are the same. The difference to the == operator is that the dimensions of the passed Argument can be a subset of the dimensions of this Argument.

Definition at line 212 of file MappingBase.cc.

References begin(), count, end(), and time.

{
  if(count < o.count){
    return false;
  }

  //if(fabs(time - o.time) > 0.000001){
  if(time != o.time){
    return false;
  }

  if(o.count == 0)
    return true;

  const_iterator itO = o.begin();
  const_iterator it = begin();

  while (it != end())
  {
    if (itO->first < it->first) {
      break;
    } else if (it->first < itO->first)
      ++it;
    else {
      //if((fabs(values[it].second - o.values[itO].second) > 0.000001)){
      if(it->second != itO->second){
        break;
      }
      ++it;
      ++itO;
    }
    if (itO == o.end()) return true;
  }

  return false;
}

bool Argument::operator< ( const Argument o  )  const

Returns true if this Argument is smaller then the passed Argument. The dimensions of the Arguments have to be the same.

An Argument is compared smaller than another Argument if the value of the Dimension with the highest id is compared smaller. If the value of the highest Dimension is compared bigger the Argument isn't compared smaller (method returns false). If the values of the Dimension with the highest Dimension are equal, the next smaller Dimension is compared.

Definition at line 301 of file MappingBase.cc.

References count, getDimensions(), time, and values.

{
  assert(getDimensions() == o.getDimensions());

  for(int it = (int)o.count - 1; it >= 0; --it){
    double diff = values[it].second - o.values[it].second;
    //if(fabs(diff) > 0.000001){
    if(diff != 0){
      return diff < 0.0;
    }
  }

  return (time - o.time) < 0;
}

void Argument::setArgValue ( const Dimension dim,
double  value 
)

Changes the value for the specified dimension.

Note: Don't use this function to change the time value! Use "setTime()" instead.

If the argument doesn't already contain a value for the specified dimension the new dimension is added.

Definition at line 165 of file MappingBase.cc.

References begin(), insertValue(), and Dimension::time_static().

Referenced by Decider80211::calcChannelSenseRSSI(), Decider80211::checkIfSignalOk(), SimpleConstMapping::createKeyEntries(), SimpleMacLayer::createMapping(), BaseMacLayer::createSingleFrequencyMapping(), RandomFrequencyOnlyModel::filterSignal(), RandomFreqTimeModel::filterSignal(), ConstMapping::print(), ThresholdDecider::printMapping(), and Decider80211::processNewSignal().

{
  assert(!(dim == Dimension::time_static()));

  insertValue(begin(), dim, value);
}

void Argument::setArgValues ( const Argument o,
bool  ignoreUnknown = false 
)

Update the values of this Argument with the values of the passed Argument.

Only the dimensions from the passed Argument are updated or added.

If the ignoreUnknown parameter is set to true, only the Dimensions already inside the Argument are updated.

Definition at line 203 of file MappingBase.cc.

References begin(), end(), insertValue(), and time.

Referenced by SimpleConstMappingIterator::iterateTo(), SimpleConstMappingIterator::jumpTo(), and SimpleConstMappingIterator::SimpleConstMappingIterator().

                                                                {
  time = o.time;

  iterator pos = begin();
  for(const_iterator i = o.begin(); i != o.end(); i++){
    pos = insertValue(pos, i->first, i->second, ingoreUnknown);
  }
}


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Argument d 
) [friend]

Output operator for Arguments.

Produces output of form "(x1, x2, x3, <...>)".

Definition at line 451 of file MappingBase.h.

                                                                    {
    out << "(" << d.time;

    for(unsigned int i = 0; i < d.count; i++){
      out << ", " << d.values[i].second;
    }
      return (out << ")");
    }


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