src/utilities/idf/ValidityReport.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "ValidityReport.hpp" | ||
| 7 | #include "IdfObject.hpp" | ||
| 8 | |||
| 9 | #include "../idd/IddObject.hpp" | ||
| 10 | |||
| 11 | #include "../core/Assert.hpp" | ||
| 12 | |||
| 13 | namespace openstudio { | ||
| 14 | |||
| 15 | 18366 | ValidityReport::ValidityReport(StrictnessLevel level) : m_level(level), m_scope(Scope::Collection) { | |
| 16 | 18366 | m_currentError = m_errors.end(); | |
| 17 | 18366 | } | |
| 18 | |||
| 19 | 992287 | ValidityReport::ValidityReport(StrictnessLevel level, const IdfObject& object) | |
| 20 |
3/3✓ Branch 2 taken 992287 times.
✓ Branch 5 taken 992287 times.
✓ Branch 8 taken 992287 times.
|
992287 | : m_level(level), m_scope(Scope::Object), m_objectType(object.iddObject().type()) { |
| 21 | 992287 | m_currentError = m_errors.end(); | |
| 22 |
1/1✓ Branch 1 taken 992287 times.
|
992287 | OptionalString oName = object.name(); |
| 23 |
2/2✓ Branch 0 taken 754492 times.
✓ Branch 1 taken 237795 times.
|
992287 | if (oName) { |
| 24 |
2/2✓ Branch 1 taken 754492 times.
✓ Branch 4 taken 754492 times.
|
754492 | m_objectName = *oName; |
| 25 | } | ||
| 26 | 992287 | } | |
| 27 | |||
| 28 | 8 | ValidityReport::ValidityReport(const ValidityReport& other) | |
| 29 |
2/2✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
|
8 | : m_level(other.m_level), m_scope(other.m_scope), m_objectType(other.m_objectType), m_objectName(other.m_objectName), m_errors(other.m_errors) { |
| 30 | // reset the currentError counter | ||
| 31 | 8 | m_currentError = m_errors.end(); | |
| 32 | 8 | } | |
| 33 | |||
| 34 | 174 | void ValidityReport::insertError(const DataError& error) { | |
| 35 | 174 | m_errors.insert(error); | |
| 36 | 174 | m_currentError = m_errors.end(); | |
| 37 | 174 | } | |
| 38 | |||
| 39 | 15648700 | StrictnessLevel ValidityReport::level() const { | |
| 40 | 15648700 | return m_level; | |
| 41 | } | ||
| 42 | |||
| 43 | 9 | Scope ValidityReport::scope() const { | |
| 44 | 9 | return m_scope; | |
| 45 | } | ||
| 46 | |||
| 47 | ✗ | std::string ValidityReport::objectName() const { | |
| 48 | ✗ | return m_objectName; | |
| 49 | } | ||
| 50 | |||
| 51 | ✗ | boost::optional<IddObjectType> ValidityReport::objectType() const { | |
| 52 | ✗ | return m_objectType; | |
| 53 | } | ||
| 54 | |||
| 55 | 613884 | unsigned ValidityReport::numErrors() const { | |
| 56 | 613884 | return m_errors.size(); | |
| 57 | } | ||
| 58 | |||
| 59 | 396863 | boost::optional<DataError> ValidityReport::nextError() { | |
| 60 | // cycle through errors | ||
| 61 |
2/2✓ Branch 2 taken 396793 times.
✓ Branch 3 taken 70 times.
|
396863 | if (m_currentError == m_errors.end()) { |
| 62 | 396793 | m_currentError = m_errors.begin(); | |
| 63 | } else { | ||
| 64 | 70 | ++m_currentError; | |
| 65 | } | ||
| 66 | |||
| 67 | // if not at end, report error | ||
| 68 | 396863 | OptionalDataError result; | |
| 69 |
2/2✓ Branch 2 taken 72 times.
✓ Branch 3 taken 396791 times.
|
396863 | if (m_currentError != m_errors.end()) { |
| 70 |
1/1✓ Branch 2 taken 72 times.
|
72 | result = *m_currentError; |
| 71 | } | ||
| 72 | |||
| 73 | 396863 | return result; | |
| 74 | ✗ | } | |
| 75 | |||
| 76 | 9 | std::ostream& operator<<(std::ostream& os, const ValidityReport& report) { | |
| 77 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
9 | if (report.scope() == Scope::Collection) { |
| 78 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 8 times.
|
9 | if (report.numErrors() == 0) { |
| 79 |
3/3✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
|
1 | os << "The collection is VALID at strictness level '" << report.level().valueName(); |
| 80 | 1 | os << "'. There are no errors to report." << '\n'; | |
| 81 | } else { | ||
| 82 |
3/3✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 8 taken 8 times.
|
8 | os << "The collection is INVALID at strictness level '" << report.level().valueName(); |
| 83 | 8 | os << "', because of the errors:" << '\n'; | |
| 84 | } | ||
| 85 | } else { | ||
| 86 | ✗ | OS_ASSERT(report.scope() == Scope::Object); | |
| 87 | ✗ | OS_ASSERT(report.objectType()); | |
| 88 | ✗ | if (report.numErrors() == 0) { | |
| 89 | ✗ | os << "The object of type '" << report.objectType()->valueDescription() << "', named '"; | |
| 90 | ✗ | os << report.objectName() << "', is VALID at strictness level '"; | |
| 91 | ✗ | os << report.level().valueName() << "'. There are no errors to report." << '\n'; | |
| 92 | } else { | ||
| 93 | ✗ | os << "The object of type '" << report.objectType()->valueDescription() << "', named '"; | |
| 94 | ✗ | os << report.objectName() << "', is INVALID at strictness level '"; | |
| 95 | ✗ | os << report.level().valueName() << "', because of the errors:" << '\n'; | |
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | // print errors | ||
| 100 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 time.
|
9 | if (report.numErrors() > 0) { |
| 101 |
1/1✓ Branch 1 taken 8 times.
|
8 | ValidityReport reportCopy(report); |
| 102 |
1/1✓ Branch 1 taken 8 times.
|
8 | OptionalDataError error = reportCopy.nextError(); |
| 103 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
|
28 | while (error) { |
| 104 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | os << *error; |
| 105 |
1/1✓ Branch 1 taken 12 times.
|
12 | error = reportCopy.nextError(); |
| 106 | } | ||
| 107 | 8 | } | |
| 108 | |||
| 109 | 9 | return os; | |
| 110 | } | ||
| 111 | |||
| 112 | } // namespace openstudio | ||
| 113 |