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

Author Topic: sf::Strings - copy ctor, copy assignment not working  (Read 2486 times)

0 Members and 1 Guest are viewing this topic.

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
sf::Strings - copy ctor, copy assignment not working
« on: October 14, 2009, 04:52:21 pm »
hello,

i was wondering why some of my instanced sf::Strings were not working,
because i ran into some unexpected behavior.

*) what i want to do:
i want to copy a sf::string


*) this is what i was doing (should work IMHO, but does NOT)
Code: [Select]

sf::Font font;
//font gets loaded ... OK

sf::String label1;
label1.SetFont(font);
//rest of setup (color, style, size) and transformation ... OK


sf::String label2 = label1;  //assuming all attributes get copied - NOT WORKING!
//just setup unique attributes of label2 ...


sf::String label3(label1);  //assuming the same - NOT WORKING!
//setup unique attributes of label3 here ...



*) this is how i should do it in order to get it working
Code: [Select]

sf::Font font;
//font gets loaded ... OK

sf::String label1;
label1.SetFont(font);
//rest of setup (color, style, size) and transformation ... OK


//A - WORKS OK
sf::String label2;
label2.SetFont(font);
label2.SetSize(size);


//B - WORKS OK
sf::String label3("", font, size);


ok, i could use A and B, but wouldn't it be more natural to just copy it?
it seems like a problem with the copy ctor or copy assignment operator.
and i don't see a problem why this should not be working.
the font reference should be a shallow copy, the content a deep copy
and all the POD-like attributes can be copied easily anyway.

btw, as a kind of little request - what about a TextFormat class?
you can assign font, style, size, etc and assign it to different sf::Strings (which only hold the string content and a reference to this format).
this would save us a lot of typing and nice OO design :)

cheers, didi

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Strings - copy ctor, copy assignment not working
« Reply #1 on: October 14, 2009, 05:26:12 pm »
Copying a sf::String works like a charm. Can you show a complete code that reproduces your problem?

Quote
btw, as a kind of little request - what about a TextFormat class?
you can assign font, style, size, etc and assign it to different sf::Strings (which only hold the string content and a reference to this format).
this would save us a lot of typing and nice OO design

Copying from another string will have the same effect as assigning a Textformat (except that the text would be copied as well).
Laurent Gomila - SFML developer

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
sf::Strings - copy ctor, copy assignment not working
« Reply #2 on: October 14, 2009, 05:37:33 pm »
believe me, it does not work here. i am sitting in front of the code.
and what do you mean, i already have posted the code?!?

maybe it has something to do with the problem of not being able to create/load a font before the opengl-context (i ran into that one before).
should i create SFML objects in any specific order?

btw, i am using a revision of SFML 1.5 (or 1.6?) on mac.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Strings - copy ctor, copy assignment not working
« Reply #3 on: October 14, 2009, 05:44:52 pm »
Quote
believe me, it does not work here. i am sitting in front of the code.

I believe you, but I'm not sure it is as simple as the copy constructor failing. All the members are directly copyable, and I let the compiler generate the copy constructor for me. So I think it might be a side effect of another error in your program.

Quote
and what do you mean, i already have posted the code?!?

I saw your code, but I want a complete one that I can copy, paste, compile and test directly ;)

Quote
maybe it has something to do with the problem of not being able to create/load a font before the opengl-context (i ran into that one before).
should i create SFML objects in any specific order?

No, there's no constraint about the order of initialization in SFML.

Quote
btw, i am using a revision of SFML 1.5 (or 1.6?) on mac.

Which revision?
Laurent Gomila - SFML developer