Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Software design: Wrapping valarray, or not.

Reply
Thread Tools

Software design: Wrapping valarray, or not.

 
 
Daniel Pitts
Guest
Posts: n/a
 
      06-14-2008
Please excuse my ramblings here. For a hobby project, I'm working on a
simple ray-tracer. I've gone through a few iterations, and I wanted some
opinions on my next idea for an iteration...

My first iteration, I went all out and created a generic
template<typename component, unsigned dimensions> class vector;
I used template meta-programming to do all of the operations as
efficiently as possible, and enforce dimensions at runtime.

It was an interesting exercise, but I something I did wasn't quite
cross-platform. I scrapped the whole thing and created a simpler
vector3d class, which used explicit x, y, z members. While this isn't
as efficient, it was a lot easier to write, and I don't need that much
efficiency at this point.

Then I discovered valarray . I wish I had known about that earlier.
So, my next iteration will probably utilize valarray some how.

My question is a "elegance in design" one. My first thought is that I
should wrap the valarray in a template vector class. I might go the
route having the type *and* dimensionality of the vector be template
parameters. That way, there is compile-time safety for operations that
require same-length vectors. cross-product for instance needs exactly 3
dimensions. Of course, my application only needs 3 dimensions, so
perhaps making it generic at this point is a little premature. Then
again, it is an exercise, and I can go the route of premature
generalization if I choose

One alternative is to use valarray directly, and not wrap it at all.
This seems to defy good OO practices though.

The other alternative is to keep the dimensionality a runtime parameter,
and use assert to verify the correct dimensionality.

So, what opinions are out there? I'm looking for more of a "why" than a
"what".

Thanks,
Daniel.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS gateway software, SMS gateway, SMS software, SMS server, SMPP software, WAP Push John UK VOIP 0 08-29-2007 05:14 AM
SMS gateway software, SMS gateway, SMS software, SMS server, SMPP software, WAP Push John ASP .Net 0 08-29-2007 05:08 AM
SMS gateway software, SMS gateway, SMS software, SMS server, SMPP software, WAP Push John Java 0 08-28-2007 05:53 AM
Wrapping text Hans P S Alnes Firefox 2 02-23-2004 03:51 AM



Advertisments