Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6643 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Jan 21, 2006, 3:04:40 PM (19 years ago)
Author:
bensch
Message:

trunk: MultiType comparisons

Location:
trunk/src/lib/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/multi_type.cc

    r5660 r6643  
    120120  return *this;
    121121}
     122
     123/**
     124 * @brief checks if the two Multitypes match
     125 * @param mt MultiType to check against this one
     126 * @returns true on match. false otherwise
     127 *
     128 * Two MultiType match if and only if
     129 *  1. the internal Type is the same
     130 *  2. the stored values match
     131 */
     132bool MultiType::operator==(const MultiType& mt) const
     133{
     134  if (this->type != mt.type)
     135    return false;
     136
     137  switch (this->type)
     138  {
     139    case MT_NULL:
     140      return true;
     141    case MT_BOOL:
     142      return (this->value.Bool == mt.value.Bool);
     143    case MT_INT:
     144      return (this->value.Int == mt.value.Int);
     145    case MT_CHAR:
     146      return (this->value.Char == mt.value.Char);
     147    case MT_FLOAT:
     148      return (this->value.Float == mt.value.Float);
     149    case MT_STRING:
     150      if (this->value.String != NULL && mt.value.String != NULL)
     151        return (!strcmp(this->value.String, mt.value.String));
     152      else
     153        return (this->value.String == NULL && mt.value.String == NULL);
     154  }
     155}
     156
     157/**
     158 * @brief checks if the internal value matches the boolean value.
     159 * @param value to check against this one
     160 * @returns true on match. false otherwise
     161 *
     162 * Two MultiType match if and only if
     163 *  1. the stored values match the given Value
     164 */
     165bool MultiType::operator==(const char* value) const
     166{
     167  if (this->value.String != NULL && value != NULL)
     168    return (!strcmp(this->value.String, value));
     169  else
     170    return (this->value.String == NULL && value == NULL);
     171}
     172
    122173
    123174/**
  • trunk/src/lib/util/multi_type.h

    r5659 r6643  
    4242    virtual ~MultiType();
    4343
    44     MultiType& operator= (const MultiType& mt);
     44    MultiType& operator=(const MultiType& mt);
     45    bool operator==(const MultiType& mt) const;
     46    bool operator==(bool value) const { return this->getBool() == value; };
     47    bool operator==(int value)const { return this->getInt() == value; };
     48    bool operator==(float value)const { return this->getFloat() ==  value; };
     49    bool operator==(char value) const { return this->getChar() == value; };
     50    bool operator==(const char* value) const;
    4551
    4652    void setType(int type);
Note: See TracChangeset for help on using the changeset viewer.