O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Expansion of utility functions

In order to keep things simple and easy to read, it's always a good idea to create utility-type functions out of any code that is going to be used frequently. When dealing with interface de-serialization, many elements have to read in parameters that have spaces in them. Our solution to this problem is to put the string in double quotes and define an inline function to read the data. The perfect spot for that is in the Utilities.h file:

inline void ReadQuotedString(std::stringstream& l_stream, std::string& l_string) { l_stream >> l_string; if (l_string.at(0) == '"'){ while (l_string.at(l_string.length() - 1) != '"' || !l_stream.eof()) { std::string str; l_stream >> str; l_string.append(" " + str); } } l_string.erase(std::remove(l_string.begin(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required