capability_mediator

Patrick Julien freak at codepimps.org
Mon Feb 16 23:57:09 CET 2004


> > 	2) Consider using standard containers instead of Qt based ones.  I.e.
> > std::map instead of QDict.
>
> Mmm. I thought about this, and didn't come to any firm conclusion. On the
> one hand, if I'm using Qt, I might as well use all of it, and use it as
> fully as possible, that gives a certain unity to the code. On the other
> hand, using std gives more connection with the standard. As far as I can
> tell, there are no significant performance differences. I don't know-- I'm
> considering, but I could well go on considering for a long time.

There are many reasons to prefer the standard containers. 

1) They have robust iterators (not to be confused with iterators of robust 
type)
2) work with the standard algorithms, worth it's weight in gold right there.
3) They are complete... consider this QValueList bug

	typedef QValueList<int> li;
	typedef li::iterator iterator;

	li l;

	// Add some data to l

	for (iterator it = l.begin(); i != l.end(); l++)
		li l2 = l; // Results in infinite loop

Now, if I would be using std::list, I don't have to work around this bug, but 
here are things I could do to work around the bug if QValueList was really a 
std::list clone:

	l2.insert(l2.end(), l.begin(), l.end());  // Doesn't work, QValueList doesn't 
have this version of insert.
	copy(l.begin(), l.end(), back_inserter(l2)); // Doesn't work,

QValueList::iterator doesn't meet standard container requirements for 
iterators.  

This is only an example, but I've learned the hard way to stick to the 
standard containers.

>
> > I have to admit tho, that this seems more like a global registry than a
> > mediator.
>
> I still have to get it working -- if it looks like it should be called
> registry, I can always rename, and if it looks like it's useless, I can
> always remove the stuff.

Well, you see, it depends what your goals are... exposing a global registry 
like this doesn't buy you anything more than exposing Krita internals 
directly.

The mediator pattern is more work in the short term... but it means more code 
reuse.  C'mon, admit it, wouldn't you be proud if Krita and Karbon would 
start sharing their dockers based on your code? :)





More information about the kimageshop mailing list