//---------------------------------------------------------------------------
bool IValue::operator!=(const IValue &a_Val) const
{
    char_type type1 = GetType(),
        type2 = a_Val.GetType();

    if (type1 == type2 || (IsScalar() && a_Val.IsScalar()))
    {
        switch (GetType())
        {
        case 's': return GetString() != a_Val.GetString();
        case 'i':
        case 'f': return GetFloat() != a_Val.GetFloat();
        case 'c': return (GetFloat() != a_Val.GetFloat()) || (GetImag() != a_Val.GetImag());
        case 'b': return GetBool() != a_Val.GetBool();
        case 'v': return true;
        case 'm': if (GetRows() != a_Val.GetRows() || GetCols() != a_Val.GetCols())
        {
            return true;
        }
                  else
                  {
                      for (int i = 0; i < GetRows(); ++i)
                      {
                          if (const_cast<IValue*>(this)->At(i) != const_cast<IValue&>(a_Val).At(i))
                              return true;
                      }

                      return false;
                  }
        default:
            ErrorContext err;
            err.Errc = ecINTERNAL_ERROR;
            err.Pos = -1;
            err.Type2 = GetType();
            err.Type1 = a_Val.GetType();
            throw ParserError(err);
        } // switch this type
    }
    else
    {
        return true;
    }
}
Esempio n. 2
0
  //---------------------------------------------------------------------------
  Value::Value(const IValue &a_Val)
    :IValue(cmVAL)
    ,m_psVal(nullptr)
    ,m_pvVal(nullptr)
    ,m_pCache(nullptr)
  {
    Reset();

    switch(a_Val.GetType())
    {
    case 'i': 
    case 'f': 
    case 'b': m_val = cmplx_type(a_Val.GetFloat(), 0);
              break;


    case 'c': m_val = cmplx_type(a_Val.GetFloat(), a_Val.GetImag());
              break;

    case 's': if (!m_psVal)
                m_psVal = new string_type(a_Val.GetString());
              else
               *m_psVal = a_Val.GetString();
              break;

    case 'm': if (!m_pvVal) 
                m_pvVal = new matrix_type(a_Val.GetArray());
              else
               *m_pvVal  = a_Val.GetArray();  
              break;

    case 'v': break;
    default:  MUP_FAIL(INVALID_TYPE_CODE);
    }
    
    m_cType = a_Val.GetType();
  }