]> www.ginac.de Git - ginac.git/commitdiff
removed a lot of superfluous const_cast<>()s
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Jun 2001 19:32:57 +0000 (19:32 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 21 Jun 2001 19:32:57 +0000 (19:32 +0000)
ginac/constant.cpp
ginac/container.pl
ginac/matrix.cpp
ginac/numeric.cpp
ginac/power.cpp
ginac/relational.cpp
ginac/structure.pl
ginac/symbol.h
ginsh/ginsh_parser.yy

index 22923855b4f90d232b0ccc6e661d848bec8fc9a0..4ca94921627c5d4c31324fd8c9774f8ed29fe9bc 100644 (file)
@@ -191,18 +191,20 @@ ex constant::derivative(const symbol & s) const
 int constant::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, constant));
-       // const constant & o=static_cast<constant &>(const_cast<basic &>(other));
-       // return name.compare(o.name);
-       const constant *o = static_cast<const constant *>(&other);
-       if (serial==o->serial) return 0;
-       return serial < o->serial ? -1 : 1;
+       const constant &o = static_cast<const constant &>(other);
+
+       if (serial == o.serial)
+               return 0;
+       else
+               return serial < o.serial ? -1 : 1;
 }
 
 bool constant::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, constant));
-       const constant *o = static_cast<const constant *>(&other);
-       return serial==o->serial;
+       const constant &o = static_cast<const constant &>(other);
+
+       return serial == o.serial;
 }
 
 unsigned constant::calchash(void) const
index 7b8304bd64d8a65e324ec6086b40125dea11c095..bed117f6acc37476190f6ee6517eacdf82757067 100755 (executable)
@@ -467,35 +467,36 @@ ex ${CONTAINER}::subs(const lst & ls, const lst & lr, bool no_pattern) const
 int ${CONTAINER}::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<${CONTAINER}>(other));
-       ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
-                                                                       (const_cast<basic &>(other));
-       int cmpval;
-       ${STLT}::const_iterator it1=seq.begin();
-       ${STLT}::const_iterator it2=o.seq.begin();
-
-       for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
-               cmpval=(*it1).compare(*it2);
-               if (cmpval!=0) return cmpval;
-       }
+       ${CONTAINER} const & o = static_cast<const ${CONTAINER} &>(other);
+
+       ${STLT}::const_iterator it1 = seq.begin(), it1end = seq.end(),
+                               it2 = o.seq.begin(), it2end = o.seq.end();
 
-       if (it1==seq.end()) {
-               return (it2==o.seq.end() ? 0 : -1);
+       while (it1 != it1end && it2 != it2end) {
+               int cmpval = it1->compare(*it2);
+               if (cmpval)
+                       return cmpval;
+               ++it1; ++it2;
        }
 
-       return 1;
+       return (it1 == it1end) ? (it2 == it2end ? 0 : -1) : 1;
 }
 
 bool ${CONTAINER}::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<${CONTAINER}>(other));
-       ${CONTAINER} const & o = static_cast<${CONTAINER} const &>(const_cast<basic &>(other));
-       if (seq.size()!=o.seq.size()) return false;
+       ${CONTAINER} const &o = static_cast<const ${CONTAINER} &>(other);
+
+       if (seq.size() != o.seq.size())
+               return false;
 
-       ${STLT}::const_iterator it1 = seq.begin();
-       ${STLT}::const_iterator it2 = o.seq.begin();
+       ${STLT}::const_iterator it1 = seq.begin(), it1end = seq.end(),
+                               it2 = o.seq.begin();
 
-       for (; it1!=seq.end(); ++it1, ++it2) {
-               if (!(*it1).is_equal(*it2)) return false;
+       while (it1 != it1end) {
+               if (!it1->is_equal(*it2))
+                       return false;
+               ++it1; ++it2;
        }
 
        return true;
index 9f9f67a82c83b62e76431de79ea4bf4054a05047..b133b6163beb989ea1a7e0f977d2ba85b0b0ed2e 100644 (file)
@@ -237,7 +237,7 @@ ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const
 int matrix::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, matrix));
-       const matrix & o = static_cast<matrix &>(const_cast<basic &>(other));
+       const matrix & o = static_cast<const matrix &>(other);
        
        // compare number of rows
        if (row != o.rows())
index eb9afa19d7c0c2feb2cf503907ec95317f9861a9..b29bf9f1c24f9bf101f017b6f0c758daa671cc7b 100644 (file)
@@ -531,7 +531,7 @@ bool numeric::has(const ex &other) const
 {
        if (!is_exactly_of_type(*other.bp, numeric))
                return false;
-       const numeric &o = static_cast<numeric &>(const_cast<basic &>(*other.bp));
+       const numeric &o = static_cast<const numeric &>(*other.bp);
        if (this->is_equal(o) || this->is_equal(-o))
                return true;
        if (o.imag().is_zero())  // e.g. scan for 3 in -3*I
@@ -576,7 +576,7 @@ ex numeric::evalf(int level) const
 int numeric::compare_same_type(const basic &other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, numeric));
