Modern C++ uses nullptr
rather than NULL
. See this answer this answer for why and how it's useful. Once you do that, you'll see that you have been abusing NULL
and using it as an integer value instead of just a pointer. For example, the code includes this:
Modern C++ uses nullptr
rather than NULL
. See this answer for why and how it's useful. Once you do that, you'll see that you have been abusing NULL
and using it as an integer value instead of just a pointer. For example, the code includes this:
Modern C++ uses nullptr
rather than NULL
. See this answer for why and how it's useful. Once you do that, you'll see that you have been abusing NULL
and using it as an integer value instead of just a pointer. For example, the code includes this:
Rather than hardcoding a filename twice (leading to the potential error of not having them match!), pass it as a parameter instead. This reduces the hidden linkages in the code and makes it easier to see what's happening.
Rather than hardcoding a filename twice, pass it as a parameter instead. This reduces the hidden linkages in the code and makes it easier to see what's happening.
Rather than hardcoding a filename twice (leading to the potential error of not having them match!), pass it as a parameter instead. This reduces the hidden linkages in the code and makes it easier to see what's happening.
friend std::istream& operator>>(std::istream& in, Config& cfg) {
Config temp;
std::string line;
int fields = 0xF;
for (std::string line; fields && std::getline(in, line); ) {
if (!in) {
return in;
}
auto pair=temp.value(line);
if (pair.first == "width") {
temp.Width = pair.second;
fields &= ~0x01;
} else if (pair.first == "height") {
temp.Height = pair.second;
fields &= ~0x02;
} else if (pair.first == "renderer") {
temp.renderer = pair.second;
fields &= ~0x04;
} else if (pair.first == "fullscreen") {
temp.Fullscreen = pair.second;
fields &= ~0x08;
}
}
if (fields == 0) {
std::swap(temp, cfg);
} else {
in.setstate(std::ios::failbit);
}
return in;
}
friend std::istream& operator>>(std::istream& in, Config& cfg) {
Config temp;
std::string line;
int fields = 0xF;
for (std::string line; fields && std::getline(in, line); ) {
if (!in) {
return in;
}
auto pair=temp.value(line);
if (pair.first == "width") {
temp.Width = pair.second;
fields &= ~0x01;
} else if (pair.first == "height") {
temp.Height = pair.second;
fields &= ~0x02;
} else if (pair.first == "renderer") {
temp.renderer = pair.second;
fields &= ~0x04;
} else if (pair.first == "fullscreen") {
temp.Fullscreen = pair.second;
fields &= ~0x08;
}
}
if (fields == 0) {
std::swap(temp, cfg);
}
return in;
}
friend std::istream& operator>>(std::istream& in, Config& cfg) {
Config temp;
std::string line;
int fields = 0xF;
for (std::string line; fields && std::getline(in, line); ) {
auto pair=temp.value(line);
if (pair.first == "width") {
temp.Width = pair.second;
fields &= ~0x01;
} else if (pair.first == "height") {
temp.Height = pair.second;
fields &= ~0x02;
} else if (pair.first == "renderer") {
temp.renderer = pair.second;
fields &= ~0x04;
} else if (pair.first == "fullscreen") {
temp.Fullscreen = pair.second;
fields &= ~0x08;
}
}
if (fields == 0) {
std::swap(temp, cfg);
} else {
in.setstate(std::ios::failbit);
}
return in;
}