Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.4 KiB

  1. #ifndef __COMPFILE_H_
  2. #define __COMPFILE_H_
  3. #include <vector>
  4. #include <string>
  5. #include <fstream>
  6. #include <section.h>
  7. //
  8. // This class abstracts the compliance file
  9. //
  10. class ComplianceFile {
  11. public:
  12. ComplianceFile(const string& szFileName){
  13. m_szFileName = szFileName;
  14. bindSectionFactory();
  15. readLines();
  16. createSections();
  17. }
  18. virtual ~ComplianceFile(){
  19. vector<Section*>::iterator iter = m_sections.begin();
  20. while (iter != m_sections.end())
  21. delete *iter++;
  22. delete m_sectionFactory;
  23. }
  24. void executeTestCases(ostream& os);
  25. //
  26. // accessors
  27. //
  28. const string& name() const{ return m_szFileName; }
  29. const vector<string>& lines() const{ return m_lines; }
  30. const vector<Section*>& sections() const{ return m_sections; }
  31. const ValueSection& typesSection() const { return *m_typesSection; }
  32. const ValueSection& varsSection() const { return *m_varsSection; }
  33. const ValueSection& suitesSection() const { return *m_suitesSection; }
  34. const ValueSection& sourcesSection() const { return *m_sourcesSection; }
  35. const ValueSection& errorsSection() const { return *m_errorsSection; }
  36. const SectionFactory& sectionFactory() const { return *m_sectionFactory; }
  37. //
  38. // exception classes
  39. //
  40. struct InvalidFileName {
  41. InvalidFileName(const string& name) : m_name(name) {}
  42. friend ostream& operator<<(ostream& os, const InvalidFileName& rhs) {
  43. os << "Exception : Invalid file name : " << rhs.m_name;
  44. return os;
  45. }
  46. string m_name;
  47. };
  48. struct InvalidFileFormat {
  49. InvalidFileFormat(const string& name) : m_name(name) {}
  50. friend ostream& operator<<(ostream& os, const struct InvalidFileFormat &rhs) {
  51. os << "Exception : Invalid file format : " << rhs.m_name;
  52. return os;
  53. }
  54. string m_name;
  55. };
  56. struct MissingSection {
  57. MissingSection(const string& name) : m_name(name){}
  58. friend ostream& operator<<(ostream& os, const struct MissingSection &rhs) {
  59. os << "Exception : The following section is missing : " << rhs.m_name;
  60. return os;
  61. }
  62. string m_name;
  63. };
  64. //
  65. // overloaded operators
  66. //
  67. friend ostream& operator<<(ostream& os, const ComplianceFile &cf);
  68. /*
  69. ComplianceFile& operator=(const ComplianceFile& rhs) {
  70. m_lines = rhs.m_lines;
  71. m_szFileName = rhs.m_szFileName;
  72. delete m_typesSection;
  73. m_typesSection = sectionFactory().create(rhs.typesSection());
  74. delete m_varsSection;
  75. m_varsSection = sectionFactory().create(rhs.varsSection());
  76. delete m_suitesSection;
  77. m_suitesSection = sectionFactory().create(rhs.suitesSection());
  78. m_upgSections = rhs.TestSections();
  79. }
  80. */
  81. void executeTestCases();
  82. protected:
  83. virtual void bindSectionFactory() {
  84. m_sectionFactory = new OldFormatSectionFactory();
  85. }
  86. //
  87. // data members
  88. //
  89. vector<string> m_lines;
  90. string m_szFileName;
  91. ValueSection *m_typesSection;
  92. ValueSection *m_varsSection;
  93. ValueSection *m_suitesSection;
  94. ValueSection *m_sourcesSection;
  95. ValueSection *m_errorsSection;
  96. SectionFactory *m_sectionFactory;
  97. vector<TestSection*> m_upgSections;
  98. vector<Section*> m_sections;
  99. private:
  100. void readLines();
  101. bool isSectionName(const string& szLine) const;
  102. void createSections();
  103. static vector<Section*>::iterator
  104. findSection(vector<Section*> &sections, const string& szName);
  105. };
  106. #endif // for __COMPFILE_H_