[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] Question: Implementation of BaseClass with virtuals templ

From: Gabriel Nützi
Subject: [Toon-members] Question: Implementation of BaseClass with virtuals template functions with TOON
Date: Fri, 19 Mar 2010 14:52:45 +0100

Hello all,

I have a basic question where I am completely stuck with TooN:
I dont know how to realize this:

I have a DynamicSystem Class which describes a Dynamical System with template parameter <int NDOF>
I would like to have a Class Solver which has a reference to an instance of DynamicSystem.
The solver should be able to call several virtual functions from DynamicSystem. (subClass could be a Ball or a Car or what ever :-))
The main problem is that this main functions take Vectors/Matrices as Input and give Vector and Matrices as Output back (depending on NDOF)
but when I want to properly define such a function in TOON i need templates (to be able to input also slices and so on....)


template<typename BaseM, typename BaseV>
Matrix<3,3,double,BaseM> get_M (double t, Vector<3,double, BaseV > x   ){
// some code

But the problem is that in C++ we can not define templates as virtual functions......

HOW DO I SOLVE this Problem with TooN?
How should I structure my Classes? Would be very helpful if someone can quickly append the changes in the attached source code (ITS SIMPLE :-))!

Thank you very much for your HELP!!

Attachment: DynamicSystem.h
Description: Binary data

Attachment: main.cpp
Description: Binary data

Am 27.02.2010 um 18:02 schrieb address@hidden:

Send Toon-members mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Toon-members digest..."

Today's Topics:

  1.  TooN/doc documentation.h (Edward Rosten)
  2. Re:  Efficient (dynamic) slicing (Rafael Spring)


Message: 1
Date: Fri, 26 Feb 2010 19:11:07 +0000
From: Edward Rosten <address@hidden>
Subject: [Toon-members] TooN/doc documentation.h
To: address@hidden
Message-ID: <address@hidden>

CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 10/02/26 19:11:07

Modified files:
doc            : documentation.h

Log message:
Documentation on how to return slices from functions.


Index: documentation.h
RCS file: /cvsroot/toon/TooN/doc/documentation.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- documentation.h 9 Feb 2010 13:43:19 -0000 1.46
+++ documentation.h 26 Feb 2010 19:11:06 -0000 1.47
@@ -67,6 +67,7 @@
 - \ref sResize
 - \ref sDebug
 - \ref sSlices
+ - \ref sFuncSlices
 - \ref sPrecision
 - \ref sSolveLinear
 - \ref sOtherStuff
@@ -502,6 +503,8 @@

Slices are usually strange types. See \ref sFunctionVector

+ See also \sFuncSlices
\subsection sPrecision Can I have a precision other than double?

@@ -523,6 +526,31 @@
rules. The result of multiplying a <code>Matrix<double></code> by a
<code>Vector<float></code> is a <code>Vector<double></code>.

+ \subsection sFuncSlices How do I return a slice from a function?
+ Each vector has a <code>SliceBase</code> type indicating the type of a slice.
+ They can be slightly tricky to use:
+ @code
+ Vector<2, double, Vector<4>::SliceBase> sliceof(Vector<4>& v)
+ {
+ return v.slice<1,2>();
+ }
+ template<int S, class P, class B>
+ Vector<2, P, Vector<S, P, B>::SliceBase> sliceof(Vector<S, P, B>& v)
+ {
+ return v.template slice<1,2>();
+ }
+ template<int S, class P, class B>
+ const Vector<2, const P, typename Vector<S, P, B>::ConstSliceBase > foo(const Vector<S, P, B>& v)
+ {
+ return v.template slice<1,2>();
+ }
+ @endcode
\subsection sSolveLinear How do I invert a matrix / solve linear equations?

You use the decomposition objects (see \ref sDecompos "below"), for example to solve Ax=b:


Message: 2
Date: Fri, 26 Feb 2010 11:46:00 -0800
From: Rafael Spring <address@hidden>
Subject: Re: [Toon-members] Efficient (dynamic) slicing
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

Ok, so the real situation is that fillSubMatrix() is virtual  
(sorry, should have mentioned that in my first mail). That would  
probably require to be explicit about the template parameters, right?
Can I now assume that the proposed pattern would not result in  
temp. matrix data being allocated from the heap? Or is there a  
better practice than this?

I am also a little confused by the Matrix documentation. For the  
slice() method there is an example:

Matrix<> m(3,3);
// Extract the top-left 2x2 matrix
Matrix<2> b = m.slice(0,0,2,2);

Is Matrix b now a copy of m's top left 2x2 or is b just referencing  
this data? Would then the following be a reference?

Matrix<Dynamic, Dynamic, double, TooN::Internal::Slice<-1,1> > b =  

Please ignore the questions. The debugger just gave me all the answers.
However, for the next beta of TooN, I'd love to have a small memory  
manager in the background to redirect the temp. allocations.



(You can't go wrong with psycho-rats.)(

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
   d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage

Toon-members mailing list


Toon-members mailing list

End of Toon-members Digest, Vol 42, Issue 10

reply via email to

[Prev in Thread] Current Thread [Next in Thread]