[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: C++ Template Question
From:       Hans Meine <hans_meine () gmx ! net>
Date:       2007-08-20 14:20:25
Message-ID: 200708201620.25127.hans_meine () gmx ! net
[Download RAW message or body]

Am Montag, 20. August 2007 15:45:55 schrieb Mosfet:
> The only question I have about it is if it is possible to use this to
> create a multidimensional array and if so what is the proper way?

You mean sth. like this?

typedef QVarLengthArray<int, 50> Row;
QVarLengthArray<Row, 50> image(height);
for(uint y=0; y<height; ++y)
  image[y].resize(width);

Unfortunately, QVarLengthArray misses a lot of STL features, which makes the 
above code more complicated than necessary.

> I'm not a 
> template expert so don't know. I could of course just allocate one block
> and use offsets but I like using indexes if possible :)

..or you could use a "view"-like 2D adapter with a 1D QVarLengthArray.
(Our VIGRA library has such a thing: 
http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/doc/vigra/classvigra_1_1BasicImageView.html)

And there are other nice array classes, too:
http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/doc/vigra/classvigra_1_1TinyVector.html
http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/doc/vigra/classvigra_1_1ArrayVector.html

VIGRA is generic, i.e. can be used with Qt.  The references were meant as a 
general pointer, but you might indeed want to try it one day - no need to 
compile it if you are not interested in VIGRA's image loading/saving - the 
rest is just a bunch of header files.

Greetings,
  Hans
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic