SFML community forums

Help => System => Topic started by: Kadoba on August 03, 2009, 06:05:36 pm

Title: Resource and ResourcePtr
Post by: Kadoba on August 03, 2009, 06:05:36 pm
Hello I'm new to SFML and C++ and I'm trying to make my own resource manager to get some experience and decided to use the built-in Resource and ResourcePtr classes.

After struggling a bit I realized that whenever you try to access the resource of a pointer it will always return a constant of that resource. Now, const correctness is something I usually don't bother with so I am a little lost.

How can you use resource pointers if it always returns a constant? Are mutators impossible in this situation?

It seems like a really useful feature but a little contrained. I guess if I have to I'll do my own reference counting with raw pointers or use another library, but I'd really like to use the built-in features if I could.
Title: Resource and ResourcePtr
Post by: Laurent on August 03, 2009, 06:11:14 pm
Hi

The Resource and ResourcePtr classes have been developed for internal use ; you can of course use them but they are not designed with generic usage in mind.

In this context, a resource is a heavy object that is loaded once and then shared / used by multiple lightweight objects:
- Image -> Sprite
- Font -> String
- SoundBuffer -> Sound

So a resource can't be modified by the objects that use it; that explains the const access.
Title: Resource and ResourcePtr
Post by: Kadoba on August 03, 2009, 06:41:10 pm
Thank you. That answered my question.   :D