Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Resource and ResourcePtr  (Read 6621 times)

0 Members and 1 Guest are viewing this topic.

Kadoba

  • Newbie
  • *
  • Posts: 7
    • View Profile
Resource and ResourcePtr
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Resource and ResourcePtr
« Reply #1 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.
Laurent Gomila - SFML developer

Kadoba

  • Newbie
  • *
  • Posts: 7
    • View Profile
Resource and ResourcePtr
« Reply #2 on: August 03, 2009, 06:41:10 pm »
Thank you. That answered my question.   :D