[clug] Code "rework/rewrite" tools.

Andrew Janke a.janke at gmail.com
Tue Jan 20 22:55:29 GMT 2009

Sitrep:  I "inherited" the job of maintaining a bunch of code a while
back.  It is C++ code from years back and is spread across a library
(or two) and the main "doover". Of course in the latest Debian/Ubuntu
things go wonky due to the (older) way in which templates and operator
overloading are used.  Even judicious use of -frepo doesn't help me
here. :(

So I am faced with the (erky) prospect of re-writing the sections of
it that matter and thus the question...

Does anyone know of a tool that allows you to "weed" a library down to
just what is used? At least then I could concentrate my work on the
bits that matter as compared to fixing/updating the whole thing. The
code dates back to 1992, so it is at times a bit "interesting" (see
below for an example).



PS + eg:

Here is an example of what is going on/down (-DUSE_DBLMAT is defined)

From: Matrix.h

template <class Type> class Mat;


//Converts Mat<Type> to Mat<double>
typedef Mat<double> DblMat;
template <class Type> Mat<double> asDblMat(const Mat<Type>&);

#ifdef USE_FLMAT
//Converts Mat<Type> to Mat<float>
typedef Mat<float> FlMat;
template <class Type> Mat<float> asFlMat(const Mat<Type>&);


template <class T1, class T2>
Mat<T1>& operator += (Mat<T1>& A, const Mat<T2>& B);


From: Matrix.cc

template <class T1, class T2>
Mat<T1>& operator += (Mat<T1>& A, const Mat<T2>& B)

 unsigned nrows = A.getrows();
 unsigned ncols = A.getcols();

 if (!(A.isvector() && B.isvector() && (A.length() == B.length())) &&
     ((B.getrows() != nrows) || (B.getcols() != ncols))) {
   cerr << "Matrices of incompatible sizes for +=" << endl;
   return A;

 T1       *aPtr = (T1 *) A.getEl()[0];
 const T2 *bPtr = B.getEl()[0];

 for (unsigned i = nrows; i; i--)
   for (unsigned j = ncols; j; j--)
     *aPtr++ += (T1) *bPtr++;

 return A;


Now I think that for example the += overload should be this for a start:

   template <class T1>
         T1 & Mat<T1>::operator+=(const Mat<T1>& rhs);

Ideally I would just remove all the type templating (-DUSE_DBLMAT) as
only the DBLMAT version is ever used and as far as I am aware this
library isn't used anywhere else! :)

More information about the linux mailing list