コード例 #1
0
ファイル: generic_type.cpp プロジェクト: cfpperche/casadi
bool GenericType::can_cast_to(opt_type other) const {
  switch (other) {
      case OT_BOOLEAN:
        return isBool() || isInt() || isDouble();
      case OT_BOOLVECTOR:
        return isIntVector() || isDoubleVector();
      case OT_INTEGER: case OT_REAL:
        return isInt() || isDouble();
      case OT_INTEGERVECTOR: case OT_REALVECTOR:
        return isDoubleVector() || isIntVector();
      default:
        return type_ == other;
  }
}
コード例 #2
0
ファイル: generic_type.cpp プロジェクト: kozatt/casadi
bool GenericType::operator!=(const GenericType& op2) const{
  if(isString() && op2.isString()){
    return toString().compare(op2.toString()) != 0;
  }

  if(isInt() && op2.isInt()){
    return toInt() != op2.toInt();
  }

  if(isDouble() && op2.isDouble()){
    return toDouble() != op2.toDouble();
  }

  if(isDoubleVector() && op2.isDoubleVector()){
    const vector<double> &v1 = toDoubleVector();
    const vector<double> &v2 = op2.toDoubleVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }

  if(isIntVector() && op2.isIntVector()){
    const vector<int> &v1 = toIntVector();
    const vector<int> &v2 = op2.toIntVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }
  
  // Different types
  return true;
}
コード例 #3
0
ファイル: generic_type.cpp プロジェクト: kozatt/casadi
const vector<double>& GenericType::toDoubleVector() const{
  casadi_assert_message(isDoubleVector(),"type mismatch");
  return static_cast<const DoubleVectorType*>(get())->d_;
}
コード例 #4
0
ファイル: generic_type.cpp プロジェクト: kozatt/casadi
bool GenericType::isEmptyVector() const{
  return (isIntVector() && toIntVector().size()==0 ) || (isDoubleVector() && toDoubleVector().size()==0 ) || (isStringVector() && toStringVector().size()==0 );
}