-       const numeric &o = static_cast<numeric &>(const_cast<basic &>(other));
+       const numeric &o = static_cast<const numeric &>(other);
        
        return this->compare(o);
 }
@@ -585,9 +585,9 @@ int numeric::compare_same_type(const basic &other) const
 bool numeric::is_equal_same_type(const basic &other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other,numeric));
-       const numeric *o = static_cast<const numeric *>(&other);
+       const numeric &o = static_cast<const numeric &>(other);
        
-       return this->is_equal(*o);
+       return this->is_equal(o);
 }
 
 
index 47efc2fd3806583b0e61197354111f090b11755e..76c72acc58160379f1a17b015f04e282a85deedd 100644 (file)
@@ -544,14 +544,13 @@ ex power::derivative(const symbol & s) const
 int power::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, power));
-       const power & o=static_cast<const power &>(const_cast<basic &>(other));
+       const power &o = static_cast<const power &>(other);
 
-       int cmpval;
-       cmpval=basis.compare(o.basis);
-       if (cmpval==0) {
+       int cmpval = basis.compare(o.basis);
+       if (cmpval)
+               return cmpval;
+       else
                return exponent.compare(o.exponent);
-       }
-       return cmpval;
 }
 
 unsigned power::return_type(void) const
index f657f8100d96ef67a5d1200bc3c4cdb04baf85db..88f2ad643b36659c03cdae2299533a150b971257 100644 (file)
@@ -193,21 +193,16 @@ ex relational::simplify_ncmul(const exvector & v) const
 int relational::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_exactly_of_type(other, relational));
-       const relational & oth=static_cast<const relational &>(const_cast<basic &>(other));
-       
-       int cmpval;
+       const relational &oth = static_cast<const relational &>(other);
        
        if (o == oth.o) {
-               cmpval = lh.compare(oth.lh);
-               if (cmpval==0)
-                       return rh.compare(oth.rh);
-               else
+               int cmpval = lh.compare(oth.lh);
+               if (cmpval)
                        return cmpval;
+               else
+                       return rh.compare(oth.rh);
        }
-       if (o<oth.o)
-               return -1;
-       else
-               return 1;
+       return (o < oth.o) ? -1 : 1;
 }
 
 unsigned relational::return_type(void) const
index 8b644540ca4cee81776156d810c6c203b4abf5d5..8303dbe4f731b6937227f3b134ab057c3be2ca79 100755 (executable)
@@ -433,8 +433,7 @@ ${subs_statements}
 int ${STRUCTURE}::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
-       ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
-                                                                       (const_cast<basic &>(other));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(other);
        int cmpval;
 ${compare_statements}
        return 0;
@@ -443,8 +442,7 @@ ${compare_statements}
 bool ${STRUCTURE}::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
-       ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
-                                                                       (const_cast<basic &>(other));
+       ${STRUCTURE} const &o = static_cast<const ${STRUCTURE} &>(other);
 ${is_equal_statements}
        return true;
 }
index 9bbf3f2eb126ab3624a3c5f9db68defa18afd271..76b87720b02b1f9a1dec31870b38c518784e55ea 100644 (file)
@@ -123,6 +123,11 @@ inline const symbol &ex_to_symbol(const ex &e)
        return static_cast<const symbol &>(*e.bp);
 }
 
+inline symbol &ex_to_nonconst_symbol(const ex &e)
+{
+       return static_cast<symbol &>(*e.bp);
+}
+
 /** Specialization of is_exactly_a<symbol>(obj) for symbol objects. */
 template<> inline bool is_exactly_a<symbol>(const basic & obj)
 {
index 2e514778b27085a9d4db6f1bfbb30f86201f768a..98213e25e4282db6772e77dc0a8db51d57b70ef7 100644 (file)
@@ -208,7 +208,7 @@ exp : T_NUMBER              {$$ = $1;}
                }
        }
        | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
-       | T_SYMBOL '=' exp      {$$ = $3; const_cast<symbol *>(&ex_to<symbol>($1))->assign($3);}
+       | T_SYMBOL '=' exp      {$$ = $3; ex_to_nonconst_symbol($1).assign($3);}
        | exp T_EQUAL exp       {$$ = $1 == $3;}
        | exp T_NOTEQ exp       {$$ = $1 != $3;}
        | exp '<' exp           {$$ = $1 < $3;}
@@ -468,7 +468,7 @@ static ex f_transpose(const exprseq &e)
 static ex f_unassign(const exprseq &e)
 {
        CHECK_ARG(0, symbol, unassign);
-       (const_cast<symbol *>(&ex_to<symbol>(e[0])))->unassign();
+       ex_to_nonconst_symbol(e[0]).unassign();
        return e[0];
 }