src/utilities/idf/DataError.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 <iomanip> | ||
| 7 | #include "DataError.hpp" | ||
| 8 | #include "IdfObject.hpp" | ||
| 9 | |||
| 10 | #include "../idd/IddObject.hpp" | ||
| 11 | |||
| 12 | #include "../core/Assert.hpp" | ||
| 13 | |||
| 14 | namespace openstudio { | ||
| 15 | |||
| 16 | 788 | DataError::DataError(unsigned fieldIndex, const IdfObject& object, DataErrorType errorType) | |
| 17 |
3/3✓ Branch 4 taken 788 times.
✓ Branch 7 taken 788 times.
✓ Branch 10 taken 788 times.
|
788 | : m_scope(Scope::Field), m_type(errorType), m_fieldIndex(fieldIndex), m_objectHandle(object.handle()), m_objectType(object.iddObject().type()) { |
| 18 | // construct field-level error | ||
| 19 |
1/1✓ Branch 1 taken 788 times.
|
788 | OptionalString oName = object.name(); |
| 20 |
2/2✓ Branch 0 taken 669 times.
✓ Branch 1 taken 119 times.
|
788 | if (oName) { |
| 21 |
2/2✓ Branch 1 taken 669 times.
✓ Branch 4 taken 669 times.
|
669 | m_objectName = *oName; |
| 22 | } | ||
| 23 | 788 | } | |
| 24 | |||
| 25 | 20 | DataError::DataError(const IdfObject& object, DataErrorType errorType) | |
| 26 |
3/3✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 10 taken 20 times.
|
20 | : m_scope(Scope::Object), m_type(errorType), m_fieldIndex(0), m_objectHandle(object.handle()), m_objectType(object.iddObject().type()) { |
| 27 | // construct object-level error | ||
| 28 |
1/1✓ Branch 1 taken 20 times.
|
20 | OptionalString oName = object.name(); |
| 29 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
|
20 | if (oName) { |
| 30 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | m_objectName = *oName; |
| 31 | } | ||
| 32 | 20 | } | |
| 33 | |||
| 34 | ✗ | DataError::DataError(DataErrorType errorType) : m_scope(Scope::Collection), m_type(errorType), m_fieldIndex(0) { | |
| 35 | // construct collection-level error | ||
| 36 | ✗ | } | |
| 37 | |||
| 38 | 21 | DataError::DataError(DataErrorType errorType, IddObjectType objectType) | |
| 39 |
1/1✓ Branch 4 taken 21 times.
|
21 | : m_scope(Scope::Collection), m_type(errorType), m_fieldIndex(0), m_objectType(objectType) { |
| 40 | // construct collection-level error | ||
| 41 | 21 | } | |
| 42 | |||
| 43 | 524 | Scope DataError::scope() const { | |
| 44 | 524 | return m_scope; | |
| 45 | } | ||
| 46 | |||
| 47 | 432 | DataErrorType DataError::type() const { | |
| 48 | 432 | return m_type; | |
| 49 | } | ||
| 50 | |||
| 51 | 4 | unsigned DataError::fieldIdentifier() const { | |
| 52 |
3/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
|
4 | if (scope() != Scope::Field) { |
| 53 | ✗ | LOG_AND_THROW("There is no field identifier for this DataError, which has scope " << scope().valueDescription() << "."); | |
| 54 | } | ||
| 55 | 4 | return m_fieldIndex; | |
| 56 | } | ||
| 57 | |||
| 58 | 2 | Handle DataError::objectIdentifier() const { | |
| 59 | 2 | return m_objectHandle; | |
| 60 | } | ||
| 61 | |||
| 62 | 10 | std::string DataError::objectName() const { | |
| 63 | 10 | return m_objectName; | |
| 64 | } | ||
| 65 | |||
| 66 | 594 | boost::optional<IddObjectType> DataError::objectType() const { | |
| 67 | 594 | return m_objectType; | |
| 68 | } | ||
| 69 | |||
| 70 | ✗ | bool DataError::operator==(const DataError& otherError) const { | |
| 71 | ✗ | return ((scope() == otherError.scope()) && (type() == otherError.type()) && (m_fieldIndex == otherError.m_fieldIndex) | |
| 72 | ✗ | && (objectIdentifier() == otherError.objectIdentifier()) && (objectName() == otherError.objectName()) | |
| 73 | ✗ | && (objectType() == otherError.objectType())); | |
| 74 | } | ||
| 75 | |||
| 76 | ✗ | bool DataError::operator!=(const DataError& otherError) const { | |
| 77 | ✗ | return !(*this == otherError); | |
| 78 | } | ||
| 79 | |||
| 80 | 178 | bool DataErrorLess::operator()(const DataError& left, const DataError& right) const { | |
| 81 | // order first by error type, since listed in order of severity | ||
| 82 |
4/4✓ Branch 1 taken 178 times.
✓ Branch 4 taken 178 times.
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 153 times.
|
178 | if (left.type() != right.type()) { |
| 83 |
2/2✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
|
25 | return left.type() < right.type(); |
| 84 | } | ||
| 85 | // within type order by collection, then object, then field-level, since | ||
| 86 | // collection-level is generally the most severe (IddFile missing, for instance) | ||
| 87 |
4/4✓ Branch 1 taken 153 times.
✓ Branch 4 taken 153 times.
✓ Branch 7 taken 11 times.
✓ Branch 8 taken 142 times.
|
153 | if (left.scope() != right.scope()) { |
| 88 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | return left.scope() > right.scope(); |
| 89 | } | ||
| 90 | // if object-level name conflict, order by name, then type | ||
| 91 |
4/10✓ Branch 1 taken 142 times.
✓ Branch 4 taken 142 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 142 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 142 times.
|
142 | if ((left.scope() == Scope::Object) && (left.type() == DataErrorType::NameConflict)) { |
| 92 | ✗ | if (!istringEqual(left.objectName(), right.objectName())) { | |
| 93 | ✗ | return istringLess(left.objectName(), right.objectName()); | |
| 94 | } | ||
| 95 | } | ||
| 96 | // if objectType exists, order by that next, since Idd Files are in a | ||
| 97 | // semi-logical order | ||
| 98 |
7/16✓ Branch 1 taken 142 times.
✓ Branch 4 taken 142 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 142 times.
✓ Branch 10 taken 142 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 142 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 142 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 142 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
142 | if ((left.objectType() != boost::none) && (right.objectType() != boost::none)) { |
| 99 |
4/4✓ Branch 1 taken 142 times.
✓ Branch 4 taken 142 times.
✓ Branch 7 taken 142 times.
✓ Branch 10 taken 142 times.
|
142 | return left.objectType().get() < right.objectType().get(); |
| 100 | } | ||
| 101 | // now order by objectName in remaining cases | ||
| 102 | ✗ | if (!istringEqual(left.objectName(), right.objectName())) { | |
| 103 | ✗ | return istringLess(left.objectName(), right.objectName()); | |
| 104 | } | ||
| 105 | // now by objectHandle (for non-named objects) | ||
| 106 | ✗ | if (left.objectIdentifier() != right.objectIdentifier()) { | |
| 107 | ✗ | return left.objectIdentifier() < right.objectIdentifier(); | |
| 108 | } | ||
| 109 | // now by fieldIndex, if applicable | ||
| 110 | ✗ | if (left.scope() == Scope::Field) { | |
| 111 | ✗ | return left.fieldIdentifier() < right.fieldIdentifier(); | |
| 112 | } | ||
| 113 | |||
| 114 | // exactly equal | ||
| 115 | ✗ | return false; | |
| 116 | } | ||
| 117 | |||
| 118 | 12 | std::ostream& operator<<(std::ostream& os, const DataError& error) { | |
| 119 | |||
| 120 |
4/4✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
|
12 | os << std::setw(11) << std::left << error.scope().valueName() << "level data error of type "; |
| 121 |
5/5✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
✓ Branch 16 taken 12 times.
|
12 | os << std::setw(18) << std::left << error.type().valueName() << "." << '\n'; |
| 122 | |||
| 123 |
4/4✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 8 times.
|
12 | if (error.scope() == Scope::Field) { |
| 124 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
|
4 | OS_ASSERT(error.objectType()); |
| 125 |
4/4✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 11 taken 4 times.
|
4 | os << "Error is in an object of type '" << error.objectType()->valueDescription(); |
| 126 |
6/6✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 17 taken 4 times.
|
4 | os << "', named '" << error.objectName() << "', in field " << error.fieldIdentifier() << "."; |
| 127 | 4 | os << '\n'; | |
| 128 | } | ||
| 129 | |||
| 130 |
4/4✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 6 times.
|
12 | if (error.scope() == Scope::Object) { |
| 131 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 7 not taken.
|
6 | OS_ASSERT(error.objectType()); |
| 132 |
4/4✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
✓ Branch 8 taken 6 times.
✓ Branch 11 taken 6 times.
|
6 | os << "Error pertains to an object of type '" << error.objectType()->valueDescription(); |
| 133 |
4/4✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
✓ Branch 8 taken 6 times.
✓ Branch 11 taken 6 times.
|
6 | os << "', named '" << error.objectName() << "'." << '\n'; |
| 134 | } | ||
| 135 | |||
| 136 |
10/13✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 10 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✓ Branch 16 taken 10 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
14 | if ((error.scope() == Scope::Collection) && (error.objectType())) { |
| 137 |
5/5✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 14 taken 2 times.
|
2 | os << "Error pertains to objects of type '" << error.objectType()->valueDescription() << "'."; |
| 138 | 2 | os << '\n'; | |
| 139 | } | ||
| 140 | |||
| 141 |
4/4✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 8 taken 12 times.
✓ Branch 11 taken 12 times.
|
12 | os << "Additional information about the error type: " << error.type().valueDescription() << "."; |
| 142 | 12 | os << '\n'; | |
| 143 | |||
| 144 | 12 | return os; | |
| 145 | } | ||
| 146 | |||
| 147 | } // namespace openstudio | ||
| 148 |