Skip to content

Commit

Permalink
Issue casadi#1586: Renamed GenericType::isNnn -> is_nnn
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Jan 11, 2016
1 parent 21119e2 commit c1c194d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 88 deletions.
108 changes: 54 additions & 54 deletions casadi/core/generic_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ namespace casadi {
bool GenericType::can_cast_to(TypeID other) const {
switch (other) {
case OT_BOOLEAN:
return isBool() || isInt() || isDouble();
return is_bool() || is_int() || is_double();
case OT_BOOLVECTOR:
return isIntVector() || isDoubleVector();
return is_int_vector() || is_double_vector();
case OT_INTEGER:
case OT_REAL:
return isInt() || isDouble();
return is_int() || is_double();
case OT_INTEGERVECTOR:
case OT_REALVECTOR:
return isDoubleVector() || isIntVector();
return is_double_vector() || is_int_vector();
case OT_STRINGVECTOR:
return isStringVector() || isString();
return is_string_vector() || is_string();
default:
return getType() == other;
}
Expand Down Expand Up @@ -118,54 +118,54 @@ namespace casadi {
}


bool GenericType::isBool() const {
bool GenericType::is_bool() const {
return getType()==OT_BOOLEAN;
}

bool GenericType::isInt() const {
bool GenericType::is_int() const {
return getType()==OT_INTEGER;
}

bool GenericType::isDouble() const {
bool GenericType::is_double() const {
return getType()==OT_REAL;
}

bool GenericType::isString() const {
bool GenericType::is_string() const {
return getType()==OT_STRING;
}

bool GenericType::is_emptyVector() const {
return (isIntVector() && toIntVector().size()==0) ||
(isIntVectorVector() && toIntVectorVector().size()==0) ||
(isDoubleVector() && toDoubleVector().size()==0) ||
(isStringVector() && toStringVector().size()==0);
bool GenericType::is_empty_vector() const {
return (is_int_vector() && toIntVector().size()==0) ||
(is_int_vector_vector() && toIntVectorVector().size()==0) ||
(is_double_vector() && toDoubleVector().size()==0) ||
(is_string_vector() && toStringVector().size()==0);
}

bool GenericType::isIntVector() const {
bool GenericType::is_int_vector() const {
return getType()==OT_INTEGERVECTOR;
}

bool GenericType::isIntVectorVector() const {
bool GenericType::is_int_vector_vector() const {
return getType()==OT_INTEGERVECTORVECTOR;
}

bool GenericType::isDoubleVector() const {
bool GenericType::is_double_vector() const {
return getType()==OT_REALVECTOR;
}

bool GenericType::isStringVector() const {
bool GenericType::is_string_vector() const {
return getType()==OT_STRINGVECTOR;
}

bool GenericType::isFunction() const {
bool GenericType::is_function() const {
return getType()==OT_FUNCTION;
}

bool GenericType::isVoidPointer() const {
bool GenericType::is_void_pointer() const {
return getType()==OT_VOIDPTR;
}

bool GenericType::isDict() const {
bool GenericType::is_dict() const {
return getType()==OT_DICT;
}

Expand Down Expand Up @@ -228,130 +228,130 @@ namespace casadi {
}

const bool& GenericType::asBool() const {
casadi_assert(isBool());
casadi_assert(is_bool());
return static_cast<const BoolType*>(get())->d_;
}

const int& GenericType::asInt() const {
casadi_assert(isInt());
casadi_assert(is_int());
return static_cast<const IntType*>(get())->d_;
}

const double& GenericType::asDouble() const {
casadi_assert(isDouble());
casadi_assert(is_double());
return static_cast<const DoubleType*>(get())->d_;
}

const std::string& GenericType::asString() const {
casadi_assert(isString());
casadi_assert(is_string());
return static_cast<const StringType*>(get())->d_;
}

const std::vector<int>& GenericType::asIntVector() const {
casadi_assert(isIntVector());
casadi_assert(is_int_vector());
return static_cast<const IntVectorType*>(get())->d_;
}

const std::vector<std::vector<int> >& GenericType::asIntVectorVector() const {
casadi_assert(isIntVectorVector());
casadi_assert(is_int_vector_vector());
return static_cast<const IntVectorVectorType*>(get())->d_;
}

const std::vector<double>& GenericType::asDoubleVector() const {
casadi_assert(isDoubleVector());
casadi_assert(is_double_vector());
return static_cast<const DoubleVectorType*>(get())->d_;
}

const std::vector<std::string>& GenericType::asStringVector() const {
casadi_assert(isStringVector());
casadi_assert(is_string_vector());
return static_cast<const StringVectorType*>(get())->d_;
}

const GenericType::Dict& GenericType::asDict() const {
casadi_assert(isDict());
casadi_assert(is_dict());
return static_cast<const DictType*>(get())->d_;
}

const Function& GenericType::asFunction() const {
casadi_assert(isFunction());
casadi_assert(is_function());
return static_cast<const FunctionType*>(get())->d_;
}

void* const & GenericType::asVoidPointer() const {
casadi_assert(isVoidPointer());
casadi_assert(is_void_pointer());
return static_cast<const VoidPointerType*>(get())->d_;
}

bool GenericType::toBool() const {
if (isBool()) {
if (is_bool()) {
return asBool();
} else if (isInt()) {
} else if (is_int()) {
return static_cast<bool>(toInt());
} else {
casadi_assert_message(isBool(), "type mismatch");
casadi_assert_message(is_bool(), "type mismatch");
return false;
}
}

int GenericType::toInt() const {
if (isDouble()) {
if (is_double()) {
double v = toDouble();
casadi_assert_message(v == std::floor(v), "The value is not an integer");
return static_cast<int>(v);
} else if (isBool()) {
} else if (is_bool()) {
return static_cast<int>(toBool());
} else {
casadi_assert_message(isInt(), "type mismatch");
casadi_assert_message(is_int(), "type mismatch");
return asInt();
}
}

double GenericType::toDouble() const {
if (isInt()) {
if (is_int()) {
return static_cast<double>(toInt());
} else {
casadi_assert_message(isDouble(), "type mismatch");
casadi_assert_message(is_double(), "type mismatch");
return asDouble();
}
}

string GenericType::toString() const {
casadi_assert_message(isString(), "type mismatch");
casadi_assert_message(is_string(), "type mismatch");
return asString();
}

vector<int> GenericType::toIntVector() const {
casadi_assert_message(isIntVector(), "type mismatch");
casadi_assert_message(is_int_vector(), "type mismatch");
return asIntVector();
}

vector<vector<int> > GenericType::toIntVectorVector() const {
casadi_assert_message(isIntVectorVector(), "type mismatch");
casadi_assert_message(is_int_vector_vector(), "type mismatch");
return asIntVectorVector();
}

vector<double> GenericType::toDoubleVector() const {
casadi_assert_message(isDoubleVector(), "type mismatch");
casadi_assert_message(is_double_vector(), "type mismatch");
return asDoubleVector();
}

vector<string> GenericType::toStringVector() const {
if (isString()) {
if (is_string()) {
std::string s = asString();
return vector<string>(1, s);
} else {
casadi_assert_message(isStringVector(), "type mismatch");
casadi_assert_message(is_string_vector(), "type mismatch");
return asStringVector();
}
}

Dict GenericType::toDict() const {
casadi_assert_message(isDict(), "type mismatch");
casadi_assert_message(is_dict(), "type mismatch");
return asDict();
}

Function GenericType::toFunction() const {
casadi_assert_message(isFunction(), "type mismatch");
casadi_assert_message(is_function(), "type mismatch");
return asFunction();
}

Expand All @@ -360,19 +360,19 @@ namespace casadi {
}

bool GenericType::operator!=(const GenericType& op2) const {
if (isString() && op2.isString()) {
if (is_string() && op2.is_string()) {
return toString().compare(op2.toString()) != 0;
}

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

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

if (isDoubleVector() && op2.isDoubleVector()) {
if (is_double_vector() && op2.is_double_vector()) {
const vector<double> &v1 = toDoubleVector();
const vector<double> &v2 = op2.toDoubleVector();
if (v1.size() != v2.size()) return true;
Expand All @@ -381,7 +381,7 @@ namespace casadi {
return false;
}

if (isIntVector() && op2.isIntVector()) {
if (is_int_vector() && op2.is_int_vector()) {
const vector<int> &v1 = toIntVector();
const vector<int> &v2 = op2.toIntVector();
if (v1.size() != v2.size()) return true;
Expand All @@ -390,7 +390,7 @@ namespace casadi {
return false;
}

if (isIntVectorVector() && op2.isIntVectorVector()) {
if (is_int_vector_vector() && op2.is_int_vector_vector()) {
const vector< vector<int> > &v1 = toIntVectorVector();
const vector< vector<int> > &v2 = op2.toIntVectorVector();
if (v1.size() != v2.size()) return true;
Expand Down
24 changes: 12 additions & 12 deletions casadi/core/generic_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ namespace casadi {

///@{
/** \brief Check if a particular type */
bool isBool() const;
bool isInt() const;
bool isDouble() const;
bool isString() const;
bool is_emptyVector() const;
bool isIntVector() const;
bool isIntVectorVector() const;
bool isDoubleVector() const;
bool isStringVector() const;
bool isDict() const;
bool isFunction() const;
bool isVoidPointer() const;
bool is_bool() const;
bool is_int() const;
bool is_double() const;
bool is_string() const;
bool is_empty_vector() const;
bool is_int_vector() const;
bool is_int_vector_vector() const;
bool is_double_vector() const;
bool is_string_vector() const;
bool is_dict() const;
bool is_function() const;
bool is_void_pointer() const;
///@}

///@{
Expand Down
6 changes: 3 additions & 3 deletions casadi/core/options_functionality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void setAdaptorOptions(Dict& dict, const string &name, const Dict &op) {
if (it == dict.end()) {
// Create an empty dictionary if not
dict[adaptor_name] = Dict();
} else if (!dict[adaptor_name].isDict()) {
} else if (!dict[adaptor_name].is_dict()) {
// If an entry is found, make sure it is a dictionary
casadi_error("setAdaptorOptions: Dict expected, but got " << dict[adaptor_name] << ".");
}
Expand Down Expand Up @@ -172,7 +172,7 @@ void OptionsFunctionalityNode::setOption(const string &name, const GenericType &
}

// If we have an empty vector, than we are not strict about the type
if (op.is_emptyVector()) {
if (op.is_empty_vector()) {
dictionary_[name] = GenericType::from_type(allowed_options[name]);
return;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ void OptionsFunctionalityNode::setOption(const string &name, const GenericType &
if (!allowed_vals_[name].empty()) {
bool found;
GenericType problem = op;
if (op.isStringVector()) {
if (op.is_string_vector()) {
found = true;
const std::vector<std::string> & opv = op.toStringVector();
for (std::vector<std::string>::const_iterator it=opv.begin();it!=opv.end();it++) {
Expand Down
6 changes: 3 additions & 3 deletions casadi/core/sx/sx_elem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace casadi {
casadi_error("Cannot compute the truth value of a CasADi SXElem symbolic expression.")
}

bool SXElem::isDoubled() const {
bool SXElem::is_doubled() const {
return is_op(OP_ADD) && is_equal(dep(0), dep(1), SXNode::eq_depth_);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ namespace casadi {
return -x;
else if (is_equal(x, y, SXNode::eq_depth_)) // terms are equal
return 1;
else if (x.isDoubled() && is_equal(y, 2))
else if (x.is_doubled() && is_equal(y, 2))
return x.dep(0);
else if (x.is_op(OP_MUL) && is_equal(y, x.dep(0), SXNode::eq_depth_))
return x.dep(1);
Expand All @@ -293,7 +293,7 @@ namespace casadi {
return y.inv();
else if (y.is_op(OP_INV))
return x*y.inv();
else if (x.isDoubled() && y.isDoubled())
else if (x.is_doubled() && y.is_doubled())
return x.dep(0) / y->dep(0);
else if (y.is_constant() && x.is_op(OP_DIV) && x.dep(1).is_constant() &&
y.getValue()*x.dep(1).getValue()==1) // (x/5)/0.2
Expand Down
2 changes: 1 addition & 1 deletion casadi/core/sx/sx_elem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace casadi {
inline explicit operator int() const { return getIntValue();}

/** \brief Check if the node is the sum of two equal expressions */
bool isDoubled() const;
bool is_doubled() const;

/** \brief Get the number of dependencies of a binary SXElem */
int n_dep() const;
Expand Down
Loading

0 comments on commit c1c194d

Please sign in to comment.