Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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:

added why having filename twice is a potential problem
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

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.

simplified extractor loop
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
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;
}
corrected comment
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /