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

Author Topic: user data variable in sfInputStream  (Read 3905 times)

0 Members and 1 Guest are viewing this topic.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
user data variable in sfInputStream
« on: March 07, 2013, 07:13:36 pm »
I've been looking through a bunch of source code regarding sfInputStreams today and I couldn't seem to find anywhere the void* userData actually get's used other than inside CallbackStream. I'm just curious what it is used for and what "user data" get's assigned to it. Or what I should be assigning to it when using sfInputStream. I was thinking that it could be used to store the current contents on the stream, but I wasn't completely sure.

Thanks!
DSFML - SFML for the D Programming Language.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: user data variable in sfInputStream
« Reply #1 on: March 07, 2013, 08:18:16 pm »
It's there so that you can put a pointer to whatever is required to implement your stream. How would you implement the 4 callbacks without any additional data? You have to pass your own data to these callbacks.
Laurent Gomila - SFML developer

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: user data variable in sfInputStream
« Reply #2 on: March 08, 2013, 02:46:35 am »
Shouldn' t the way the callbacks access the "user data" be left up to whoever is implementing the use of the sfInputStream though?

The issue that I am running into is reimplementing this in a different language. I wanted to get things working more or less like the C++ version, and having the extra parameter for each callback means I will probably have to write some wonky looking code instead of just writing a function with the same parameters as the C++ version and then assigning the address of that to to the callback.

Now, you are a far more experienced developer  than I, so far be it from me to argue with how you implement things. I'm sure you have reasons for doing things and if need be I can work around this. Just thought I would express my thoughts.
DSFML - SFML for the D Programming Language.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: user data variable in sfInputStream
« Reply #3 on: March 08, 2013, 08:00:27 am »
Hmm... This is a very standard way of implementing things in C, in fact this is even the only one. I have no idea how you would do it differently.

To implement an oriented object wrapper around it in another language is straight-forward, I did it in C#. Just pass the wrapper object as the user data, and make the callbacks call the corresponding member functions of the wrapper.
Laurent Gomila - SFML developer

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: user data variable in sfInputStream
« Reply #4 on: March 08, 2013, 07:18:31 pm »
I always forget that you did a .net wrapper. I'll check it out and see if I can make it work in a similar way.

Thanks as usual!
DSFML - SFML for the D Programming Language.