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; } }
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; }
const vector<int>& GenericType::toIntVector() const{ casadi_assert_message(isIntVector(),"type mismatch"); return static_cast<const IntVectorType*>(get())->d_; }
bool GenericType::isEmptyVector() const{ return (isIntVector() && toIntVector().size()==0 ) || (isDoubleVector() && toDoubleVector().size()==0 ) || (isStringVector() && toStringVector().size()==0 ); }