I’m making a container full of Drawables that I can access by name. In the Juce demo, there’s an example of something similar, but it takes a couple of data structures, like this (edited for clarity):
StringArray iconNames;
OwnedArray <Drawable> icons;
// ...
// create a named drawable
iconNames.add ("myName");
icons.add (Drawable::createFromImageDataStream (*svgFileStream));
// fetch a named drawable
Drawable* image = icons [iconNames.indexOf ("myName")]->createCopy();
Using std::tr1::shared_ptr and STL containers instead, doing the same thing looks like
typedef std::tr1::shared_ptr<Drawable> DrawablePtr;
std::map <String, DrawablePtr> icons;
// ...
// create a named drawable
icons["myName"] = (Drawable::createFromImageDataStream (*svgFileStream));
// fetch a named drawable
Drawable* image = icons["myName"];
With the STL method there is no need to mess around with two data structures that could possibly get out of sync. The std::map code also has the advantages of working with any kind of sortable object you want (such as a hash) for a key, and of being highly optimized.
JUCE’s ScopedPointers are by design not copyable, a quirk that is documented but can lead to some crazy-making situations if you are unaware (me earlier today.) For example, this compiles OK
ScopedPointer<Drawable> p;
p = (Drawable::createFromImageData(data, dataSize));
but this doesn’t.
ScopedPointer<Drawable> p = (Drawable::createFromImageData(data, dataSize));
For the same reason, ScopedPointers can’t be contained in STL containers. Since Jules is a busy guy, and JUCE has its own set of container classes, I’m not saying this should be changed. But if like me, you rely on both JUCE and the STL, take note: there are some gotchas.