fork download
  1. template <class T>
  2. void format_error(T& obj, const std::string& symbol)
  3. {
  4. std::stringstream ss
  5. ss << symbol << " is incorrectly formatted";
  6. obj.errorH(ss.str(), 2);
  7. }
  8. template <class T>
  9. void not_member_error(T& obj, const std::string& symbol, const std::string& type)
  10. {
  11. std::stringstream ss
  12. ss << symbol << " is not a member of " << type;
  13. obj.errorH(ss.str(), 1);
  14. }
  15.  
  16. std::istream& operator>>(std::istream& file, first& obj)
  17. {
  18. std::string symbol;
  19. while(file >> symbol)
  20. {
  21. if (symbol[0] == '#')
  22. {
  23. std::getline(file, symbol);
  24. }
  25. else if (symbol == FIRSTTAGEND)
  26. {
  27. break;
  28. }
  29. else if (symbol == FILEPATH)
  30. {
  31. if (!(file >> '=' >> obj.filename))
  32. format_error(obj, symbol);
  33. }
  34. else if (symbol == SCALE)
  35. {
  36. if (! (file >> '=' >> obj.scale) )
  37. format_error(obj, symbol);
  38. }
  39. else
  40. { //not a member: failure
  41. not_member_error(obj, symbol, "first");
  42. file.setstate(file.rdstate() | std::ios::badbit);
  43. break;
  44. }
  45. }
  46. return file;
  47. }
  48.  
  49. std::istream& operator>>(std::istream& file, InputDeck& obj)
  50. {
  51. std::string symbol;
  52. while(file >> symbol)
  53. {
  54. if (symbol[0] == '#')
  55. {
  56. std::getline(file, symbol);
  57. }
  58. else if (symbol == FIRSTTAGBEG)
  59. {
  60. inputMesh t;
  61. if (file >> t)
  62. obj.mesh.push_back(t);
  63. }
  64. else
  65. {
  66. not_member_error(obj, symbol, "InputDeck");
  67. file.setstate(file.rdstate() | std::ios::badbit);
  68. }
  69. }
  70. return file;
  71. }
  72.  
  73. bool InputDeck::readFile(std::string filename)
  74. {
  75. std::ifstream infile;
  76. infile.open(filename.c_str());
  77. infile >> *this;
  78. return true;
  79. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty