Recommended Posts

I know that some people like the idea of: SoundFx a=SoundManager.Load("badExampleOfOODesign.wav"); However, I have been trying to get away from the whole concept of a "manager" (which I despise intensely and will not argue over in this thread, so please do not try). Then in the midst of working on my code for loading graphics from file into a generic Bitmap object I stumbled into this syntax for loading.
bmp::Bitmap bitmap;
std::ifstream ifs("testin.png",std::ios::in|std::ios::binary);
ifs.close();


Object o;
Stream s(STREAM_PARAMETERS); // STREAM_PARAMETERS could be a file name
s.close(); // not necessary as this is automatic with RAII


Or if I have a LoaderObject that already knows the stream use (possibly a Monostate) it can be:
Object o;


And I may even add this syntax as well:
ContainerWithAnOutputIterator c;
c.reserve(NUMBER_OF_OBJECTS_TO_LOAD); // if this is a vector or a similar type
Container paramList; // list of STREAM_PARAMETERS which again could be file names


So now I am thinking that if I pair all (or at least most) of my objects that need IO with a Loader object, I can create objects now and still have great flexibility in what I do with IO later. I admit that I have heard of the idea IO visitor objects before, but I have never seen an example or an explanation for why one would use it. However, now I understand.

Share on other sites
For my engine since I was writing it in C/C++ I used template specialization to load all my resources from an XML file that can specify anything from textures to sound files. I worked rather well a loading call was as simple as the following.

Mesh m = ResourceManager<Mesh>::load( xmlElement );

You could essentially do the same thing only make the param to the load function take a stream instead of an XML element.

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627682
• Total Posts
2978622

• 9
• 14
• 12
• 10
• 12