src/utilities/idf/Workspace.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 "Workspace.hpp" | ||
| 7 | #include "Workspace_Impl.hpp" | ||
| 8 | |||
| 9 | #include "IdfFile.hpp" | ||
| 10 | #include "ValidityReport.hpp" | ||
| 11 | |||
| 12 | #include <utilities/idd/IddEnums.hxx> | ||
| 13 | #include <utilities/idd/IddFactory.hxx> | ||
| 14 | |||
| 15 | #include "../plot/ProgressBar.hpp" | ||
| 16 | |||
| 17 | #include "../core/Assert.hpp" | ||
| 18 | #include "../core/StringHelpers.hpp" | ||
| 19 | |||
| 20 | #include <boost/lexical_cast.hpp> | ||
| 21 | #include <memory> | ||
| 22 | |||
| 23 | using namespace std; | ||
| 24 | using openstudio::istringEqual; // used for all name comparisons | ||
| 25 | |||
| 26 | namespace openstudio { | ||
| 27 | |||
| 28 | namespace detail { | ||
| 29 | |||
| 30 | // CONSTRUCTORS | ||
| 31 | |||
| 32 | 6641 | Workspace_Impl::Workspace_Impl(StrictnessLevel level, IddFileType iddFileType) | |
| 33 | 6641 | : m_strictnessLevel(level), | |
| 34 |
1/1✓ Branch 1 taken 6641 times.
|
6641 | m_iddFileAndFactoryWrapper(iddFileType), |
| 35 | 6641 | m_fastNaming(false), | |
| 36 |
2/2✓ Branch 1 taken 6641 times.
✓ Branch 4 taken 6641 times.
|
6641 | m_workspaceObjectOrder(std::make_shared<WorkspaceObjectOrder_Impl>( |
| 37 | 19923 | HandleVector(), [this](const Handle& handle) -> boost::optional<WorkspaceObject> { return getObject(handle); })) { | |
| 38 |
1/1✓ Branch 1 taken 6641 times.
|
6641 | m_workspaceObjectMap.reserve(1 << 15); |
| 39 |
1/1✓ Branch 1 taken 6641 times.
|
6641 | m_idfReferencesMap.reserve(1 << 15); |
| 40 | 6641 | } | |
| 41 | |||
| 42 | 411 | Workspace_Impl::Workspace_Impl(const IdfFile& idfFile, StrictnessLevel level) | |
| 43 | 411 | : m_strictnessLevel(level), | |
| 44 |
1/1✓ Branch 1 taken 411 times.
|
411 | m_header(idfFile.header()), |
| 45 |
1/1✓ Branch 1 taken 411 times.
|
411 | m_iddFileAndFactoryWrapper(idfFile.iddFileAndFactoryWrapper()), |
| 46 | 411 | m_fastNaming(false), | |
| 47 |
2/2✓ Branch 1 taken 411 times.
✓ Branch 4 taken 411 times.
|
411 | m_workspaceObjectOrder(std::make_shared<WorkspaceObjectOrder_Impl>( |
| 48 | 1233 | HandleVector(), [this](const Handle& handle) -> boost::optional<WorkspaceObject> { return getObject(handle); })) { | |
| 49 |
1/1✓ Branch 1 taken 411 times.
|
411 | m_workspaceObjectMap.reserve(1 << 15); |
| 50 |
1/1✓ Branch 1 taken 411 times.
|
411 | m_idfReferencesMap.reserve(1 << 15); |
| 51 | 411 | } | |
| 52 | |||
| 53 | 1399 | Workspace_Impl::Workspace_Impl(const Workspace_Impl& other, bool /*keepHandles*/) | |
| 54 | 1399 | : m_strictnessLevel(other.m_strictnessLevel), | |
| 55 |
1/1✓ Branch 1 taken 1399 times.
|
1399 | m_header(other.m_header), |
| 56 |
1/1✓ Branch 1 taken 1399 times.
|
1399 | m_iddFileAndFactoryWrapper(other.m_iddFileAndFactoryWrapper), |
| 57 |
1/1✓ Branch 1 taken 1399 times.
|
1399 | m_fastNaming(other.fastNaming()), |
| 58 |
2/2✓ Branch 1 taken 1399 times.
✓ Branch 4 taken 1399 times.
|
1399 | m_workspaceObjectOrder(std::make_shared<WorkspaceObjectOrder_Impl>( |
| 59 | 4197 | HandleVector(), [this](const Handle& handle) -> boost::optional<WorkspaceObject> { return getObject(handle); })) { | |
| 60 | // m_workspaceObjectOrder | ||
| 61 |
2/2✓ Branch 1 taken 1399 times.
✓ Branch 4 taken 1399 times.
|
1399 | OptionalIddObjectTypeVector iddOrderVector = other.order().iddOrder(); |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1399 times.
|
1399 | if (iddOrderVector) { |
| 63 | ✗ | m_workspaceObjectOrder.setIddOrder(*iddOrderVector); | |
| 64 | } | ||
| 65 |
2/2✓ Branch 1 taken 1399 times.
✓ Branch 4 taken 1399 times.
|
1399 | OptionalHandleVector directOrderVector = other.order().directOrder(); |
| 66 |
1/2✓ Branch 0 taken 1399 times.
✗ Branch 1 not taken.
|
1399 | if (directOrderVector) { |
| 67 |
2/2✓ Branch 1 taken 1399 times.
✓ Branch 4 taken 1399 times.
|
1399 | m_workspaceObjectOrder.setDirectOrder(*directOrderVector); |
| 68 | } | ||
| 69 |
1/1✓ Branch 1 taken 1399 times.
|
1399 | m_workspaceObjectMap.reserve(1 << 15); |
| 70 |
1/1✓ Branch 1 taken 1399 times.
|
1399 | m_idfReferencesMap.reserve(1 << 15); |
| 71 | 1399 | } | |
| 72 | |||
| 73 | 9888 | Workspace_Impl::Workspace_Impl(const Workspace_Impl& other, const std::vector<Handle>& hs, bool /*keepHandles*/, StrictnessLevel level) | |
| 74 | 9888 | : m_strictnessLevel(level), | |
| 75 | 9888 | m_header(), // subset of original data--discard header | |
| 76 |
1/1✓ Branch 1 taken 9888 times.
|
9888 | m_iddFileAndFactoryWrapper(other.m_iddFileAndFactoryWrapper), |
| 77 |
1/1✓ Branch 1 taken 9888 times.
|
9888 | m_fastNaming(other.fastNaming()), |
| 78 |
2/2✓ Branch 1 taken 9888 times.
✓ Branch 4 taken 9888 times.
|
9888 | m_workspaceObjectOrder(std::make_shared<WorkspaceObjectOrder_Impl>( |
| 79 | 29664 | HandleVector(), [this](const Handle& handle) -> boost::optional<WorkspaceObject> { return getObject(handle); })) { | |
| 80 | // m_workspaceObjectOrder | ||
| 81 |
2/2✓ Branch 1 taken 9888 times.
✓ Branch 4 taken 9888 times.
|
9888 | OptionalIddObjectTypeVector iddOrderVector = other.order().iddOrder(); |
| 82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9888 times.
|
9888 | if (iddOrderVector) { |
| 83 | ✗ | m_workspaceObjectOrder.setIddOrder(*iddOrderVector); | |
| 84 | } | ||
| 85 |
2/2✓ Branch 1 taken 9888 times.
✓ Branch 4 taken 9888 times.
|
9888 | OptionalHandleVector directOrderVector = other.order().directOrder(); |
| 86 |
1/2✓ Branch 0 taken 9888 times.
✗ Branch 1 not taken.
|
9888 | if (directOrderVector) { |
| 87 | // discard unused handles | ||
| 88 | 9888 | HandleVector subsetOrder; | |
| 89 |
3/3✓ Branch 1 taken 9888 times.
✓ Branch 8 taken 1283711 times.
✓ Branch 9 taken 9888 times.
|
1293599 | for (const Handle& h : *directOrderVector) { |
| 90 |
3/3✓ Branch 4 taken 1283711 times.
✓ Branch 7 taken 315 times.
✓ Branch 8 taken 1283396 times.
|
1283711 | if (std::find(hs.begin(), hs.end(), h) != hs.end()) { |
| 91 |
1/1✓ Branch 1 taken 315 times.
|
315 | subsetOrder.push_back(h); |
| 92 | } | ||
| 93 | } | ||
| 94 |
1/1✓ Branch 1 taken 9888 times.
|
9888 | m_workspaceObjectOrder.setDirectOrder(subsetOrder); |
| 95 | 9888 | } | |
| 96 |
1/1✓ Branch 1 taken 9888 times.
|
9888 | m_workspaceObjectMap.reserve(1 << 15); |
| 97 |
1/1✓ Branch 1 taken 9888 times.
|
9888 | m_idfReferencesMap.reserve(1 << 15); |
| 98 | 9888 | } | |
| 99 | |||
| 100 | 265 | Workspace Workspace_Impl::clone(bool keepHandles) const { | |
| 101 | // copy everything but objects | ||
| 102 |
3/5✓ Branch 1 taken 265 times.
✓ Branch 4 taken 265 times.
✓ Branch 7 taken 265 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
265 | std::shared_ptr<Workspace_Impl> cloneImpl(new Workspace_Impl(*this, keepHandles)); |
| 103 | // clone objects | ||
| 104 |
2/2✓ Branch 2 taken 265 times.
✓ Branch 6 taken 265 times.
|
265 | createAndAddClonedObjects(workspace().getImpl<Workspace_Impl>(), cloneImpl, keepHandles); |
| 105 | // wrap impl and return | ||
| 106 |
1/1✓ Branch 2 taken 265 times.
|
265 | Workspace result(cloneImpl); |
| 107 | 530 | return result; | |
| 108 | 265 | } | |
| 109 | |||
| 110 | 104 | Workspace Workspace_Impl::cloneSubset(const std::vector<Handle>& handles, bool keepHandles, StrictnessLevel level) const { | |
| 111 | // copy everything but objects | ||
| 112 |
3/5✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
✓ Branch 7 taken 104 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
104 | std::shared_ptr<Workspace_Impl> cloneImpl(new Workspace_Impl(*this, handles, keepHandles, level)); |
| 113 | // clone objects | ||
| 114 |
2/2✓ Branch 2 taken 104 times.
✓ Branch 6 taken 104 times.
|
104 | createAndAddSubsetClonedObjects(workspace().getImpl<Workspace_Impl>(), cloneImpl, handles, keepHandles); |
| 115 | // wrap impl and return | ||
| 116 |
1/1✓ Branch 2 taken 104 times.
|
104 | Workspace result(cloneImpl); |
| 117 | 208 | return result; | |
| 118 | 104 | } | |
| 119 | |||
| 120 | 1 | void Workspace_Impl::swap(Workspace& other) { | |
| 121 | 1 | std::shared_ptr<Workspace_Impl> otherImpl = other.getImpl<Workspace_Impl>(); | |
| 122 | |||
| 123 | 1 | StrictnessLevel tsl = m_strictnessLevel; | |
| 124 | 1 | m_strictnessLevel = otherImpl->m_strictnessLevel; | |
| 125 | 1 | otherImpl->m_strictnessLevel = tsl; | |
| 126 | |||
| 127 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string th = m_header; |
| 128 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_header = otherImpl->m_header; |
| 129 |
1/1✓ Branch 2 taken 1 time.
|
1 | otherImpl->m_header = th; |
| 130 | |||
| 131 |
1/1✓ Branch 1 taken 1 time.
|
1 | IddFileAndFactoryWrapper tifafw = m_iddFileAndFactoryWrapper; |
| 132 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_iddFileAndFactoryWrapper = otherImpl->m_iddFileAndFactoryWrapper; |
| 133 |
1/1✓ Branch 2 taken 1 time.
|
1 | otherImpl->m_iddFileAndFactoryWrapper = tifafw; |
| 134 | |||
| 135 | 1 | bool tfn = m_fastNaming; | |
| 136 | 1 | m_fastNaming = otherImpl->m_fastNaming; | |
| 137 | 1 | otherImpl->m_fastNaming = tfn; | |
| 138 | |||
| 139 |
1/1✓ Branch 1 taken 1 time.
|
1 | WorkspaceObjectMap twop = m_workspaceObjectMap; |
| 140 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_workspaceObjectMap = otherImpl->m_workspaceObjectMap; |
| 141 |
1/1✓ Branch 2 taken 1 time.
|
1 | otherImpl->m_workspaceObjectMap = twop; |
| 142 | |||
| 143 | 1 | WorkspaceObjectOrder twoo = m_workspaceObjectOrder; | |
| 144 | 1 | m_workspaceObjectOrder = otherImpl->m_workspaceObjectOrder; | |
| 145 | 1 | otherImpl->m_workspaceObjectOrder = twoo; | |
| 146 | |||
| 147 |
1/1✓ Branch 1 taken 1 time.
|
1 | IddObjectTypeMap tiotm = m_iddObjectTypeMap; |
| 148 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_iddObjectTypeMap = otherImpl->m_iddObjectTypeMap; |
| 149 |
1/1✓ Branch 2 taken 1 time.
|
1 | otherImpl->m_iddObjectTypeMap = tiotm; |
| 150 | |||
| 151 |
1/1✓ Branch 1 taken 1 time.
|
1 | IdfReferencesMap tirm = m_idfReferencesMap; |
| 152 |
1/1✓ Branch 2 taken 1 time.
|
1 | m_idfReferencesMap = otherImpl->m_idfReferencesMap; |
| 153 |
1/1✓ Branch 2 taken 1 time.
|
1 | otherImpl->m_idfReferencesMap = tirm; |
| 154 | 1 | } | |
| 155 | |||
| 156 | // GETTERS | ||
| 157 | |||
| 158 | 21467 | Workspace Workspace_Impl::workspace() { | |
| 159 | 21467 | return getWorkspace<Workspace>(); | |
| 160 | } | ||
| 161 | |||
| 162 | 369 | Workspace Workspace_Impl::workspace() const { | |
| 163 | 369 | return getWorkspace<Workspace>(); | |
| 164 | } | ||
| 165 | |||
| 166 | 3478534 | StrictnessLevel Workspace_Impl::strictnessLevel() const { | |
| 167 | 3478534 | return m_strictnessLevel; | |
| 168 | } | ||
| 169 | |||
| 170 | 1744 | VersionString Workspace_Impl::version() const { | |
| 171 |
2/2✓ Branch 1 taken 1744 times.
✓ Branch 4 taken 1744 times.
|
1744 | return VersionString(m_iddFileAndFactoryWrapper.version()); |
| 172 | } | ||
| 173 | |||
| 174 | 1 | IddFile Workspace_Impl::iddFile() const { | |
| 175 | 1 | return m_iddFileAndFactoryWrapper.iddFile(); | |
| 176 | } | ||
| 177 | |||
| 178 | 601947 | IddFileType Workspace_Impl::iddFileType() const { | |
| 179 | 601947 | return m_iddFileAndFactoryWrapper.iddFileType(); | |
| 180 | } | ||
| 181 | |||
| 182 | 111367 | boost::optional<IddObject> Workspace_Impl::getIddObject(const IddObjectType& type) const { | |
| 183 | 111367 | return m_iddFileAndFactoryWrapper.getObject(type); | |
| 184 | } | ||
| 185 | |||
| 186 | 35436 | boost::optional<std::string> Workspace_Impl::name(const Handle& handle) const { | |
| 187 |
1/1✓ Branch 1 taken 35436 times.
|
35436 | OptionalWorkspaceObject object = getObject(handle); |
| 188 |
2/2✓ Branch 0 taken 34506 times.
✓ Branch 1 taken 930 times.
|
35436 | if (object) { |
| 189 |
2/2✓ Branch 1 taken 34506 times.
✓ Branch 4 taken 34506 times.
|
34506 | return object->name(); |
| 190 | } | ||
| 191 | 930 | return boost::none; | |
| 192 | 35436 | } | |
| 193 | |||
| 194 | 9224179 | boost::optional<WorkspaceObject> Workspace_Impl::getObject(const Handle& handle) const { | |
| 195 |
1/1✓ Branch 1 taken 9224179 times.
|
9224179 | auto womIt = m_workspaceObjectMap.find(handle); |
| 196 |
2/2✓ Branch 2 taken 9210783 times.
✓ Branch 3 taken 13396 times.
|
9224179 | if (womIt != m_workspaceObjectMap.end()) { |
| 197 |
2/2✓ Branch 3 taken 9210783 times.
✓ Branch 6 taken 9210783 times.
|
9210783 | return WorkspaceObject(womIt->second); |
| 198 | } | ||
| 199 | 13396 | return boost::none; | |
| 200 | } | ||
| 201 | |||
| 202 | 70972 | std::vector<WorkspaceObject> Workspace_Impl::objects(bool sorted) const { | |
| 203 |
1/1✓ Branch 1 taken 70972 times.
|
70972 | OptionalIddObject versionIdd = m_iddFileAndFactoryWrapper.versionObject(); |
| 204 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 70972 times.
|
70972 | if (!versionIdd) { |
| 205 | ✗ | return {}; | |
| 206 | } | ||
| 207 | |||
| 208 |
2/2✓ Branch 0 taken 2363 times.
✓ Branch 1 taken 68609 times.
|
70972 | if (sorted) { |
| 209 |
2/2✓ Branch 1 taken 2363 times.
✓ Branch 4 taken 2363 times.
|
2363 | OptionalHandleVector directOrder = order().directOrder(); |
| 210 |
8/8✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 2360 times.
✓ Branch 7 taken 2360 times.
✓ Branch 9 taken 1545 times.
✓ Branch 10 taken 815 times.
✓ Branch 11 taken 1545 times.
✓ Branch 12 taken 818 times.
|
2363 | if (directOrder && (directOrder->size() == numObjects())) { |
| 211 | 1545 | WorkspaceObjectVector result; | |
| 212 | 1545 | HandleSet setToCheckUniqueness; | |
| 213 |
3/3✓ Branch 1 taken 1545 times.
✓ Branch 8 taken 3663 times.
✓ Branch 9 taken 1545 times.
|
5208 | for (const Handle& h : *directOrder) { |
| 214 |
1/1✓ Branch 1 taken 3663 times.
|
3663 | OptionalWorkspaceObject owo = getObject(h); |
| 215 |
1/1✓ Branch 1 taken 3663 times.
|
3663 | std::pair<HandleSet::iterator, bool> insertResult = setToCheckUniqueness.insert(h); |
| 216 |
9/16✓ Branch 1 taken 3663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3663 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3663 times.
✓ Branch 9 taken 3663 times.
✓ Branch 12 taken 3663 times.
✓ Branch 15 taken 3663 times.
✓ Branch 17 taken 3663 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 3663 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3663 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
7326 | if (owo && insertResult.second && (owo->iddObject() != versionIdd.get())) { |
| 217 |
2/2✓ Branch 1 taken 3663 times.
✓ Branch 4 taken 3663 times.
|
3663 | result.push_back(*owo); |
| 218 | } else { | ||
| 219 | ✗ | return sort(objects(false)); | |
| 220 | } | ||
| 221 | 3663 | } | |
| 222 | 1545 | return result; | |
| 223 | 1545 | } | |
| 224 |
2/2✓ Branch 1 taken 818 times.
✓ Branch 4 taken 818 times.
|
818 | return sort(objects(false)); |
| 225 | 2363 | } | |
| 226 | |||
| 227 | 68609 | WorkspaceObjectVector result; | |
| 228 |
2/2✓ Branch 5 taken 2959092 times.
✓ Branch 6 taken 68609 times.
|
3027701 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 229 |
1/1✓ Branch 2 taken 2959092 times.
|
2959092 | WorkspaceObject obj = WorkspaceObject(p.second); |
| 230 |
5/5✓ Branch 1 taken 2959092 times.
✓ Branch 4 taken 2959092 times.
✓ Branch 7 taken 2959092 times.
✓ Branch 10 taken 2891384 times.
✓ Branch 11 taken 67708 times.
|
2959092 | if (obj.iddObject() != versionIdd.get()) { |
| 231 |
1/1✓ Branch 1 taken 2891384 times.
|
2891384 | result.push_back(obj); |
| 232 | } | ||
| 233 | 2959092 | } | |
| 234 | 68609 | return result; | |
| 235 | 70972 | } | |
| 236 | |||
| 237 | 11 | std::vector<Handle> Workspace_Impl::handles(bool sorted) const { | |
| 238 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
|
11 | if (sorted) { |
| 239 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | OptionalHandleVector directOrder = order().directOrder(); |
| 240 |
5/8✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
|
3 | if (directOrder && (directOrder->size() == numObjects())) { |
| 241 | ✗ | HandleSet setToCheckUniqueness; | |
| 242 | ✗ | for (const Handle& h : *directOrder) { | |
| 243 | ✗ | std::pair<HandleSet::iterator, bool> insertResult = setToCheckUniqueness.insert(h); | |
| 244 | ✗ | if (!insertResult.second) { | |
| 245 | ✗ | return sort(handles(false)); | |
| 246 | } | ||
| 247 | } | ||
| 248 | ✗ | return *directOrder; | |
| 249 | ✗ | } | |
| 250 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | return sort(handles(false)); |
| 251 | 3 | } | |
| 252 | |||
| 253 | 8 | HandleVector result; | |
| 254 |
1/1✓ Branch 1 taken 8 times.
|
8 | OptionalIddObject versionIdd = m_iddFileAndFactoryWrapper.versionObject(); |
| 255 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (!versionIdd) { |
| 256 | ✗ | return result; | |
| 257 | } | ||
| 258 |
2/2✓ Branch 5 taken 3049 times.
✓ Branch 6 taken 8 times.
|
3057 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 259 |
5/5✓ Branch 1 taken 3049 times.
✓ Branch 5 taken 3049 times.
✓ Branch 8 taken 3049 times.
✓ Branch 11 taken 3041 times.
✓ Branch 12 taken 8 times.
|
3049 | if (p.second->iddObject() != versionIdd.get()) { |
| 260 |
1/1✓ Branch 1 taken 3041 times.
|
3041 | result.push_back(p.first); |
| 261 | } | ||
| 262 | } | ||
| 263 | 8 | return result; | |
| 264 | 8 | } | |
| 265 | |||
| 266 | 1 | std::vector<WorkspaceObject> Workspace_Impl::objectsWithURLFields() const { | |
| 267 | 1 | WorkspaceObjectVector result; | |
| 268 |
2/2✓ Branch 5 taken 383 times.
✓ Branch 6 taken 1 time.
|
384 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 269 |
4/4✓ Branch 2 taken 383 times.
✓ Branch 5 taken 383 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 382 times.
|
383 | if (p.second->iddObject().hasURL()) { |
| 270 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | result.push_back(WorkspaceObject(p.second)); |
| 271 | } | ||
| 272 | } | ||
| 273 | 1 | return result; | |
| 274 | ✗ | } | |
| 275 | |||
| 276 | 13254 | boost::optional<WorkspaceObject> Workspace_Impl::versionObject() const { | |
| 277 | 13254 | OptionalWorkspaceObject result; | |
| 278 | 13254 | WorkspaceObjectVector candidates; | |
| 279 |
4/4✓ Branch 1 taken 13254 times.
✓ Branch 4 taken 13254 times.
✓ Branch 7 taken 2311 times.
✓ Branch 8 taken 10943 times.
|
13254 | if (iddFileType() == IddFileType::EnergyPlus) { |
| 280 |
2/2✓ Branch 1 taken 2311 times.
✓ Branch 4 taken 2311 times.
|
2311 | candidates = getObjectsByType(IddObjectType(IddObjectType::Version)); |
| 281 |
3/4✓ Branch 1 taken 10943 times.
✓ Branch 4 taken 10943 times.
✓ Branch 7 taken 10943 times.
✗ Branch 8 not taken.
|
10943 | } else if (iddFileType() == IddFileType::OpenStudio) { |
| 282 |
2/2✓ Branch 1 taken 10943 times.
✓ Branch 4 taken 10943 times.
|
10943 | candidates = getObjectsByType(IddObjectType(IddObjectType::OS_Version)); |
| 283 | ✗ | } else if (OptionalIddObject versionIdd = m_iddFileAndFactoryWrapper.versionObject()) { | |
| 284 | ✗ | candidates = getObjectsByType(*versionIdd); | |
| 285 | ✗ | } | |
| 286 |
2/2✓ Branch 1 taken 11510 times.
✓ Branch 2 taken 1744 times.
|
13254 | if (candidates.size() == 1u) { |
| 287 |
1/1✓ Branch 2 taken 11510 times.
|
11510 | result = candidates[0]; |
| 288 | } | ||
| 289 | 26508 | return result; | |
| 290 | 13254 | } | |
| 291 | |||
| 292 | ✗ | std::vector<WorkspaceObject> Workspace_Impl::getObjects(const std::vector<Handle>& handles) const { | |
| 293 | ✗ | WorkspaceObjectVector result; | |
| 294 | ✗ | result.reserve(handles.size()); | |
| 295 | |||
| 296 | ✗ | bool lossy = false; | |
| 297 | |||
| 298 | // return in same order | ||
| 299 | ✗ | for (const Handle& handle : handles) { | |
| 300 | ✗ | OptionalWorkspaceObject candidate = getObject(handle); | |
| 301 | ✗ | if (candidate) { | |
| 302 | ✗ | result.push_back(*candidate); | |
| 303 | } else { | ||
| 304 | ✗ | lossy = true; | |
| 305 | } | ||
| 306 | ✗ | } | |
| 307 | |||
| 308 | ✗ | if (lossy) { | |
| 309 | ✗ | LOG(Warn, "Invalid handle. Cannot return all requested objects."); | |
| 310 | } | ||
| 311 | ✗ | return result; | |
| 312 | ✗ | } | |
| 313 | |||
| 314 | 22033 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByName(const std::string& name, bool exactMatch) const { | |
| 315 | 22033 | WorkspaceObjectVector result; | |
| 316 |
2/2✓ Branch 0 taken 11561 times.
✓ Branch 1 taken 10472 times.
|
22033 | if (exactMatch) { |
| 317 |
2/2✓ Branch 5 taken 1811259 times.
✓ Branch 6 taken 11561 times.
|
1822820 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 318 |
3/3✓ Branch 2 taken 1811259 times.
✓ Branch 4 taken 1386223 times.
✓ Branch 5 taken 425036 times.
|
3622518 | if (OptionalString candidate = p.second->name()) { |
| 319 |
4/4✓ Branch 1 taken 1386223 times.
✓ Branch 4 taken 1386223 times.
✓ Branch 6 taken 9200 times.
✓ Branch 7 taken 1377023 times.
|
1386223 | if (istringEqual(*candidate, name)) { |
| 320 |
2/2✓ Branch 2 taken 9200 times.
✓ Branch 5 taken 9200 times.
|
9200 | result.push_back(WorkspaceObject(p.second)); |
| 321 | } | ||
| 322 | 1811259 | } | |
| 323 | } | ||
| 324 | } else { | ||
| 325 |
1/1✓ Branch 1 taken 10472 times.
|
10472 | std::string baseName = getBaseName(name); |
| 326 |
2/2✓ Branch 5 taken 1158098 times.
✓ Branch 6 taken 10472 times.
|
1168570 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 327 |
3/3✓ Branch 2 taken 1158098 times.
✓ Branch 4 taken 960026 times.
✓ Branch 5 taken 198072 times.
|
2316196 | if (OptionalString candidate = p.second->name()) { |
| 328 |
4/4✓ Branch 1 taken 960026 times.
✓ Branch 4 taken 960026 times.
✓ Branch 6 taken 57283 times.
✓ Branch 7 taken 902743 times.
|
960026 | if (baseNamesMatch(baseName, *candidate)) { |
| 329 |
2/2✓ Branch 2 taken 57283 times.
✓ Branch 5 taken 57283 times.
|
57283 | result.push_back(WorkspaceObject(p.second)); |
| 330 | } | ||
| 331 | 1158098 | } | |
| 332 | } | ||
| 333 | 10472 | } | |
| 334 | 22033 | return result; | |
| 335 | ✗ | } | |
| 336 | |||
| 337 | 535153 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByType(IddObjectType objectType) const { | |
| 338 |
1/1✓ Branch 1 taken 535153 times.
|
535153 | auto loc = m_iddObjectTypeMap.find(objectType); |
| 339 |
2/2✓ Branch 2 taken 385335 times.
✓ Branch 3 taken 149818 times.
|
535153 | if (loc == m_iddObjectTypeMap.end()) { |
| 340 | 385335 | return {}; | |
| 341 | } | ||
| 342 | 149818 | std::vector<WorkspaceObject> result; | |
| 343 |
1/1✓ Branch 3 taken 149818 times.
|
149818 | result.reserve(loc->second.size()); |
| 344 |
2/2✓ Branch 5 taken 7498721 times.
✓ Branch 6 taken 149818 times.
|
7648539 | for (auto it = loc->second.begin(); it != loc->second.end(); ++it) { |
| 345 |
2/2✓ Branch 3 taken 7498721 times.
✓ Branch 6 taken 7498721 times.
|
7498721 | result.push_back(it->second); |
| 346 | } | ||
| 347 | 149818 | return result; | |
| 348 | 149818 | } | |
| 349 | |||
| 350 | 84 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByType(const IddObject& objectType) const { | |
| 351 | 84 | WorkspaceObjectVector result; | |
| 352 |
3/3✓ Branch 1 taken 84 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 84 times.
|
86 | for (const WorkspaceObject& object : objects()) { |
| 353 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | if (object.iddObject() == objectType) { |
| 354 |
1/1✓ Branch 1 taken 2 times.
|
2 | result.push_back(object); |
| 355 | } | ||
| 356 | 84 | } | |
| 357 | 84 | return result; | |
| 358 | ✗ | } | |
| 359 | |||
| 360 | 6597 | boost::optional<WorkspaceObject> Workspace_Impl::getObjectByTypeAndName(IddObjectType objectType, const std::string& name) const { | |
| 361 |
3/3✓ Branch 1 taken 6597 times.
✓ Branch 8 taken 97429 times.
✓ Branch 9 taken 1005 times.
|
98434 | for (const WorkspaceObject& object : getObjectsByType(objectType)) { |
| 362 |
1/1✓ Branch 1 taken 97429 times.
|
97429 | OptionalString candidate = object.name(); |
| 363 |
8/8✓ Branch 0 taken 97425 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 97425 times.
✓ Branch 6 taken 97425 times.
✓ Branch 8 taken 5592 times.
✓ Branch 9 taken 91833 times.
✓ Branch 10 taken 5592 times.
✓ Branch 11 taken 91837 times.
|
97429 | if (candidate && istringEqual(*candidate, name)) { |
| 364 |
1/1✓ Branch 1 taken 5592 times.
|
5592 | return object; |
| 365 | } | ||
| 366 | 104026 | } | |
| 367 | 1005 | return boost::none; | |
| 368 | } | ||
| 369 | |||
| 370 | 114639 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByTypeAndName(IddObjectType objectType, const std::string& name) const { | |
| 371 | 114639 | WorkspaceObjectVector result; | |
| 372 |
1/1✓ Branch 1 taken 114639 times.
|
114639 | std::string baseName = getBaseName(name); |
| 373 |
3/3✓ Branch 1 taken 114639 times.
✓ Branch 8 taken 7168822 times.
✓ Branch 9 taken 114639 times.
|
7283461 | for (const WorkspaceObject& object : getObjectsByType(objectType)) { |
| 374 |
2/3✓ Branch 1 taken 7168822 times.
✓ Branch 3 taken 7168822 times.
✗ Branch 4 not taken.
|
14337644 | if (OptionalString candidate = object.name()) { |
| 375 |
4/4✓ Branch 1 taken 7168822 times.
✓ Branch 4 taken 7168822 times.
✓ Branch 6 taken 810991 times.
✓ Branch 7 taken 6357831 times.
|
7168822 | if (baseNamesMatch(baseName, *candidate)) { |
| 376 |
1/1✓ Branch 1 taken 810991 times.
|
810991 | result.push_back(object); |
| 377 | } | ||
| 378 | 7168822 | } | |
| 379 | 114639 | } | |
| 380 | 229278 | return result; | |
| 381 | 114639 | } | |
| 382 | |||
| 383 | 3 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByReference(const std::string& referenceName) const { | |
| 384 |
1/1✓ Branch 1 taken 3 times.
|
3 | auto loc = m_idfReferencesMap.find(referenceName); |
| 385 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
|
3 | if (loc == m_idfReferencesMap.end()) { |
| 386 | 1 | return {}; | |
| 387 | } | ||
| 388 | 2 | std::vector<WorkspaceObject> result; | |
| 389 |
1/1✓ Branch 3 taken 2 times.
|
2 | result.reserve(loc->second.size()); |
| 390 |
2/2✓ Branch 5 taken 8 times.
✓ Branch 6 taken 2 times.
|
10 | for (auto it = loc->second.begin(); it != loc->second.end(); ++it) { |
| 391 |
2/2✓ Branch 3 taken 8 times.
✓ Branch 6 taken 8 times.
|
8 | result.push_back(it->second); |
| 392 | } | ||
| 393 | 2 | return result; | |
| 394 | 2 | } | |
| 395 | |||
| 396 | 263280 | std::vector<WorkspaceObject> Workspace_Impl::getObjectsByReference(const std::vector<std::string>& referenceNames) const { | |
| 397 | 263280 | WorkspaceObjectMap objectMap; | |
| 398 |
2/2✓ Branch 5 taken 1009567 times.
✓ Branch 6 taken 263280 times.
|
1272847 | for (const std::string& referenceName : referenceNames) { |
| 399 |
1/1✓ Branch 1 taken 1009567 times.
|
1009567 | auto loc = m_idfReferencesMap.find(referenceName); |
| 400 |
2/2✓ Branch 2 taken 908997 times.
✓ Branch 3 taken 100570 times.
|
1009567 | if (loc != m_idfReferencesMap.end()) { |
| 401 |
1/1✓ Branch 5 taken 908997 times.
|
908997 | objectMap.insert(loc->second.begin(), loc->second.end()); |
| 402 | } | ||
| 403 | } | ||
| 404 | 263280 | std::vector<WorkspaceObject> result; | |
| 405 |
1/1✓ Branch 2 taken 263280 times.
|
263280 | result.reserve(objectMap.size()); |
| 406 |
2/2✓ Branch 3 taken 21463311 times.
✓ Branch 4 taken 263280 times.
|
21726591 | for (auto it = objectMap.begin(); it != objectMap.end(); ++it) { |
| 407 |
2/2✓ Branch 3 taken 21463311 times.
✓ Branch 6 taken 21463311 times.
|
21463311 | result.push_back(it->second); |
| 408 | } | ||
| 409 | 526560 | return result; | |
| 410 | 263280 | } | |
| 411 | |||
| 412 | 72944 | boost::optional<WorkspaceObject> Workspace_Impl::getObjectByNameAndReference(const std::string& name, | |
| 413 | const std::vector<std::string>& referenceNames) const { | ||
| 414 |
3/3✓ Branch 1 taken 72944 times.
✓ Branch 8 taken 1863516 times.
✓ Branch 9 taken 386 times.
|
1863902 | for (const WorkspaceObject& object : getObjectsByReference(referenceNames)) { |
| 415 |
1/1✓ Branch 1 taken 1863516 times.
|
1863516 | OptionalString candidate = object.name(); |
| 416 |
7/8✓ Branch 0 taken 1863516 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1863516 times.
✓ Branch 6 taken 1863516 times.
✓ Branch 8 taken 72558 times.
✓ Branch 9 taken 1790958 times.
✓ Branch 10 taken 72558 times.
✓ Branch 11 taken 1790958 times.
|
1863516 | if (candidate && istringEqual(*candidate, name)) { |
| 417 |
1/1✓ Branch 1 taken 72558 times.
|
72558 | return object; |
| 418 | } | ||
| 419 | 1936460 | } | |
| 420 | 386 | return boost::none; | |
| 421 | } | ||
| 422 | |||
| 423 | 11292 | bool Workspace_Impl::fastNaming() const { | |
| 424 | 11292 | return m_fastNaming; | |
| 425 | } | ||
| 426 | |||
| 427 | // SETTERS | ||
| 428 | |||
| 429 | 185 | bool Workspace_Impl::setStrictnessLevel(StrictnessLevel level) { | |
| 430 |
1/2✓ Branch 1 taken 185 times.
✗ Branch 2 not taken.
|
185 | if (isValid(level)) { |
| 431 | 185 | m_strictnessLevel = level; | |
| 432 | 185 | return true; | |
| 433 | } | ||
| 434 | ✗ | return false; | |
| 435 | } | ||
| 436 | |||
| 437 | // Helper function to start the process of adding an object to the workspace. | ||
| 438 | 147337 | std::shared_ptr<WorkspaceObject_Impl> Workspace_Impl::createObject(const IdfObject& object, bool keepHandle) { | |
| 439 |
2/4✓ Branch 2 taken 147337 times.
✓ Branch 5 taken 147337 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
147337 | return WorkspaceObject_ImplPtr(new WorkspaceObject_Impl(object, this, keepHandle)); |
| 440 | } | ||
| 441 | |||
| 442 | // Helper function to start the process of adding a cloned object to the workspace. | ||
| 443 | 10623 | WorkspaceObject_ImplPtr Workspace_Impl::createObject(const std::shared_ptr<WorkspaceObject_Impl>& originalObjectImplPtr, bool keepHandle) { | |
| 444 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10623 times.
|
10623 | OS_ASSERT(originalObjectImplPtr); |
| 445 |
2/4✓ Branch 3 taken 10623 times.
✓ Branch 6 taken 10623 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
10623 | return WorkspaceObject_ImplPtr(new WorkspaceObject_Impl(*originalObjectImplPtr, this, keepHandle)); |
| 446 | } | ||
| 447 | |||
| 448 | 177615 | std::vector<WorkspaceObject> Workspace_Impl::addObjects(std::vector<std::shared_ptr<WorkspaceObject_Impl>>& objectImplPtrs, bool checkNames) { | |
| 449 |
1/1✓ Branch 3 taken 177615 times.
|
355230 | return addObjects(objectImplPtrs, UHPointerVector(), HUPointerVector(), true, false, checkNames); |
| 450 | } | ||
| 451 | |||
| 452 | 179761 | std::vector<WorkspaceObject> Workspace_Impl::addObjects(std::vector<std::shared_ptr<WorkspaceObject_Impl>>& objectImplPtrs, | |
| 453 | const std::vector<UHPointer>& pointersIntoWorkspace, | ||
| 454 | const std::vector<HUPointer>& pointersFromWorkspace, bool driverMethod, | ||
| 455 | bool expectToLosePointers, bool checkNames) { | ||
| 456 | 179761 | HandleVector newHandles; | |
| 457 | 179761 | WorkspaceObjectVector newObjects; | |
| 458 | |||
| 459 | 179761 | int i = 0; | |
| 460 | 179761 | int N = objectImplPtrs.size(); | |
| 461 |
1/1✓ Branch 1 taken 179761 times.
|
179761 | this->progressRange.nano_emit(0, 3 * N); |
| 462 |
1/1✓ Branch 1 taken 179761 times.
|
179761 | this->progressValue.nano_emit(0); |
| 463 |
1/1✓ Branch 1 taken 179761 times.
|
179761 | this->progressCaption.nano_emit("Adding Objects"); |
| 464 | |||
| 465 | // step 1: add to maps | ||
| 466 | 179761 | bool ok = true; | |
| 467 |
2/2✓ Branch 5 taken 392254 times.
✓ Branch 6 taken 179761 times.
|
572015 | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 468 |
3/5✓ Branch 0 taken 392254 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 392254 times.
✓ Branch 5 taken 392254 times.
✗ Branch 6 not taken.
|
392254 | ok = ok && nominallyAddObject(ptr); // will fail if ptr already in map |
| 469 |
1/2✓ Branch 0 taken 392254 times.
✗ Branch 1 not taken.
|
392254 | if (ok) { |
| 470 |
2/2✓ Branch 2 taken 392254 times.
✓ Branch 5 taken 392254 times.
|
392254 | newHandles.push_back(ptr->handle()); |
| 471 |
6/6✓ Branch 1 taken 392254 times.
✓ Branch 4 taken 392254 times.
✓ Branch 8 taken 392254 times.
✓ Branch 11 taken 392254 times.
✓ Branch 14 taken 392254 times.
✓ Branch 17 taken 392254 times.
|
392254 | LOG(Trace, "Adding object with handle " << newHandles.back()); |
| 472 | } else { | ||
| 473 | ✗ | LOG(Error, "Tried to add two objects with the same handle: " << ptr->handle()); | |
| 474 | } | ||
| 475 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | this->progressValue.nano_emit(++i); |
| 476 | } | ||
| 477 | |||
| 478 | // step 2: replace string pointers | ||
| 479 |
1/2✓ Branch 0 taken 179761 times.
✗ Branch 1 not taken.
|
179761 | if (ok) { |
| 480 |
2/2✓ Branch 5 taken 392254 times.
✓ Branch 6 taken 179761 times.
|
572015 | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 481 |
1/1✓ Branch 2 taken 392254 times.
|
392254 | ptr->initializeOnAdd(expectToLosePointers); |
| 482 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | this->progressValue.nano_emit(++i); |
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | // step 3: handle provided relationships | ||
| 487 |
6/8✓ Branch 0 taken 179761 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 179685 times.
✓ Branch 4 taken 76 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 179685 times.
✓ Branch 8 taken 76 times.
✓ Branch 9 taken 179685 times.
|
179761 | if (ok && (!pointersIntoWorkspace.empty() || !pointersFromWorkspace.empty())) { |
| 488 |
3/5✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 76 times.
✓ Branch 5 taken 76 times.
✗ Branch 6 not taken.
|
76 | ok = ok && addProvidedRelationships(newHandles, pointersIntoWorkspace, pointersFromWorkspace); |
| 489 | } | ||
| 490 | |||
| 491 | // step 4: register initialization | ||
| 492 |
1/2✓ Branch 0 taken 179761 times.
✗ Branch 1 not taken.
|
179761 | if (ok) { |
| 493 |
2/2✓ Branch 5 taken 392254 times.
✓ Branch 6 taken 179761 times.
|
572015 | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 494 |
1/1✓ Branch 2 taken 392254 times.
|
392254 | ptr->setInitialized(); |
| 495 |
2/2✓ Branch 2 taken 392254 times.
✓ Branch 5 taken 392254 times.
|
392254 | newObjects.push_back(WorkspaceObject(ptr)); |
| 496 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | this->progressValue.nano_emit(++i); |
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 500 | // step 5: check validity | ||
| 501 |
3/4✓ Branch 0 taken 179761 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 179670 times.
✓ Branch 3 taken 91 times.
|
179761 | if (ok && driverMethod) { |
| 502 |
1/1✓ Branch 1 taken 179670 times.
|
179670 | StrictnessLevel level = strictnessLevel(); |
| 503 |
7/8✓ Branch 2 taken 179670 times.
✓ Branch 4 taken 171586 times.
✓ Branch 5 taken 8084 times.
✓ Branch 7 taken 171586 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 171586 times.
✓ Branch 12 taken 8084 times.
✓ Branch 13 taken 171586 times.
|
179670 | if ((objectImplPtrs.size() == numAllObjects()) || (level == StrictnessLevel::Final)) { |
| 504 | // check whole workspace | ||
| 505 |
1/1✓ Branch 1 taken 8084 times.
|
8084 | ok = isValid(); |
| 506 | } else { | ||
| 507 | // check individual objects | ||
| 508 |
2/2✓ Branch 5 taken 172848 times.
✓ Branch 6 taken 171580 times.
|
344428 | for (const WorkspaceObject& newObject : newObjects) { |
| 509 |
4/5✓ Branch 0 taken 172848 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 172848 times.
✓ Branch 5 taken 172842 times.
✓ Branch 6 taken 6 times.
|
172848 | ok = ok && newObject.isValid(level, checkNames); |
| 510 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 172842 times.
|
172848 | if (!ok) { |
| 511 | 6 | break; | |
| 512 | } | ||
| 513 | } | ||
| 514 | } | ||
| 515 | } | ||
| 516 | |||
| 517 | // step 6: rollback if necessary | ||
| 518 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 179754 times.
|
179761 | if (!ok) { |
| 519 |
8/8✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
✓ Branch 13 taken 7 times.
✓ Branch 17 taken 7 times.
✓ Branch 20 taken 7 times.
✓ Branch 23 taken 7 times.
|
7 | LOG(Info, "Unable to add objects to Workspace. The validity report is: " << '\n' << validityReport()); |
| 520 |
1/1✓ Branch 1 taken 7 times.
|
7 | nominallyRemoveObjects(newHandles); // no validity check |
| 521 |
2/2✓ Branch 5 taken 15 times.
✓ Branch 6 taken 7 times.
|
22 | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 522 |
1/1✓ Branch 2 taken 15 times.
|
15 | ptr->disconnect(); |
| 523 | } | ||
| 524 | 7 | newObjects.clear(); | |
| 525 | 7 | return newObjects; | |
| 526 | } | ||
| 527 | |||
| 528 | // step 7: emit signals for successful completion | ||
| 529 |
2/2✓ Branch 0 taken 179663 times.
✓ Branch 1 taken 91 times.
|
179754 | if (driverMethod) { |
| 530 |
2/2✓ Branch 5 taken 392148 times.
✓ Branch 6 taken 179663 times.
|
571811 | for (const WorkspaceObject& newObject : newObjects) { |
| 531 |
1/1✓ Branch 1 taken 392148 times.
|
392148 | registerAdditionOfObject(newObject); |
| 532 | } | ||
| 533 | } | ||
| 534 | |||
| 535 | 179754 | return newObjects; | |
| 536 | 179761 | } | |
| 537 | |||
| 538 | 30612 | std::vector<WorkspaceObject> Workspace_Impl::addClones(std::vector<std::shared_ptr<WorkspaceObject_Impl>>& objectImplPtrs, | |
| 539 | const HandleMap& oldNewHandleMap, bool collectionClone, | ||
| 540 | const std::vector<UHPointer>& pointersIntoWorkspace, | ||
| 541 | const std::vector<HUPointer>& pointersFromWorkspace, bool driverMethod) { | ||
| 542 | 30612 | int i = 0; | |
| 543 | 30612 | int N = objectImplPtrs.size(); | |
| 544 |
2/2✓ Branch 1 taken 1119 times.
✓ Branch 2 taken 29493 times.
|
30612 | if (oldNewHandleMap.empty()) { |
| 545 |
1/1✓ Branch 1 taken 1119 times.
|
1119 | this->progressRange.nano_emit(0, 2 * N); |
| 546 | } else { | ||
| 547 |
1/1✓ Branch 1 taken 29493 times.
|
29493 | this->progressRange.nano_emit(0, 3 * N); |
| 548 | } | ||
| 549 |
1/1✓ Branch 1 taken 30612 times.
|
30612 | this->progressValue.nano_emit(0); |
| 550 |
1/1✓ Branch 1 taken 30612 times.
|
30612 | this->progressCaption.nano_emit("Cloning Objects"); |
| 551 | |||
| 552 | // step 1: add objects to maps | ||
| 553 | 30612 | HandleVector newHandles; | |
| 554 |
2/2✓ Branch 5 taken 180546 times.
✓ Branch 6 taken 30612 times.
|
211158 | for (const WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 555 |
2/2✓ Branch 2 taken 180546 times.
✓ Branch 5 taken 180546 times.
|
180546 | newHandles.push_back(ptr->handle()); |
| 556 |
1/1✓ Branch 3 taken 180546 times.
|
180546 | m_workspaceObjectMap.insert(WorkspaceObjectMap::value_type(newHandles.back(), ptr)); |
| 557 |
1/1✓ Branch 1 taken 180546 times.
|
180546 | insertIntoIddObjectTypeMap(ptr); |
| 558 |
1/1✓ Branch 1 taken 180546 times.
|
180546 | insertIntoIdfReferencesMap(ptr); |
| 559 |
1/1✓ Branch 1 taken 180546 times.
|
180546 | this->progressValue.nano_emit(++i); |
| 560 | } | ||
| 561 | |||
| 562 | // step 2: apply handle map to pointers | ||
| 563 |
2/2✓ Branch 1 taken 29493 times.
✓ Branch 2 taken 1119 times.
|
30612 | if (!oldNewHandleMap.empty()) { |
| 564 |
2/2✓ Branch 5 taken 41865 times.
✓ Branch 6 taken 29493 times.
|
71358 | for (const WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 565 |
1/1✓ Branch 2 taken 41865 times.
|
41865 | ptr->initializeOnClone(oldNewHandleMap); |
| 566 |
1/1✓ Branch 1 taken 41865 times.
|
41865 | this->progressValue.nano_emit(++i); |
| 567 | } | ||
| 568 | } | ||
| 569 | |||
| 570 | // step 3: apply handle map to orderer | ||
| 571 |
6/7✓ Branch 1 taken 29493 times.
✓ Branch 2 taken 1119 times.
✓ Branch 4 taken 29493 times.
✓ Branch 6 taken 29493 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 29493 times.
✓ Branch 9 taken 1119 times.
|
30612 | if (!oldNewHandleMap.empty() && m_workspaceObjectOrder.isDirectOrder()) { |
| 572 |
2/2✓ Branch 0 taken 10168 times.
✓ Branch 1 taken 19325 times.
|
29493 | if (collectionClone) { |
| 573 | // objects in order, just under wrong handles | ||
| 574 |
4/4✓ Branch 1 taken 10168 times.
✓ Branch 4 taken 10168 times.
✓ Branch 7 taken 10168 times.
✓ Branch 10 taken 10168 times.
|
10168 | HandleVector directOrderVector = order().directOrder().get(); |
| 575 |
1/1✓ Branch 1 taken 10168 times.
|
10168 | HandleVector mappedOrder = applyHandleMap(directOrderVector, oldNewHandleMap); |
| 576 |
1/1✓ Branch 1 taken 10168 times.
|
10168 | m_workspaceObjectOrder.setDirectOrder(mappedOrder); |
| 577 | 10168 | } else { | |
| 578 | // new objects not yet in order | ||
| 579 |
2/2✓ Branch 4 taken 23849 times.
✓ Branch 5 taken 19325 times.
|
43174 | for (const WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 580 |
2/2✓ Branch 2 taken 23849 times.
✓ Branch 5 taken 23849 times.
|
23849 | m_workspaceObjectOrder.push_back(ptr->handle()); |
| 581 | } | ||
| 582 | } | ||
| 583 | } | ||
| 584 | |||
| 585 | // step 4: handle provided relationships | ||
| 586 | 30612 | bool ok = true; | |
| 587 |
5/6✓ Branch 1 taken 25227 times.
✓ Branch 2 taken 5385 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 25227 times.
✓ Branch 6 taken 5385 times.
✓ Branch 7 taken 25227 times.
|
30612 | if (!pointersIntoWorkspace.empty() || !pointersFromWorkspace.empty()) { |
| 588 |
3/5✓ Branch 0 taken 5385 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 5385 times.
✓ Branch 5 taken 5385 times.
✗ Branch 6 not taken.
|
5385 | ok = ok && addProvidedRelationships(newHandles, pointersIntoWorkspace, pointersFromWorkspace); |
| 589 | } | ||
| 590 | |||
| 591 | // step 5: register initialization | ||
| 592 | 30612 | WorkspaceObjectVector newObjects; | |
| 593 |
2/2✓ Branch 5 taken 180546 times.
✓ Branch 6 taken 30612 times.
|
211158 | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { |
| 594 |
1/1✓ Branch 2 taken 180546 times.
|
180546 | ptr->setInitialized(); |
| 595 |
2/2✓ Branch 2 taken 180546 times.
✓ Branch 5 taken 180546 times.
|
180546 | newObjects.push_back(WorkspaceObject(ptr)); |
| 596 |
1/1✓ Branch 1 taken 180546 times.
|
180546 | this->progressValue.nano_emit(++i); |
| 597 | } | ||
| 598 | |||
| 599 | // step 6: check validity | ||
| 600 |
1/1✓ Branch 1 taken 30612 times.
|
30612 | StrictnessLevel level = strictnessLevel(); |
| 601 |
8/11✓ Branch 0 taken 30612 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30612 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11287 times.
✓ Branch 5 taken 19325 times.
✓ Branch 7 taken 11287 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 11287 times.
✓ Branch 12 taken 19325 times.
✓ Branch 13 taken 11287 times.
|
30612 | if (ok && driverMethod && (!collectionClone || (level == StrictnessLevel::Final))) { |
| 602 |
3/3✓ Branch 2 taken 19325 times.
✓ Branch 4 taken 10007 times.
✓ Branch 5 taken 9318 times.
|
19325 | if (objectImplPtrs.size() == numObjects()) { |
| 603 | // check whole workspace | ||
| 604 |
1/1✓ Branch 1 taken 10007 times.
|
10007 | ok = isValid(); |
| 605 | } else { | ||
| 606 | // check individual objects | ||
| 607 |
2/2✓ Branch 5 taken 10066 times.
✓ Branch 6 taken 9318 times.
|
19384 | for (const WorkspaceObject& newObject : newObjects) { |
| 608 |
3/5✓ Branch 0 taken 10066 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 10066 times.
✓ Branch 5 taken 10066 times.
✗ Branch 6 not taken.
|
10066 | ok = ok && newObject.isValid(level); |
| 609 |
4/13✓ Branch 1 taken 10066 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10066 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 10066 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 10066 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
10066 | if ((level > StrictnessLevel::Draft) && (newObject.iddObject().properties().unique)) { |
| 610 | ✗ | ok = ok && (numObjectsOfType(newObject.iddObject().type()) == 1u); | |
| 611 | } | ||
| 612 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10066 times.
|
10066 | if (!ok) { |
| 613 | ✗ | break; | |
| 614 | } | ||
| 615 | } | ||
| 616 | } | ||
| 617 | } | ||
| 618 | |||
| 619 | // step 7: rollback if necessary | ||
| 620 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30612 times.
|
30612 | if (!ok) { |
| 621 | ✗ | LOG(Info, "Unable to add cloned objects to Workspace. The validity report is: " << '\n' << validityReport()); | |
| 622 | ✗ | nominallyRemoveObjects(newHandles); // no validity check | |
| 623 | ✗ | for (WorkspaceObject_ImplPtr& ptr : objectImplPtrs) { | |
| 624 | ✗ | ptr->disconnect(); | |
| 625 | } | ||
| 626 | ✗ | newObjects.clear(); | |
| 627 | ✗ | return newObjects; | |
| 628 | } | ||
| 629 | |||
| 630 | // step 8: emit signals for successful completion | ||
| 631 |
1/2✓ Branch 0 taken 30612 times.
✗ Branch 1 not taken.
|
30612 | if (driverMethod) { |
| 632 |
2/2✓ Branch 5 taken 180546 times.
✓ Branch 6 taken 30612 times.
|
211158 | for (const WorkspaceObject& newObject : newObjects) { |
| 633 |
1/1✓ Branch 1 taken 180546 times.
|
180546 | registerAdditionOfObject(newObject); |
| 634 | } | ||
| 635 | } | ||
| 636 | |||
| 637 | 30612 | return newObjects; | |
| 638 | 30612 | } | |
| 639 | |||
| 640 | 1713 | boost::optional<WorkspaceObject> Workspace_Impl::addObject(const IdfObject& idfObject) { | |
| 641 | 1713 | WorkspaceObject_ImplPtr objectImplPtr; | |
| 642 | |||
| 643 | // handle potential name conflicts up front | ||
| 644 |
1/1✓ Branch 1 taken 1713 times.
|
1713 | IdfObject workingIdfObject = idfObject; // shallow copy |
| 645 |
4/4✓ Branch 1 taken 1713 times.
✓ Branch 4 taken 1713 times.
✓ Branch 7 taken 1525 times.
✓ Branch 8 taken 188 times.
|
1713 | if (idfObject.iddObject().hasNameField()) { |
| 646 |
1/1✓ Branch 1 taken 1525 times.
|
1525 | OptionalString currentName = idfObject.name(); |
| 647 |
6/7✓ Branch 0 taken 1525 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1525 times.
✓ Branch 6 taken 315 times.
✓ Branch 7 taken 1210 times.
✓ Branch 8 taken 315 times.
✓ Branch 9 taken 1210 times.
|
1525 | if (currentName && !currentName->empty()) { |
| 648 |
4/4✓ Branch 1 taken 315 times.
✓ Branch 4 taken 315 times.
✓ Branch 7 taken 315 times.
✓ Branch 10 taken 315 times.
|
315 | bool potentialConflict = potentialNameConflict(idfObject.name().get(), idfObject.iddObject()); |
| 649 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 314 times.
|
315 | if (potentialConflict) { |
| 650 |
8/8✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
|
1 | LOG(Info, "Resetting name of " << idfObject.briefDescription() << " to avoid name conflict upon adding it to the Workspace."); |
| 651 |
1/1✓ Branch 1 taken 1 time.
|
1 | workingIdfObject = idfObject.clone(); // deep copy |
| 652 | // clear name of single object--WorkspaceObject_Impl constructor will make new one | ||
| 653 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | bool ok = workingIdfObject.setName("").has_value(); |
| 654 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
|
1 | OS_ASSERT(ok); |
| 655 | } | ||
| 656 | } | ||
| 657 | 1525 | } | |
| 658 | // create new object | ||
| 659 |
1/1✓ Branch 1 taken 1713 times.
|
1713 | objectImplPtr = this->createObject(workingIdfObject, false); |
| 660 | |||
| 661 | // add to workspace | ||
| 662 |
1/1✓ Branch 1 taken 1713 times.
|
1713 | WorkspaceObject_ImplPtrVector objectImplPtrs(1u, objectImplPtr); |
| 663 |
1/1✓ Branch 1 taken 1713 times.
|
1713 | WorkspaceObjectVector objects = addObjects(objectImplPtrs, false); |
| 664 | |||
| 665 | // assess result and return | ||
| 666 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1713 times.
|
1713 | if (objects.size() != 1) { |
| 667 | ✗ | OS_ASSERT(objects.empty()); | |
| 668 | ✗ | return boost::none; | |
| 669 | } | ||
| 670 |
1/1✓ Branch 2 taken 1713 times.
|
1713 | return objects[0]; |
| 671 | 1713 | } | |
| 672 | |||
| 673 | ✗ | boost::optional<WorkspaceObject> Workspace_Impl::insertObject(const IdfObject& idfObject) { | |
| 674 | ✗ | OptionalWorkspaceObject result = getEquivalentObject(idfObject); | |
| 675 | ✗ | if (!result) { | |
| 676 | ✗ | result = addObject(idfObject); | |
| 677 | } | ||
| 678 | ✗ | return result; | |
| 679 | ✗ | } | |
| 680 | |||
| 681 | 955 | std::vector<WorkspaceObject> Workspace_Impl::addObjects(const std::vector<IdfObject>& idfObjects, bool checkNames) { | |
| 682 | 955 | WorkspaceObjectVector result; | |
| 683 | 955 | WorkspaceObject_ImplPtrVector newObjects; | |
| 684 | |||
| 685 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 953 times.
|
955 | if (idfObjects.empty()) { |
| 686 | 2 | return result; | |
| 687 | } | ||
| 688 | |||
| 689 |
2/2✓ Branch 2 taken 953 times.
✓ Branch 5 taken 953 times.
|
953 | bool keepHandles = idfObjects[0].iddObject().hasHandleField(); |
| 690 | |||
| 691 | 953 | bool checkedForNameConflicts(false); | |
| 692 |
3/3✓ Branch 1 taken 953 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 946 times.
|
953 | if (numObjects() > 0) { |
| 693 | // handle potential name conflicts | ||
| 694 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 5 taken 7 times.
|
7 | Workspace working = this->cloneSubset(HandleVector()); // empty clone |
| 695 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 5 taken 7 times.
|
7 | working.order().setDirectOrder(HandleVector()); // maintain order in vector |
| 696 | // call method like this one, but simpler, which expects to lose outward pointers | ||
| 697 |
1/1✓ Branch 3 taken 7 times.
|
7 | WorkspaceObjectVector wsObjects = working.getImpl<detail::Workspace_Impl>()->simpleAddObjects(idfObjects); |
| 698 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
|
7 | if (wsObjects.size() != idfObjects.size()) { |
| 699 | ✗ | LOG(Error, "Unable to add idfObjects to their own Workspace as an intermediate step."); | |
| 700 | ✗ | return {}; | |
| 701 | } | ||
| 702 |
1/1✓ Branch 1 taken 7 times.
|
7 | bool changes = resolvePotentialNameConflicts(working); |
| 703 | 7 | checkedForNameConflicts = true; | |
| 704 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (changes) { |
| 705 | // merge data and create objects | ||
| 706 | 3 | auto it(idfObjects.begin()); | |
| 707 | 3 | auto itEnd(idfObjects.end()); | |
| 708 |
2/2✓ Branch 5 taken 9 times.
✓ Branch 6 taken 3 times.
|
12 | for (const WorkspaceObject& object : wsObjects) { |
| 709 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
|
9 | OS_ASSERT(it != itEnd); |
| 710 |
1/1✓ Branch 1 taken 9 times.
|
9 | IdfObject mergedObject = object.idfObject(); |
| 711 |
1/1✓ Branch 2 taken 9 times.
|
9 | mergeIdfObjectAfterPotentialNameConflictResolution(mergedObject, *it); |
| 712 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | newObjects.push_back(this->createObject(mergedObject, keepHandles)); |
| 713 | 9 | ++it; | |
| 714 | 9 | } | |
| 715 | // add objects | ||
| 716 |
1/1✓ Branch 1 taken 3 times.
|
3 | result = addObjects(newObjects, checkNames); |
| 717 | 3 | return result; | |
| 718 | } | ||
| 719 | 10 | } | |
| 720 | |||
| 721 | // no name conflicts---directly create and add objects | ||
| 722 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 950 times.
✗ Branch 4 not taken.
|
950 | OS_ASSERT(newObjects.empty()); |
| 723 | 950 | auto it(idfObjects.begin()); | |
| 724 | 950 | auto itEnd(idfObjects.end()); | |
| 725 |
2/2✓ Branch 1 taken 53089 times.
✓ Branch 2 taken 950 times.
|
54039 | for (; it != itEnd; ++it) { |
| 726 |
2/2✓ Branch 2 taken 53089 times.
✓ Branch 5 taken 53089 times.
|
53089 | newObjects.push_back(this->createObject(*it, keepHandles)); |
| 727 | } | ||
| 728 |
1/1✓ Branch 1 taken 950 times.
|
950 | result = addObjects(newObjects, checkNames); |
| 729 |
2/2✓ Branch 0 taken 946 times.
✓ Branch 1 taken 4 times.
|
950 | if (!checkedForNameConflicts) { |
| 730 |
1/1✓ Branch 1 taken 946 times.
|
946 | Workspace thisWorkspace = workspace(); |
| 731 |
1/1✓ Branch 1 taken 946 times.
|
946 | resolvePotentialNameConflicts(thisWorkspace); |
| 732 | 946 | } | |
| 733 | |||
| 734 | 950 | return result; | |
| 735 | 955 | } | |
| 736 | |||
| 737 | 4 | std::vector<WorkspaceObject> Workspace_Impl::insertObjects(const IdfObjectVector& idfObjects) { | |
| 738 |
1/1✓ Branch 2 taken 4 times.
|
4 | return addAndInsertObjects(IdfObjectVector(), idfObjects); |
| 739 | } | ||
| 740 | |||
| 741 | 5 | std::vector<WorkspaceObject> Workspace_Impl::addAndInsertObjects(const std::vector<IdfObject>& objectsToAdd, | |
| 742 | const std::vector<IdfObject>& objectsToInsert) { | ||
| 743 | // merge objects into one vector | ||
| 744 | 5 | unsigned nAdd = objectsToAdd.size(); | |
| 745 | 5 | unsigned nInsert = objectsToInsert.size(); | |
| 746 | 5 | unsigned n = nAdd + nInsert; | |
| 747 |
1/1✓ Branch 1 taken 5 times.
|
5 | IdfObjectVector idfObjects = objectsToAdd; |
| 748 |
1/1✓ Branch 5 taken 5 times.
|
5 | idfObjects.insert(idfObjects.end(), objectsToInsert.begin(), objectsToInsert.end()); |
| 749 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
|
5 | OS_ASSERT(idfObjects.size() == n); |
| 750 | |||
| 751 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (idfObjects.empty()) { |
| 752 | ✗ | return {}; | |
| 753 | } | ||
| 754 | |||
| 755 |
2/2✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
|
5 | bool keepHandles = idfObjects[0].iddObject().hasHandleField(); |
| 756 | |||
| 757 | // find equivalent objects for objectsToInsert | ||
| 758 | 5 | UnsignedVector foundObjectIndices; | |
| 759 | 5 | UnsignedVector notFoundObjectIndices; | |
| 760 | 5 | WorkspaceObjectVector equivalentObjects; | |
| 761 | 5 | unsigned i = nAdd; | |
| 762 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 5 times.
|
19 | for (unsigned i = nAdd, n = idfObjects.size(); i < n; ++i) { |
| 763 |
1/1✓ Branch 2 taken 14 times.
|
14 | OptionalWorkspaceObject oEquivalent = getEquivalentObject(idfObjects[i]); |
| 764 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | if (oEquivalent) { |
| 765 |
1/1✓ Branch 1 taken 7 times.
|
7 | foundObjectIndices.push_back(i); |
| 766 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | equivalentObjects.push_back(*oEquivalent); |
| 767 | } else { | ||
| 768 |
1/1✓ Branch 1 taken 7 times.
|
7 | notFoundObjectIndices.push_back(i); |
| 769 | } | ||
| 770 | 14 | } | |
| 771 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 5 not taken.
|
5 | OS_ASSERT(foundObjectIndices.size() + notFoundObjectIndices.size() == nInsert); |
| 772 | |||
| 773 | // handle potential name conflicts. only objects to be added need attention. | ||
| 774 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 5 taken 5 times.
|
5 | Workspace working = this->cloneSubset(HandleVector()); // empty clone |
| 775 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 5 taken 5 times.
|
5 | working.order().setDirectOrder(HandleVector()); // maintain order in vector |
| 776 |
1/1✓ Branch 1 taken 5 times.
|
5 | WorkspaceObjectVector wsObjects = working.addObjects(idfObjects, false); |
| 777 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (wsObjects.size() != idfObjects.size()) { |
| 778 | ✗ | LOG(Error, "Unable to add idfObjects to their own Workspace as an intermediate step."); | |
| 779 | ✗ | return {}; | |
| 780 | } | ||
| 781 |
1/1✓ Branch 1 taken 5 times.
|
5 | bool changes = resolvePotentialNameConflicts(working, foundObjectIndices); |
| 782 | |||
| 783 | // create objects while handling the mess we have made above | ||
| 784 | 5 | WorkspaceObject_ImplPtrVector newObjects; // objects to be added | |
| 785 | 5 | HUPointerVector pointersFromWorkspace; // workspace object -> object to be added | |
| 786 | 5 | HHPointerVector pointersToRollBackOnFail; // workspace object -> workspace object pointers | |
| 787 | // directly added by this method | ||
| 788 | 5 | i = 0; // step through all of the objects | |
| 789 | 5 | auto equivIt = equivalentObjects.begin(); | |
| 790 | 5 | auto foundIndicesBegin = foundObjectIndices.begin(); | |
| 791 | 5 | auto foundIndicesEnd = foundObjectIndices.end(); | |
| 792 | // loop through Workspace versions of idfObjects | ||
| 793 |
2/2✓ Branch 4 taken 15 times.
✓ Branch 5 taken 5 times.
|
20 | for (const WorkspaceObject& object : wsObjects) { |
| 794 |
3/3✓ Branch 1 taken 15 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 7 times.
|
15 | if (std::find(foundIndicesBegin, foundIndicesEnd, i) == foundIndicesEnd) { |
| 795 | // no equivalent object in workspace -- create new object to add | ||
| 796 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 time.
|
8 | if (changes) { |
| 797 |
1/1✓ Branch 1 taken 7 times.
|
7 | IdfObject mergedObject = object.idfObject(); |
| 798 |
1/1✓ Branch 2 taken 7 times.
|
7 | mergeIdfObjectAfterPotentialNameConflictResolution(mergedObject, idfObjects[i]); |
| 799 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | newObjects.push_back(this->createObject(mergedObject, keepHandles)); |
| 800 | 7 | } else { | |
| 801 |
2/2✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
|
1 | newObjects.push_back(this->createObject(idfObjects[i], keepHandles)); |
| 802 | } | ||
| 803 | } else { | ||
| 804 | // there is an equivalent object in workspace | ||
| 805 |
4/6✓ Branch 1 taken 7 times.
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 7 times.
✗ Branch 13 not taken.
|
7 | OS_ASSERT(equivIt->iddObject() == object.iddObject()); |
| 806 | // preserve idfObject[i] -> idfObject[j] | ||
| 807 |
1/1✓ Branch 1 taken 7 times.
|
7 | WorkspaceObjectVector targets = object.targets(); |
| 808 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 7 times.
|
11 | for (const WorkspaceObject& target : targets) { |
| 809 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | OptionalUnsigned targetIndexInWorking = working.order().indexInOrder(target.handle()); |
| 810 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
|
4 | OS_ASSERT(targetIndexInWorking); |
| 811 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | UnsignedVector fieldIndicesObjectToTarget = object.getSourceIndices(target.handle()); |
| 812 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
|
4 | OS_ASSERT(!fieldIndicesObjectToTarget.empty()); |
| 813 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | auto targetInFoundObjectsIt = std::find(foundIndicesBegin, foundIndicesEnd, *targetIndexInWorking); |
| 814 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (targetInFoundObjectsIt == foundIndicesEnd) { |
| 815 | // target has no equivalent in this Workspace | ||
| 816 | // get index target will have in newObjects vector | ||
| 817 | ✗ | unsigned newObjectsIndexOfTarget(0); | |
| 818 | ✗ | if (*targetIndexInWorking < nAdd) { | |
| 819 | ✗ | newObjectsIndexOfTarget = *targetIndexInWorking; | |
| 820 | } else { | ||
| 821 | ✗ | auto targetInNotFoundObjectsIt = std::find(notFoundObjectIndices.begin(), notFoundObjectIndices.end(), *targetIndexInWorking); | |
| 822 | ✗ | OS_ASSERT(targetInNotFoundObjectsIt != notFoundObjectIndices.end()); | |
| 823 | ✗ | newObjectsIndexOfTarget = nAdd + static_cast<unsigned>(targetInNotFoundObjectsIt - notFoundObjectIndices.begin()); | |
| 824 | } | ||
| 825 | ✗ | for (unsigned index : fieldIndicesObjectToTarget) { | |
| 826 | ✗ | pointersFromWorkspace.push_back(HUPointer(equivIt->handle(), index, newObjectsIndexOfTarget)); | |
| 827 | } | ||
| 828 | } else { | ||
| 829 | // target has equivalent in this Workspace. make sure pointer is there or add it. | ||
| 830 | 4 | auto targetIndexInEquivalentObjects = static_cast<unsigned>(targetInFoundObjectsIt - foundIndicesBegin); | |
| 831 |
1/1✓ Branch 2 taken 4 times.
|
4 | WorkspaceObject equivalentTarget = equivalentObjects[targetIndexInEquivalentObjects]; |
| 832 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
|
4 | UnsignedVector fieldIndicesFoundObjectToFoundTarget = equivIt->getSourceIndices(equivalentTarget.handle()); |
| 833 |
2/2✓ Branch 5 taken 6 times.
✓ Branch 6 taken 4 times.
|
10 | for (unsigned index : fieldIndicesObjectToTarget) { |
| 834 |
1/1✓ Branch 3 taken 6 times.
|
6 | if (std::find(fieldIndicesFoundObjectToFoundTarget.begin(), fieldIndicesFoundObjectToFoundTarget.end(), index) |
| 835 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 | == fieldIndicesFoundObjectToFoundTarget.end()) { |
| 836 | ✗ | OS_ASSERT(!(equivIt->getTarget(index))); | |
| 837 | ✗ | bool ok = equivIt->setPointer(index, equivalentTarget.handle()); | |
| 838 | ✗ | if (ok) { | |
| 839 | ✗ | pointersToRollBackOnFail.push_back(HHPointer(equivIt->handle(), index, equivalentTarget.handle())); | |
| 840 | } else { | ||
| 841 | ✗ | LOG(Warn, "Unable to move pointer from " << object.briefDescription() << " to " << target.briefDescription() << " from field " | |
| 842 | << index << " over to equivalent objects " << equivIt->briefDescription() << " and " | ||
| 843 | << equivalentTarget.briefDescription() << ", respectively, already in Workspace."); | ||
| 844 | } | ||
| 845 | } | ||
| 846 | } | ||
| 847 | 4 | } // if (target does not have an equivalent) else | |
| 848 | 4 | } // for each target of an object that has an equivalent | |
| 849 | 7 | ++equivIt; | |
| 850 | 7 | } // if (object does not have an equivalent) else | |
| 851 | 15 | ++i; | |
| 852 | } // for each object | ||
| 853 | |||
| 854 | // add objects | ||
| 855 |
1/1✓ Branch 2 taken 5 times.
|
5 | WorkspaceObjectVector addedObjects = addObjects(newObjects, UHPointerVector(), pointersFromWorkspace); |
| 856 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (addedObjects.size() != newObjects.size()) { |
| 857 | ✗ | for (const HHPointer& ptr : pointersToRollBackOnFail) { | |
| 858 | ✗ | OptionalWorkspaceObject oSource = getObject(ptr.source); | |
| 859 | ✗ | OS_ASSERT(oSource); | |
| 860 | ✗ | oSource->setPointer(ptr.fieldIndex, Handle()); | |
| 861 | ✗ | } | |
| 862 | ✗ | return {}; | |
| 863 | } | ||
| 864 | |||
| 865 | // successful, make result vector | ||
| 866 | 5 | WorkspaceObjectVector result; | |
| 867 | 5 | auto addedIt = addedObjects.begin(); | |
| 868 | 5 | equivIt = equivalentObjects.begin(); | |
| 869 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 5 not taken.
|
5 | OS_ASSERT(addedObjects.size() + equivalentObjects.size() == n); |
| 870 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 5 times.
|
20 | for (unsigned i = 0; i < n; ++i) { |
| 871 |
3/3✓ Branch 1 taken 15 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 7 times.
|
15 | if (std::find(foundIndicesBegin, foundIndicesEnd, i) == foundIndicesEnd) { |
| 872 | // no equivalent--added | ||
| 873 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 5 not taken.
|
8 | OS_ASSERT(addedIt != addedObjects.end()); |
| 874 |
1/1✓ Branch 2 taken 8 times.
|
8 | result.push_back(*addedIt); |
| 875 | 8 | ++addedIt; | |
| 876 | } else { | ||
| 877 | // equivalent | ||
| 878 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 5 not taken.
|
7 | OS_ASSERT(equivIt != equivalentObjects.end()); |
| 879 |
1/1✓ Branch 2 taken 7 times.
|
7 | result.push_back(*equivIt); |
| 880 | 7 | ++equivIt; | |
| 881 | } | ||
| 882 | } | ||
| 883 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 5 not taken.
|
5 | OS_ASSERT(addedIt == addedObjects.end()); |
| 884 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 5 not taken.
|
5 | OS_ASSERT(equivIt == equivalentObjects.end()); |
| 885 | |||
| 886 | 5 | return result; | |
| 887 | 5 | } | |
| 888 | |||
| 889 | 9673 | std::vector<WorkspaceObject> Workspace_Impl::addObjects(const std::vector<WorkspaceObject>& objects, bool /*checkNames*/) { | |
| 890 | 9673 | WorkspaceObjectVector result; | |
| 891 | 9673 | WorkspaceObject_ImplPtrVector newObjects; | |
| 892 | 9673 | HandleMap oldNewHandleMap; | |
| 893 | 9673 | UHPointerVector pointersIntoWorkspace; | |
| 894 | |||
| 895 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9673 times.
|
9673 | if (objects.empty()) { |
| 896 | ✗ | return result; | |
| 897 | } | ||
| 898 | |||
| 899 |
3/3✓ Branch 1 taken 9673 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 9671 times.
|
9673 | if (numObjects() > 0) { |
| 900 | |||
| 901 | // handle potential name conflicts | ||
| 902 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | Workspace working = this->cloneSubset(HandleVector()); // empty clone |
| 903 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | working.order().setDirectOrder(HandleVector()); // maintain order in vector |
| 904 |
1/1✓ Branch 1 taken 2 times.
|
2 | WorkspaceObjectVector wsObjects = working.addObjects(objects, false); // recursive call |
| 905 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (wsObjects.size() != objects.size()) { |
| 906 | ✗ | LOG(Error, "Unable to add objects to their own Workspace as an intermediate step."); | |
| 907 | ✗ | return result; | |
| 908 | } | ||
| 909 |
1/1✓ Branch 1 taken 2 times.
|
2 | bool changes = resolvePotentialNameConflicts(working); |
| 910 | |||
| 911 | // create new objects, and keep track of outward pointers if | ||
| 912 | // objects[0].workspace() == workspace() | ||
| 913 | 2 | bool sameWorkspace = false; | |
| 914 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
2 | if (objects[0].workspace() == this->workspace()) { |
| 915 | ✗ | sameWorkspace = true; | |
| 916 | ✗ | OS_ASSERT(changes); | |
| 917 | } | ||
| 918 | 2 | unsigned i(0); | |
| 919 |
2/2✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
|
8 | for (const WorkspaceObject& wsObject : wsObjects) { |
| 920 |
2/2✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
|
6 | newObjects.push_back(this->createObject(wsObject.getImpl<WorkspaceObject_Impl>(), false)); |
| 921 |
3/3✓ Branch 3 taken 6 times.
✓ Branch 6 taken 6 times.
✓ Branch 10 taken 6 times.
|
6 | oldNewHandleMap.insert(HandleMap::value_type(wsObject.handle(), newObjects.back()->handle())); |
| 922 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (sameWorkspace) { |
| 923 | ✗ | WorkspaceObjectVector objectTargets = objects[i].targets(); | |
| 924 | ✗ | for (const WorkspaceObject& target : objectTargets) { | |
| 925 | ✗ | if (std::find(objects.begin(), objects.end(), target) == objects.end()) { | |
| 926 | ✗ | UnsignedVector fieldIndices = objects[i].getSourceIndices(target.handle()); | |
| 927 | ✗ | for (unsigned index : fieldIndices) { | |
| 928 | ✗ | pointersIntoWorkspace.push_back(UHPointer(i, index, target.handle())); | |
| 929 | } | ||
| 930 | ✗ | } | |
| 931 | } | ||
| 932 | ✗ | } | |
| 933 | 6 | ++i; | |
| 934 | } | ||
| 935 | |||
| 936 |
1/1✓ Branch 2 taken 2 times.
|
2 | result = addClones(newObjects, oldNewHandleMap, false, pointersIntoWorkspace); |
| 937 | 2 | return result; | |
| 938 | 2 | } | |
| 939 | |||
| 940 | // blank Workspace---directly create and add objects | ||
| 941 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9671 times.
✗ Branch 4 not taken.
|
9671 | OS_ASSERT(newObjects.empty()); |
| 942 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9671 times.
✗ Branch 4 not taken.
|
9671 | OS_ASSERT(oldNewHandleMap.empty()); |
| 943 | 9671 | [[maybe_unused]] unsigned i = 0; | |
| 944 |
2/2✓ Branch 4 taken 12993 times.
✓ Branch 5 taken 9671 times.
|
22664 | for (const WorkspaceObject& object : objects) { |
| 945 |
2/2✓ Branch 2 taken 12993 times.
✓ Branch 5 taken 12993 times.
|
12993 | newObjects.push_back(this->createObject(object.getImpl<WorkspaceObject_Impl>(), false)); |
| 946 |
3/3✓ Branch 3 taken 12993 times.
✓ Branch 6 taken 12993 times.
✓ Branch 10 taken 12993 times.
|
12993 | oldNewHandleMap.insert(HandleMap::value_type(object.handle(), newObjects.back()->handle())); |
| 947 | 12993 | ++i; | |
| 948 | } | ||
| 949 |
1/1✓ Branch 3 taken 9671 times.
|
9671 | result = addClones(newObjects, oldNewHandleMap, false); |
| 950 | |||
| 951 | 9671 | return result; | |
| 952 | 9673 | } | |
| 953 | |||
| 954 | 1 | std::vector<WorkspaceObject> Workspace_Impl::insertObjects(const std::vector<WorkspaceObject>& objects) { | |
| 955 |
1/1✓ Branch 2 taken 1 time.
|
1 | return addAndInsertObjects(WorkspaceObjectVector(), objects); |
| 956 | } | ||
| 957 | |||
| 958 | 8152 | std::vector<WorkspaceObject> Workspace_Impl::addAndInsertObjects(const std::vector<WorkspaceObject>& objectsToAdd, | |
| 959 | const std::vector<WorkspaceObject>& objectsToInsert) { | ||
| 960 | // merge objects into one vector | ||
| 961 | 8152 | unsigned nAdd = objectsToAdd.size(); | |
| 962 | 8152 | unsigned nInsert = objectsToInsert.size(); | |
| 963 | 8152 | unsigned n = nAdd + nInsert; | |
| 964 |
1/1✓ Branch 1 taken 8152 times.
|
8152 | WorkspaceObjectVector allObjects = objectsToAdd; |
| 965 |
1/1✓ Branch 5 taken 8152 times.
|
8152 | allObjects.insert(allObjects.end(), objectsToInsert.begin(), objectsToInsert.end()); |
| 966 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 8152 times.
✗ Branch 4 not taken.
|
8152 | OS_ASSERT(allObjects.size() == n); |
| 967 | |||
| 968 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8152 times.
|
8152 | if (allObjects.empty()) { |
| 969 | ✗ | return {}; | |
| 970 | } | ||
| 971 | |||
| 972 | // find equivalent objects for objectsToInsert | ||
| 973 | 8152 | UnsignedVector foundObjectIndices; | |
| 974 | 8152 | UnsignedVector notFoundObjectIndices; | |
| 975 | 8152 | WorkspaceObjectVector equivalentObjects; | |
| 976 |
2/2✓ Branch 1 taken 1897 times.
✓ Branch 2 taken 8152 times.
|
10049 | for (unsigned i = nAdd, n = allObjects.size(); i < n; ++i) { |
| 977 |
1/1✓ Branch 2 taken 1897 times.
|
1897 | OptionalWorkspaceObject oEquivalent = getEquivalentObject(allObjects[i]); |
| 978 |
2/2✓ Branch 0 taken 1895 times.
✓ Branch 1 taken 2 times.
|
1897 | if (oEquivalent) { |
| 979 |
1/1✓ Branch 1 taken 1895 times.
|
1895 | foundObjectIndices.push_back(i); |
| 980 |
2/2✓ Branch 1 taken 1895 times.
✓ Branch 4 taken 1895 times.
|
1895 | equivalentObjects.push_back(*oEquivalent); |
| 981 | } else { | ||
| 982 |
1/1✓ Branch 1 taken 2 times.
|
2 | notFoundObjectIndices.push_back(i); |
| 983 | } | ||
| 984 | 1897 | } | |
| 985 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 8152 times.
✗ Branch 5 not taken.
|
8152 | OS_ASSERT(foundObjectIndices.size() + notFoundObjectIndices.size() == nInsert); |
| 986 | |||
| 987 |
1/1✓ Branch 1 taken 8152 times.
|
8152 | return addAndInsertObjects(allObjects, foundObjectIndices, notFoundObjectIndices, equivalentObjects); |
| 988 | 8152 | } | |
| 989 | |||
| 990 | 1500 | std::vector<WorkspaceObject> Workspace_Impl::addAndInsertObjects(const std::vector<WorkspaceObject>& objectsToAdd, | |
| 991 | const std::vector<std::vector<WorkspaceObject>>& objectsToInsert) { | ||
| 992 | 1500 | UnsignedVector foundObjectIndices; | |
| 993 | 1500 | UnsignedVector notFoundObjectIndices; | |
| 994 | 1500 | WorkspaceObjectVector equivalentObjects; | |
| 995 | |||
| 996 | // merge objects into one vector and find equivalent objects for objectsToInsert | ||
| 997 | 1500 | unsigned nAdd = objectsToAdd.size(); | |
| 998 |
1/1✓ Branch 1 taken 1500 times.
|
1500 | WorkspaceObjectVector allObjects = objectsToAdd; |
| 999 | 1500 | unsigned i(nAdd); | |
| 1000 | 1500 | unsigned nInsert(0); | |
| 1001 |
2/2✓ Branch 5 taken 743 times.
✓ Branch 6 taken 1500 times.
|
2243 | for (const std::vector<WorkspaceObject>& group : objectsToInsert) { |
| 1002 | 743 | UnsignedVector groupIndices; | |
| 1003 | 743 | WorkspaceObjectVector tempEquivalents; | |
| 1004 |
2/2✓ Branch 5 taken 812 times.
✓ Branch 6 taken 743 times.
|
1555 | for (const WorkspaceObject& object : group) { |
| 1005 |
1/1✓ Branch 1 taken 812 times.
|
812 | groupIndices.push_back(i); |
| 1006 |
1/1✓ Branch 1 taken 812 times.
|
812 | allObjects.push_back(object); |
| 1007 |
1/1✓ Branch 2 taken 812 times.
|
812 | OptionalWorkspaceObject oEquivalent = getEquivalentObject(allObjects[i]); |
| 1008 |
2/2✓ Branch 0 taken 172 times.
✓ Branch 1 taken 640 times.
|
812 | if (oEquivalent) { |
| 1009 |
2/2✓ Branch 1 taken 172 times.
✓ Branch 4 taken 172 times.
|
172 | tempEquivalents.push_back(*oEquivalent); |
| 1010 | } | ||
| 1011 | 812 | ++i; | |
| 1012 | 812 | } | |
| 1013 | 743 | nInsert += groupIndices.size(); | |
| 1014 |
2/2✓ Branch 2 taken 168 times.
✓ Branch 3 taken 575 times.
|
743 | if (tempEquivalents.size() == groupIndices.size()) { |
| 1015 | // all have equivalents | ||
| 1016 |
1/1✓ Branch 5 taken 168 times.
|
168 | foundObjectIndices.insert(foundObjectIndices.end(), groupIndices.begin(), groupIndices.end()); |
| 1017 |
1/1✓ Branch 5 taken 168 times.
|
168 | equivalentObjects.insert(equivalentObjects.end(), tempEquivalents.begin(), tempEquivalents.end()); |
| 1018 | } else { | ||
| 1019 |
1/1✓ Branch 5 taken 575 times.
|
575 | notFoundObjectIndices.insert(notFoundObjectIndices.end(), groupIndices.begin(), groupIndices.end()); |
| 1020 | } | ||
| 1021 | 743 | } | |
| 1022 | |||
| 1023 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1500 times.
✗ Branch 4 not taken.
|
1500 | OS_ASSERT(allObjects.size() == nAdd + nInsert); |
| 1024 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1500 times.
✗ Branch 5 not taken.
|
1500 | OS_ASSERT(foundObjectIndices.size() + notFoundObjectIndices.size() == nInsert); |
| 1025 | |||
| 1026 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1500 times.
|
1500 | if (allObjects.empty()) { |
| 1027 | ✗ | return {}; | |
| 1028 | } | ||
| 1029 | |||
| 1030 |
1/1✓ Branch 1 taken 1500 times.
|
1500 | return addAndInsertObjects(allObjects, foundObjectIndices, notFoundObjectIndices, equivalentObjects); |
| 1031 | 1500 | } | |
| 1032 | |||
| 1033 | 9652 | std::vector<WorkspaceObject> Workspace_Impl::addAndInsertObjects(const std::vector<WorkspaceObject>& allObjects, | |
| 1034 | const std::vector<unsigned>& foundObjectIndices, | ||
| 1035 | const std::vector<unsigned>& notFoundObjectIndices, | ||
| 1036 | std::vector<WorkspaceObject>& equivalentObjects) { | ||
| 1037 | 9652 | WorkspaceObjectVector result; | |
| 1038 | 9652 | WorkspaceObject_ImplPtrVector newObjects; | |
| 1039 | 9652 | HandleMap oldNewHandleMap; | |
| 1040 | 9652 | UHPointerVector pointersIntoWorkspace; | |
| 1041 | 9652 | HUPointerVector pointersFromWorkspace; | |
| 1042 | |||
| 1043 | 9652 | unsigned n = allObjects.size(); | |
| 1044 | 9652 | unsigned nInsert = foundObjectIndices.size() + notFoundObjectIndices.size(); | |
| 1045 | 9652 | unsigned nAdd = n - nInsert; | |
| 1046 | |||
| 1047 | // handle potential name conflicts. only objects to be added need attention. | ||
| 1048 |
2/2✓ Branch 1 taken 9652 times.
✓ Branch 5 taken 9652 times.
|
9652 | Workspace working = this->cloneSubset(HandleVector()); // empty clone |
| 1049 |
2/2✓ Branch 1 taken 9652 times.
✓ Branch 5 taken 9652 times.
|
9652 | working.order().setDirectOrder(HandleVector()); // maintain order in vector |
| 1050 |
1/1✓ Branch 1 taken 9652 times.
|
9652 | WorkspaceObjectVector wsObjects = working.addObjects(allObjects, false); |
| 1051 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9652 times.
|
9652 | if (wsObjects.size() != allObjects.size()) { |
| 1052 | ✗ | LOG(Error, "Unable to add objectsToAdd and objectsToInsert to their own Workspace as an " << "intermediate step."); | |
| 1053 | ✗ | return result; | |
| 1054 | } | ||
| 1055 |
1/1✓ Branch 1 taken 9652 times.
|
9652 | resolvePotentialNameConflicts(working, foundObjectIndices); |
| 1056 | |||
| 1057 | // create objects while handling the mess we have made above | ||
| 1058 | 9652 | HHPointerVector pointersToRollBackOnFail; // workspace object -> workspace object pointers | |
| 1059 | // directly added by this method | ||
| 1060 | 9652 | unsigned i = 0; // step through all of the objects | |
| 1061 | 9652 | unsigned j = 0; // index for new objects | |
| 1062 | 9652 | auto equivIt = equivalentObjects.begin(); | |
| 1063 | 9652 | auto foundIndicesBegin = foundObjectIndices.begin(); | |
| 1064 | 9652 | auto foundIndicesEnd = foundObjectIndices.end(); | |
| 1065 | // keep track of outward pointers if objects[0].workspace() == workspace() | ||
| 1066 | 9652 | bool sameWorkspace = false; | |
| 1067 |
5/5✓ Branch 1 taken 9652 times.
✓ Branch 5 taken 9652 times.
✓ Branch 8 taken 9652 times.
✓ Branch 12 taken 8151 times.
✓ Branch 13 taken 1501 times.
|
9652 | if (allObjects[0].workspace() == this->workspace()) { |
| 1068 | 8151 | sameWorkspace = true; | |
| 1069 | } | ||
| 1070 | // loop through working versions of allObjects | ||
| 1071 |
2/2✓ Branch 4 taken 12916 times.
✓ Branch 5 taken 9652 times.
|
22568 | for (const WorkspaceObject& object : wsObjects) { |
| 1072 |
3/3✓ Branch 1 taken 12916 times.
✓ Branch 4 taken 10850 times.
✓ Branch 5 taken 2066 times.
|
12916 | if (std::find(foundIndicesBegin, foundIndicesEnd, i) == foundIndicesEnd) { |
| 1073 | // no equivalent object in workspace, create new object | ||
| 1074 |
2/2✓ Branch 2 taken 10850 times.
✓ Branch 5 taken 10850 times.
|
10850 | newObjects.push_back(this->createObject(object.getImpl<detail::WorkspaceObject_Impl>(), false)); |
| 1075 |
3/3✓ Branch 3 taken 10850 times.
✓ Branch 6 taken 10850 times.
✓ Branch 10 taken 10850 times.
|
10850 | oldNewHandleMap.insert(HandleMap::value_type(object.handle(), newObjects.back()->handle())); |
| 1076 |
1/1✓ Branch 1 taken 10850 times.
|
10850 | WorkspaceObjectVector objectTargets = object.targets(); |
| 1077 | // preserve pointers to equivalent objects | ||
| 1078 |
2/2✓ Branch 5 taken 3342 times.
✓ Branch 6 taken 10850 times.
|
14192 | for (const WorkspaceObject& target : objectTargets) { |
| 1079 |
3/3✓ Branch 1 taken 3342 times.
✓ Branch 4 taken 3342 times.
✓ Branch 7 taken 3342 times.
|
3342 | OptionalUnsigned targetIndexInWorking = working.order().indexInOrder(target.handle()); |
| 1080 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 3342 times.
✗ Branch 4 not taken.
|
3342 | OS_ASSERT(targetIndexInWorking); |
| 1081 |
2/2✓ Branch 1 taken 3342 times.
✓ Branch 4 taken 3342 times.
|
3342 | auto targetInFoundObjectsIt = std::find(foundIndicesBegin, foundIndicesEnd, *targetIndexInWorking); |
| 1082 |
2/2✓ Branch 1 taken 2068 times.
✓ Branch 2 taken 1274 times.
|
3342 | if (targetInFoundObjectsIt != foundIndicesEnd) { |
| 1083 | // set pointer(s) to equivalent object | ||
| 1084 |
2/2✓ Branch 1 taken 2068 times.
✓ Branch 4 taken 2068 times.
|
2068 | UnsignedVector fieldIndicesObjectToTarget = object.getSourceIndices(target.handle()); |
| 1085 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2068 times.
✗ Branch 4 not taken.
|
2068 | OS_ASSERT(!fieldIndicesObjectToTarget.empty()); |
| 1086 | 2068 | auto targetIndexInEquivalentObjects = static_cast<unsigned>(targetInFoundObjectsIt - foundIndicesBegin); | |
| 1087 |
1/1✓ Branch 2 taken 2068 times.
|
2068 | WorkspaceObject equivalentTarget = equivalentObjects[targetIndexInEquivalentObjects]; |
| 1088 |
2/2✓ Branch 4 taken 2294 times.
✓ Branch 5 taken 2068 times.
|
4362 | for (unsigned index : fieldIndicesObjectToTarget) { |
| 1089 |
2/2✓ Branch 1 taken 2294 times.
✓ Branch 5 taken 2294 times.
|
2294 | pointersIntoWorkspace.push_back(UHPointer(j, index, equivalentTarget.handle())); |
| 1090 | } | ||
| 1091 | 2068 | } | |
| 1092 | } | ||
| 1093 |
2/2✓ Branch 0 taken 8153 times.
✓ Branch 1 taken 2697 times.
|
10850 | if (sameWorkspace) { |
| 1094 | // preserve external targets too | ||
| 1095 |
1/1✓ Branch 2 taken 8153 times.
|
8153 | objectTargets = allObjects[i].targets(); |
| 1096 |
2/2✓ Branch 5 taken 7150 times.
✓ Branch 6 taken 8153 times.
|
15303 | for (const WorkspaceObject& target : objectTargets) { |
| 1097 |
3/3✓ Branch 4 taken 7150 times.
✓ Branch 7 taken 5193 times.
✓ Branch 8 taken 1957 times.
|
7150 | if (std::find(allObjects.begin(), allObjects.end(), target) == allObjects.end()) { |
| 1098 |
2/2✓ Branch 2 taken 5193 times.
✓ Branch 5 taken 5193 times.
|
5193 | UnsignedVector fieldIndices = allObjects[i].getSourceIndices(target.handle()); |
| 1099 |
2/2✓ Branch 4 taken 5207 times.
✓ Branch 5 taken 5193 times.
|
10400 | for (unsigned index : fieldIndices) { |
| 1100 |
2/2✓ Branch 1 taken 5207 times.
✓ Branch 5 taken 5207 times.
|
5207 | pointersIntoWorkspace.push_back(UHPointer(j, index, target.handle())); |
| 1101 | } | ||
| 1102 | 5193 | } | |
| 1103 | } | ||
| 1104 | } | ||
| 1105 | 10850 | ++j; | |
| 1106 | 10850 | } else { | |
| 1107 | // there is an equivalent object in workspace | ||
| 1108 |
4/6✓ Branch 1 taken 2066 times.
✓ Branch 5 taken 2066 times.
✓ Branch 8 taken 2066 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2066 times.
✗ Branch 13 not taken.
|
2066 | OS_ASSERT(equivIt->iddObject() == object.iddObject()); |
| 1109 | // preserve idfObject[i] -> idfObject[j] | ||
| 1110 |
1/1✓ Branch 1 taken 2066 times.
|
2066 | WorkspaceObjectVector targets = object.targets(); |
| 1111 |
2/2✓ Branch 5 taken 63 times.
✓ Branch 6 taken 2066 times.
|
2129 | for (const WorkspaceObject& target : targets) { |
| 1112 |
3/3✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
✓ Branch 7 taken 63 times.
|
63 | OptionalUnsigned targetIndexInWorking = working.order().indexInOrder(target.handle()); |
| 1113 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✗ Branch 4 not taken.
|
63 | OS_ASSERT(targetIndexInWorking); |
| 1114 |
2/2✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
|
63 | UnsignedVector fieldIndicesObjectToTarget = object.getSourceIndices(target.handle()); |
| 1115 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✗ Branch 4 not taken.
|
63 | OS_ASSERT(!fieldIndicesObjectToTarget.empty()); |
| 1116 |
2/2✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
|
63 | auto targetInFoundObjectsIt = std::find(foundIndicesBegin, foundIndicesEnd, *targetIndexInWorking); |
| 1117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
|
63 | if (targetInFoundObjectsIt == foundIndicesEnd) { |
| 1118 | // target has no equivalent in this Workspace | ||
| 1119 | // get index target will have in newObjects vector | ||
| 1120 | ✗ | unsigned newObjectsIndexOfTarget(0); | |
| 1121 | ✗ | if (*targetIndexInWorking < nAdd) { | |
| 1122 | ✗ | newObjectsIndexOfTarget = *targetIndexInWorking; | |
| 1123 | } else { | ||
| 1124 | ✗ | auto targetInNotFoundObjectsIt = std::find(notFoundObjectIndices.begin(), notFoundObjectIndices.end(), *targetIndexInWorking); | |
| 1125 | ✗ | OS_ASSERT(targetInNotFoundObjectsIt != notFoundObjectIndices.end()); | |
| 1126 | ✗ | newObjectsIndexOfTarget = nAdd + static_cast<unsigned>(targetInNotFoundObjectsIt - notFoundObjectIndices.begin()); | |
| 1127 | } | ||
| 1128 | ✗ | for (unsigned index : fieldIndicesObjectToTarget) { | |
| 1129 | ✗ | pointersFromWorkspace.push_back(HUPointer(equivIt->handle(), index, newObjectsIndexOfTarget)); | |
| 1130 | } | ||
| 1131 | } else { | ||
| 1132 | // target has equivalent in this Workspace. make sure pointer is there or add it. | ||
| 1133 | 63 | auto targetIndexInEquivalentObjects = static_cast<unsigned>(targetInFoundObjectsIt - foundIndicesBegin); | |
| 1134 |
1/1✓ Branch 2 taken 63 times.
|
63 | WorkspaceObject equivalentTarget = equivalentObjects[targetIndexInEquivalentObjects]; |
| 1135 |
2/2✓ Branch 2 taken 63 times.
✓ Branch 5 taken 63 times.
|
63 | UnsignedVector fieldIndicesFoundObjectToFoundTarget = equivIt->getSourceIndices(equivalentTarget.handle()); |
| 1136 |
2/2✓ Branch 5 taken 63 times.
✓ Branch 6 taken 63 times.
|
126 | for (unsigned index : fieldIndicesObjectToTarget) { |
| 1137 |
1/1✓ Branch 3 taken 63 times.
|
63 | if (std::find(fieldIndicesFoundObjectToFoundTarget.begin(), fieldIndicesFoundObjectToFoundTarget.end(), index) |
| 1138 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
|
126 | == fieldIndicesFoundObjectToFoundTarget.end()) { |
| 1139 | ✗ | OS_ASSERT(!(equivIt->getTarget(index))); | |
| 1140 | ✗ | bool ok = equivIt->setPointer(index, equivalentTarget.handle()); | |
| 1141 | ✗ | if (ok) { | |
| 1142 | ✗ | pointersToRollBackOnFail.push_back(HHPointer(equivIt->handle(), index, equivalentTarget.handle())); | |
| 1143 | } else { | ||
| 1144 | ✗ | LOG(Warn, "Unable to move pointer from " << object.briefDescription() << " to " << target.briefDescription() << " from field " | |
| 1145 | << index << " over to equivalent objects " << equivIt->briefDescription() << " and " | ||
| 1146 | << equivalentTarget.briefDescription() << ", respectively, already in Workspace."); | ||
| 1147 | } | ||
| 1148 | } | ||
| 1149 | } | ||
| 1150 | 63 | } // if (target does not have an equivalent) else | |
| 1151 | 63 | } // for each target of an object that has an equivalent | |
| 1152 | 2066 | ++equivIt; | |
| 1153 | 2066 | } // if (object does not have an equivalent) else | |
| 1154 | 12916 | ++i; | |
| 1155 | } // for each object | ||
| 1156 | |||
| 1157 | // add objects | ||
| 1158 |
1/1✓ Branch 1 taken 9652 times.
|
9652 | WorkspaceObjectVector addedObjects = addClones(newObjects, oldNewHandleMap, false, pointersIntoWorkspace, pointersFromWorkspace); |
| 1159 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9652 times.
|
9652 | if (addedObjects.size() != newObjects.size()) { |
| 1160 | ✗ | for (const HHPointer& ptr : pointersToRollBackOnFail) { | |
| 1161 | ✗ | OptionalWorkspaceObject oSource = getObject(ptr.source); | |
| 1162 | ✗ | OS_ASSERT(oSource); | |
| 1163 | ✗ | oSource->setPointer(ptr.fieldIndex, Handle()); | |
| 1164 | ✗ | } | |
| 1165 | ✗ | return result; | |
| 1166 | } | ||
| 1167 | |||
| 1168 | // successful, make result vector | ||
| 1169 | 9652 | auto addedIt = addedObjects.begin(); | |
| 1170 | 9652 | equivIt = equivalentObjects.begin(); | |
| 1171 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9652 times.
✗ Branch 5 not taken.
|
9652 | OS_ASSERT(addedObjects.size() + equivalentObjects.size() == unsigned(n)); |
| 1172 |
2/2✓ Branch 0 taken 12916 times.
✓ Branch 1 taken 9652 times.
|
22568 | for (unsigned i = 0; i < n; ++i) { |
| 1173 |
3/3✓ Branch 1 taken 12916 times.
✓ Branch 4 taken 10850 times.
✓ Branch 5 taken 2066 times.
|
12916 | if (std::find(foundIndicesBegin, foundIndicesEnd, i) == foundIndicesEnd) { |
| 1174 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 10850 times.
✗ Branch 5 not taken.
|
10850 | OS_ASSERT(addedIt != addedObjects.end()); |
| 1175 |
1/1✓ Branch 2 taken 10850 times.
|
10850 | result.push_back(*addedIt); |
| 1176 | 10850 | ++addedIt; | |
| 1177 | } else { | ||
| 1178 | // equivalent | ||
| 1179 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 2066 times.
✗ Branch 5 not taken.
|
2066 | OS_ASSERT(equivIt != equivalentObjects.end()); |
| 1180 |
1/1✓ Branch 2 taken 2066 times.
|
2066 | result.push_back(*equivIt); |
| 1181 | 2066 | ++equivIt; | |
| 1182 | } | ||
| 1183 | } | ||
| 1184 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9652 times.
✗ Branch 5 not taken.
|
9652 | OS_ASSERT(addedIt == addedObjects.end()); |
| 1185 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9652 times.
✗ Branch 5 not taken.
|
9652 | OS_ASSERT(equivIt == equivalentObjects.end()); |
| 1186 | |||
| 1187 | 9652 | return result; | |
| 1188 | 9652 | } | |
| 1189 | |||
| 1190 | 93 | bool Workspace_Impl::swap(WorkspaceObject& currentObject, IdfObject& newObject, bool keepTargets) { | |
| 1191 | // make sure currentObject is in workspace | ||
| 1192 |
3/4✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 93 times.
|
93 | if (!isMember(currentObject.handle())) { |
| 1193 | ✗ | LOG(Info, "Unable to swap objects because WorkspaceObject is not in this Workspace."); | |
| 1194 | ✗ | return false; | |
| 1195 | } | ||
| 1196 | |||
| 1197 |
1/1✓ Branch 1 taken 93 times.
|
93 | std::stringstream ss; // placeholder for information common to all log messages |
| 1198 |
2/2✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
|
279 | ss << "The WorkspaceObject is of type " << currentObject.iddObject().name() << ", and the IdfObject is of type " << newObject.iddObject().name() |
| 1199 |
7/7✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
✓ Branch 10 taken 93 times.
✓ Branch 13 taken 93 times.
✓ Branch 16 taken 93 times.
✓ Branch 19 taken 93 times.
|
279 | << "."; |
| 1200 | |||
| 1201 |
2/2✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
|
93 | StringVector curRefs = currentObject.iddObject().references(); |
| 1202 |
2/2✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
|
93 | StringVector newRefs = newObject.iddObject().references(); |
| 1203 |
5/6✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
✓ Branch 10 taken 93 times.
✓ Branch 15 taken 93 times.
✗ Branch 16 not taken.
|
93 | if (currentObject.iddObject().type() != newObject.iddObject().type()) { |
| 1204 | // make sure there is some overlap in references | ||
| 1205 |
1/1✓ Branch 1 taken 93 times.
|
93 | StringVector intersection = intersectReferenceLists(curRefs, newRefs); |
| 1206 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
|
93 | if (intersection.empty()) { |
| 1207 | ✗ | LOG(Info, "Unable to swap objects because the two objects' reference lists have an empty " << "intersection. " << ss.str()); | |
| 1208 | ✗ | return false; | |
| 1209 | } | ||
| 1210 | 93 | } | |
| 1211 | |||
| 1212 | // place newObject in its own workspace | ||
| 1213 |
2/2✓ Branch 1 taken 93 times.
✓ Branch 5 taken 93 times.
|
93 | Workspace working = this->cloneSubset(HandleVector()); |
| 1214 |
1/1✓ Branch 1 taken 93 times.
|
93 | OptionalWorkspaceObject newObjectInWS = working.addObject(newObject); |
| 1215 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
|
93 | if (!newObjectInWS) { |
| 1216 | ✗ | return false; | |
| 1217 | } | ||
| 1218 | |||
| 1219 | // rename newObject if necessary | ||
| 1220 |
2/2✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
|
93 | OptionalString newObjectName = newObjectInWS->name(); |
| 1221 |
1/1✓ Branch 1 taken 93 times.
|
93 | OptionalString currentObjectName = currentObject.name(); |
| 1222 |
1/2✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
|
93 | if (newObjectName) { |
| 1223 | // placing in workspace will provide name | ||
| 1224 |
2/4✓ Branch 1 taken 93 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 93 times.
✗ Branch 7 not taken.
|
93 | OS_ASSERT(!(newObjectName->empty())); |
| 1225 | // okay if name same as originalObject | ||
| 1226 |
8/9✓ Branch 1 taken 93 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
✓ Branch 10 taken 93 times.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 88 times.
✓ Branch 14 taken 5 times.
✓ Branch 15 taken 88 times.
|
93 | if (!currentObjectName || (!istringEqual(*newObjectName, *currentObjectName))) { |
| 1227 |
6/6✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 3 times.
|
5 | if (potentialNameConflict(*newObjectName, newObjectInWS->iddObject())) { |
| 1228 |
6/6✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
|
2 | OptionalString ok = newObjectInWS->setName(nextName(newObjectInWS->iddObject().type(), false)); |
| 1229 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
|
2 | OS_ASSERT(ok); |
| 1230 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 20 taken 2 times.
✓ Branch 23 taken 2 times.
✓ Branch 26 taken 2 times.
|
2 | LOG(Info, "Renaming " << newObject.briefDescription() << " during swap operation to " << "avoid name conflict."); |
| 1231 | 2 | } | |
| 1232 | } | ||
| 1233 | } | ||
| 1234 | |||
| 1235 | // check each source to see if pointer can be repointed | ||
| 1236 | // and accumulate information for doing the swap | ||
| 1237 | 93 | HUPointerVector sources; // from workspace | |
| 1238 |
3/3✓ Branch 1 taken 93 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 93 times.
|
133 | for (const WorkspaceObject& source : currentObject.sources()) { |
| 1239 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
|
40 | UnsignedVector indices = source.getSourceIndices(currentObject.handle()); |
| 1240 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 4 not taken.
|
40 | OS_ASSERT(!indices.empty()); |
| 1241 |
2/2✓ Branch 4 taken 40 times.
✓ Branch 5 taken 40 times.
|
80 | for (unsigned index : indices) { |
| 1242 |
2/3✓ Branch 1 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
|
40 | if (!source.canBeSource(index, newRefs)) { |
| 1243 | ✗ | LOG(Info, "Unable to swap objects because one of the WorkspaceObject's sources, which is " | |
| 1244 | << "of type " << source.iddObject().name() << ", cannot point to the IdfObject from " << "field " << index << ". " << ss.str()); | ||
| 1245 | ✗ | return false; | |
| 1246 | } | ||
| 1247 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 5 taken 40 times.
|
40 | sources.push_back(HUPointer(source.handle(), index, 0)); |
| 1248 | } | ||
| 1249 | 133 | } | |
| 1250 | |||
| 1251 | // construct targets for newObject | ||
| 1252 | 93 | UHPointerVector targets; // into workspace | |
| 1253 | 93 | UnsignedSet spokenFor; // maintain uniqueness of newObject pointers | |
| 1254 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (keepTargets) { |
| 1255 | // first try to pull currentObject targets over | ||
| 1256 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 2 times.
|
12 | for (unsigned index : currentObject.objectListFields()) { |
| 1257 |
1/1✓ Branch 1 taken 10 times.
|
10 | OptionalWorkspaceObject owo = currentObject.getTarget(index); |
| 1258 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
|
10 | if (owo) { |
| 1259 | // newObject must be able to point to the same target | ||
| 1260 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | WorkspaceObject target = *owo; |
| 1261 |
1/1✓ Branch 1 taken 4 times.
|
4 | OptionalString targetName = target.name(); |
| 1262 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
|
4 | OS_ASSERT(targetName); |
| 1263 | // loop through candidate fields | ||
| 1264 | 4 | bool found = false; | |
| 1265 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 2 times.
|
14 | for (unsigned i : newObject.objectListFields()) { |
| 1266 |
2/3✓ Branch 2 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
|
12 | if (spokenFor.find(i) != spokenFor.end()) { |
| 1267 | ✗ | continue; | |
| 1268 | } | ||
| 1269 | // data null or equal to *targetName? | ||
| 1270 |
1/1✓ Branch 1 taken 12 times.
|
12 | OptionalString newField = newObject.getString(i); |
| 1271 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 4 not taken.
|
12 | OS_ASSERT(newField); |
| 1272 |
10/10✓ Branch 1 taken 12 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 8 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 15 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 10 times.
✓ Branch 18 taken 2 times.
|
12 | if (newField->empty() || istringEqual(*newField, *targetName)) { |
| 1273 | // object lists and target references have non-empty intersection? | ||
| 1274 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | OptionalIddField newOLIdd = newObject.iddObject().getField(i); |
| 1275 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 4 not taken.
|
10 | OS_ASSERT(newOLIdd); |
| 1276 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | StringVector tRefs = target.iddObject().references(); |
| 1277 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
|
10 | StringVector newObjLists = newOLIdd->properties().objectLists; |
| 1278 |
1/1✓ Branch 1 taken 10 times.
|
10 | StringVector intersection = intersectReferenceLists(tRefs, newObjLists); |
| 1279 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
|
10 | if (!intersection.empty()) { |
| 1280 | // save target data | ||
| 1281 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | targets.push_back(UHPointer(0, i, target.handle())); |
| 1282 | 2 | found = true; | |
| 1283 |
1/1✓ Branch 1 taken 2 times.
|
2 | spokenFor.insert(i); |
| 1284 | 2 | break; | |
| 1285 | } | ||
| 1286 | 16 | } | |
| 1287 | 16 | } // for each newObject.objectListFields() | |
| 1288 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (!found) { |
| 1289 |
19/19✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 31 taken 2 times.
✓ Branch 34 taken 2 times.
✓ Branch 37 taken 2 times.
✓ Branch 40 taken 2 times.
✓ Branch 43 taken 2 times.
✓ Branch 46 taken 2 times.
✓ Branch 52 taken 2 times.
✓ Branch 55 taken 2 times.
✓ Branch 58 taken 2 times.
|
2 | LOG(Info, "Unable to swap objects because the IdfObject cannot be made to point to one of " |
| 1290 | << "the WorkspaceObject's targets, which is of type " << target.iddObject().name() << " and named '" << *targetName << "'. " | ||
| 1291 | << ss.str() << " The IdfObject in question " << "is:" << '\n' | ||
| 1292 | << newObject); | ||
| 1293 | 2 | return false; | |
| 1294 | } | ||
| 1295 | 6 | } // if non-null target | |
| 1296 | 14 | } // for each currentObject.objectListFields() | |
| 1297 | } // if keepTargets | ||
| 1298 | |||
| 1299 |
3/3✓ Branch 1 taken 91 times.
✓ Branch 8 taken 299 times.
✓ Branch 9 taken 91 times.
|
390 | for (unsigned i : newObject.objectListFields()) { |
| 1300 | // if not spoken for ... | ||
| 1301 |
3/3✓ Branch 4 taken 299 times.
✓ Branch 7 taken 297 times.
✓ Branch 8 taken 2 times.
|
299 | if (std::find(spokenFor.begin(), spokenFor.end(), i) == spokenFor.end()) { |
| 1302 | // ... try to find target in workspace | ||
| 1303 |
1/1✓ Branch 1 taken 297 times.
|
297 | OptionalString targetName = newObject.getString(i); |
| 1304 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 297 times.
✗ Branch 4 not taken.
|
297 | OS_ASSERT(targetName); |
| 1305 |
2/2✓ Branch 1 taken 297 times.
✓ Branch 4 taken 297 times.
|
297 | OptionalIddField iddField = newObject.iddObject().getField(i); |
| 1306 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 297 times.
✗ Branch 4 not taken.
|
297 | OS_ASSERT(iddField); |
| 1307 |
4/4✓ Branch 1 taken 297 times.
✓ Branch 4 taken 297 times.
✓ Branch 7 taken 297 times.
✓ Branch 10 taken 297 times.
|
297 | OptionalWorkspaceObject oTarget = getObjectByNameAndReference(*targetName, iddField->properties().objectLists); |
| 1308 |
2/2✓ Branch 0 taken 149 times.
✓ Branch 1 taken 148 times.
|
297 | if (oTarget) { |
| 1309 |
3/3✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
✓ Branch 8 taken 149 times.
|
149 | targets.push_back(UHPointer(0, i, oTarget->handle())); |
| 1310 | } | ||
| 1311 | 297 | } | |
| 1312 | 91 | } | |
| 1313 | |||
| 1314 | // compatible--try to add newObject | ||
| 1315 | 91 | WorkspaceObject_ImplPtrVector newObjectPtrs; | |
| 1316 |
2/4✓ Branch 1 taken 91 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 91 times.
✗ Branch 6 not taken.
|
91 | OS_ASSERT(working.numObjects() == 1); |
| 1317 |
3/3✓ Branch 1 taken 91 times.
✓ Branch 6 taken 91 times.
✓ Branch 9 taken 91 times.
|
91 | newObjectPtrs.push_back(this->createObject(working.objects()[0].getImpl<WorkspaceObject_Impl>(), false)); |
| 1318 |
1/1✓ Branch 1 taken 91 times.
|
91 | WorkspaceObjectVector addResult = Workspace_Impl::addObjects(newObjectPtrs, targets, sources, false); |
| 1319 |
1/2✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
|
91 | if (!addResult.empty()) { |
| 1320 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✗ Branch 4 not taken.
|
91 | OS_ASSERT(addResult.size() == 1); |
| 1321 | // successful add, prepare to swap data by preserving current object | ||
| 1322 |
1/1✓ Branch 1 taken 91 times.
|
91 | IdfObject idfCurrentObject = currentObject.idfObject(); |
| 1323 | // preserve order if directOrder | ||
| 1324 |
3/4✓ Branch 1 taken 91 times.
✓ Branch 4 taken 91 times.
✓ Branch 7 taken 91 times.
✗ Branch 8 not taken.
|
91 | if (order().isDirectOrder()) { |
| 1325 |
3/3✓ Branch 1 taken 91 times.
✓ Branch 4 taken 91 times.
✓ Branch 7 taken 91 times.
|
91 | OptionalUnsigned position = order().indexInOrder(currentObject.handle()); |
| 1326 |
1/2✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
|
91 | if (position) { |
| 1327 |
4/4✓ Branch 1 taken 91 times.
✓ Branch 4 taken 91 times.
✓ Branch 8 taken 91 times.
✓ Branch 11 taken 91 times.
|
91 | order().move(addResult[0].handle(), *position); |
| 1328 | } | ||
| 1329 | } | ||
| 1330 | // try to remove old workspace object | ||
| 1331 |
2/2✓ Branch 1 taken 91 times.
✓ Branch 4 taken 91 times.
|
91 | bool ok = removeObject(currentObject.handle()); // checks validity and emits remove signal |
| 1332 |
1/2✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
|
91 | if (ok) { |
| 1333 |
1/1✓ Branch 2 taken 91 times.
|
91 | currentObject = addResult[0]; |
| 1334 |
1/1✓ Branch 1 taken 91 times.
|
91 | newObject = idfCurrentObject; |
| 1335 | // recover original name if new and current names were same | ||
| 1336 |
9/11✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 91 times.
✓ Branch 8 taken 91 times.
✓ Branch 11 taken 91 times.
✓ Branch 13 taken 88 times.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 88 times.
✓ Branch 16 taken 3 times.
|
182 | if (newObjectName && currentObjectName && (istringEqual(*newObjectName, *currentObjectName))) { |
| 1337 |
14/14✓ Branch 1 taken 88 times.
✓ Branch 4 taken 88 times.
✓ Branch 7 taken 88 times.
✓ Branch 10 taken 88 times.
✓ Branch 13 taken 88 times.
✓ Branch 16 taken 88 times.
✓ Branch 19 taken 88 times.
✓ Branch 22 taken 88 times.
✓ Branch 25 taken 88 times.
✓ Branch 28 taken 88 times.
✓ Branch 31 taken 88 times.
✓ Branch 36 taken 88 times.
✓ Branch 39 taken 88 times.
✓ Branch 42 taken 88 times.
|
88 | LOG(Info, "Restoring original name, '" << *newObjectName << "' of " << currentObject.briefDescription() << " after a successful swap with " |
| 1338 | << newObject.briefDescription() << "."); | ||
| 1339 |
2/2✓ Branch 3 taken 88 times.
✓ Branch 6 taken 88 times.
|
88 | ok = currentObject.getImpl<WorkspaceObject_Impl>()->setName(*newObjectName, false).has_value(); |
| 1340 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
✗ Branch 3 not taken.
|
88 | OS_ASSERT(ok); |
| 1341 | } | ||
| 1342 | // handle add signals | ||
| 1343 |
1/1✓ Branch 2 taken 91 times.
|
91 | registerAdditionOfObject(addResult[0]); |
| 1344 | 91 | return true; | |
| 1345 | } | ||
| 1346 | ✗ | LOG(Info, "Unable to swap objects because the removal of the WorkspaceObject, " << '\n' << idfCurrentObject << '\n' << ", was unsuccessful."); | |
| 1347 | // remove new object | ||
| 1348 | ✗ | nominallyRemoveObject(addResult[0].handle()); | |
| 1349 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
|
91 | } else { |
| 1350 | ✗ | LOG(Info, "Unable to swap objects because the addition of the IdfObject, " << '\n' | |
| 1351 | << newObject << '\n' | ||
| 1352 | << ", was unsuccessful. In addition to the object itself, " | ||
| 1353 | << "there were " << sources.size() << " pointers to the object, and " | ||
| 1354 | << targets.size() << "pointers from the object to set."); | ||
| 1355 | } | ||
| 1356 | |||
| 1357 | // reset source pointers | ||
| 1358 | ✗ | for (HUPointer sourcePtr : sources) { | |
| 1359 | ✗ | OptionalWorkspaceObject source = getObject(sourcePtr.source); | |
| 1360 | ✗ | OS_ASSERT(source); | |
| 1361 | ✗ | source->getImpl<WorkspaceObject_Impl>()->setPointer(sourcePtr.fieldIndex, currentObject.handle(), false); | |
| 1362 | ✗ | } | |
| 1363 | |||
| 1364 | ✗ | return false; | |
| 1365 | 93 | } | |
| 1366 | |||
| 1367 | 6239 | bool Workspace_Impl::removeObject(const Handle& handle) { | |
| 1368 | |||
| 1369 |
1/1✓ Branch 1 taken 6239 times.
|
6239 | OptionalSavedWorkspaceObject objectData = savedWorkspaceObject(handle); |
| 1370 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6239 times.
|
6239 | if (!objectData) { |
| 1371 | ✗ | return true; | |
| 1372 | } // trivially satisfied | ||
| 1373 | |||
| 1374 |
5/5✓ Branch 2 taken 6239 times.
✓ Branch 5 taken 6239 times.
✓ Branch 8 taken 6239 times.
✓ Branch 12 taken 6239 times.
✓ Branch 15 taken 6239 times.
|
6239 | this->removeWorkspaceObject.nano_emit(WorkspaceObject(objectData->objectImplPtr), objectData->objectImplPtr->iddObject().type(), |
| 1375 |
2/2✓ Branch 1 taken 6239 times.
✓ Branch 4 taken 6239 times.
|
6239 | objectData->handle); |
| 1376 |
6/6✓ Branch 1 taken 6239 times.
✓ Branch 4 taken 6239 times.
✓ Branch 8 taken 6239 times.
✓ Branch 11 taken 6239 times.
✓ Branch 14 taken 6239 times.
✓ Branch 17 taken 6239 times.
|
6239 | this->removeWorkspaceObjectPtr.nano_emit(objectData->objectImplPtr, objectData->objectImplPtr->iddObject().type(), objectData->handle); |
| 1377 | |||
| 1378 | // actual work of removing from maps--is always successful | ||
| 1379 |
1/1✓ Branch 1 taken 6239 times.
|
6239 | WorkspaceObjectVector sources = nominallyRemoveObject(handle); |
| 1380 | |||
| 1381 | // can only be invalid if removal results in null and required | ||
| 1382 |
3/8✓ Branch 1 taken 6239 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6239 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 6239 times.
✗ Branch 12 not taken.
|
6239 | if ((m_strictnessLevel < StrictnessLevel::Final) || isValid()) { |
| 1383 |
1/1✓ Branch 1 taken 6239 times.
|
6239 | std::vector<Handle> removedHandles(1, handle); |
| 1384 |
2/2✓ Branch 1 taken 6239 times.
✓ Branch 5 taken 6239 times.
|
6239 | registerRemovalOfObject(objectData->objectImplPtr, sources, removedHandles); |
| 1385 |
1/1✓ Branch 1 taken 6239 times.
|
6239 | this->onChange.nano_emit(); |
| 1386 | 6239 | return true; | |
| 1387 | 6239 | } else { | |
| 1388 | ✗ | restoreObject(*objectData); | |
| 1389 | ✗ | return false; | |
| 1390 | } | ||
| 1391 | 6239 | } | |
| 1392 | |||
| 1393 | 1791 | bool Workspace_Impl::removeObjects(const std::vector<Handle>& handles) { | |
| 1394 | |||
| 1395 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1790 times.
|
1791 | if (handles.empty()) { |
| 1396 | 1 | return true; | |
| 1397 | } | ||
| 1398 | |||
| 1399 | 1790 | SavedWorkspaceObjectVector objectData; | |
| 1400 |
2/2✓ Branch 5 taken 3720 times.
✓ Branch 6 taken 1790 times.
|
5510 | for (const Handle& handle : handles) { |
| 1401 |
1/1✓ Branch 1 taken 3720 times.
|
3720 | OptionalSavedWorkspaceObject candidate = savedWorkspaceObject(handle); |
| 1402 |
1/2✓ Branch 0 taken 3720 times.
✗ Branch 1 not taken.
|
3720 | if (candidate) { |
| 1403 |
2/2✓ Branch 1 taken 3720 times.
✓ Branch 4 taken 3720 times.
|
3720 | objectData.push_back(*candidate); |
| 1404 | } | ||
| 1405 | 3720 | } | |
| 1406 | |||
| 1407 |
2/2✓ Branch 6 taken 3720 times.
✓ Branch 7 taken 1790 times.
|
5510 | for (SavedWorkspaceObject savedObject : objectData) { |
| 1408 |
4/4✓ Branch 2 taken 3720 times.
✓ Branch 5 taken 3720 times.
✓ Branch 9 taken 3720 times.
✓ Branch 12 taken 3720 times.
|
3720 | this->removeWorkspaceObject.nano_emit(WorkspaceObject(savedObject.objectImplPtr), savedObject.objectImplPtr->iddObject().type(), |
| 1409 | savedObject.handle); | ||
| 1410 |
3/3✓ Branch 2 taken 3720 times.
✓ Branch 5 taken 3720 times.
✓ Branch 8 taken 3720 times.
|
3720 | this->removeWorkspaceObjectPtr.nano_emit(savedObject.objectImplPtr, savedObject.objectImplPtr->iddObject().type(), savedObject.handle); |
| 1411 | 3720 | } | |
| 1412 | |||
| 1413 | // actual work of removing from maps--is always successful | ||
| 1414 |
1/1✓ Branch 1 taken 1790 times.
|
1790 | std::vector<WorkspaceObjectVector> sources = nominallyRemoveObjects(handles); |
| 1415 | |||
| 1416 |
3/8✓ Branch 1 taken 1790 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1790 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1790 times.
✗ Branch 12 not taken.
|
1790 | if ((m_strictnessLevel < StrictnessLevel::Final) || isValid()) { |
| 1417 |
1/1✓ Branch 1 taken 1790 times.
|
1790 | registerRemovalOfObjects(objectData, sources, handles); |
| 1418 |
1/1✓ Branch 1 taken 1790 times.
|
1790 | this->onChange.nano_emit(); |
| 1419 | 1790 | return true; | |
| 1420 | } else { | ||
| 1421 | ✗ | restoreObjects(objectData); | |
| 1422 | ✗ | return false; | |
| 1423 | } | ||
| 1424 | 1790 | } | |
| 1425 | |||
| 1426 | 571778 | void Workspace_Impl::forwardReferences(const Handle& sourceHandle, unsigned index, const Handle& targetHandle) { | |
| 1427 | |||
| 1428 | // get source object | ||
| 1429 |
1/1✓ Branch 1 taken 571778 times.
|
571778 | OptionalWorkspaceObject owo = getObject(sourceHandle); |
| 1430 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 571778 times.
✗ Branch 4 not taken.
|
571778 | OS_ASSERT(owo); |
| 1431 |
2/2✓ Branch 1 taken 571778 times.
✓ Branch 4 taken 571778 times.
|
571778 | WorkspaceObject sourceObject = *owo; |
| 1432 | |||
| 1433 | // get reference lists and add targetHandle to them (ok if insert fails) | ||
| 1434 |
2/2✓ Branch 1 taken 571778 times.
✓ Branch 4 taken 571778 times.
|
571778 | OptionalIddField iddField = sourceObject.iddObject().getField(index); |
| 1435 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 571778 times.
✗ Branch 4 not taken.
|
571778 | OS_ASSERT(iddField); |
| 1436 |
4/4✓ Branch 1 taken 571778 times.
✓ Branch 4 taken 571778 times.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 571778 times.
|
571783 | for (const std::string& referenceName : iddField->properties().references) { |
| 1437 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 12 taken 5 times.
|
5 | m_idfReferencesMap[referenceName].insert(std::make_pair(targetHandle, getObject(targetHandle)->getImpl<WorkspaceObject_Impl>())); |
| 1438 | } | ||
| 1439 | 571778 | } | |
| 1440 | |||
| 1441 | 29433 | void Workspace_Impl::removeForwardedReferences(const Handle& sourceHandle, unsigned index, const WorkspaceObject& targetObject) { | |
| 1442 | // get source object | ||
| 1443 |
1/1✓ Branch 1 taken 29433 times.
|
29433 | OptionalWorkspaceObject owo = getObject(sourceHandle); |
| 1444 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29433 times.
✗ Branch 4 not taken.
|
29433 | OS_ASSERT(owo); |
| 1445 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
|
29433 | WorkspaceObject srcObj = *owo; |
| 1446 | |||
| 1447 | // only do something if references were forwarded | ||
| 1448 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
|
29433 | OptionalIddField iddField = srcObj.iddObject().getField(index); |
| 1449 |
3/4✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 29433 times.
|
29433 | if (!iddField->properties().references.empty()) { |
| 1450 | // get other source objects | ||
| 1451 | ✗ | WorkspaceObjectVector sourceObjects = targetObject.sources(); | |
| 1452 | ✗ | std::vector<UnsignedVector> sourceIndices; | |
| 1453 | // get source index for each source object | ||
| 1454 | ✗ | for (const WorkspaceObject& sourceObject : sourceObjects) { | |
| 1455 | ✗ | OS_ASSERT(sourceObject.handle() != sourceHandle); // pointer already nullified | |
| 1456 | ✗ | UnsignedVector temp = sourceObject.getSourceIndices(targetObject.handle()); | |
| 1457 | ✗ | OS_ASSERT(!temp.empty()); | |
| 1458 | ✗ | sourceIndices.push_back(temp); | |
| 1459 | ✗ | } | |
| 1460 | // loop through reference names | ||
| 1461 | ✗ | for (const std::string& referenceName : iddField->properties().references) { | |
| 1462 | // see if name is forwarded by any other source objects | ||
| 1463 | ✗ | bool found = false; | |
| 1464 | ✗ | auto indIt = sourceIndices.begin(); | |
| 1465 | ✗ | for (auto objIt = sourceObjects.begin(), objItEnd = sourceObjects.end(); objIt != objItEnd; ++objIt, ++indIt) { | |
| 1466 | ✗ | for (unsigned index : *indIt) { | |
| 1467 | ✗ | OptionalIddField sourceIddField = (*objIt).iddObject().getField(index); | |
| 1468 | ✗ | OS_ASSERT(sourceIddField); | |
| 1469 | ✗ | StringVector sourceFieldRefs = sourceIddField->properties().references; | |
| 1470 | ✗ | if (std::find_if(sourceFieldRefs.cbegin(), sourceFieldRefs.cend(), | |
| 1471 | ✗ | [&referenceName](const auto& s) { return istringEqual(s, referenceName); }) | |
| 1472 | ✗ | != sourceFieldRefs.end()) { | |
| 1473 | ✗ | found = true; | |
| 1474 | ✗ | break; | |
| 1475 | } | ||
| 1476 | ✗ | } | |
| 1477 | } | ||
| 1478 | // if not, erase the reference | ||
| 1479 | ✗ | if (!found) { | |
| 1480 | ✗ | auto it = m_idfReferencesMap[referenceName].find(targetObject.handle()); | |
| 1481 | ✗ | OS_ASSERT(it != m_idfReferencesMap[referenceName].end()); | |
| 1482 | ✗ | m_idfReferencesMap[referenceName].erase(it); | |
| 1483 | } | ||
| 1484 | } | ||
| 1485 | ✗ | } | |
| 1486 | 29433 | } | |
| 1487 | |||
| 1488 | 2386 | void Workspace_Impl::setFastNaming(bool fastNaming) { | |
| 1489 | 2386 | m_fastNaming = fastNaming; | |
| 1490 | 2386 | } | |
| 1491 | |||
| 1492 | // OBJECT ORDER | ||
| 1493 | |||
| 1494 | 23521 | WorkspaceObjectOrder Workspace_Impl::order() { | |
| 1495 | 23521 | return m_workspaceObjectOrder; | |
| 1496 | } | ||
| 1497 | |||
| 1498 | 24940 | const WorkspaceObjectOrder Workspace_Impl::order() const { | |
| 1499 | 24940 | return m_workspaceObjectOrder; | |
| 1500 | } | ||
| 1501 | |||
| 1502 | 820 | std::vector<WorkspaceObject> Workspace_Impl::sort(const std::vector<WorkspaceObject>& objects) const { | |
| 1503 | 820 | return m_workspaceObjectOrder.sort(objects); | |
| 1504 | } | ||
| 1505 | |||
| 1506 | 3 | std::vector<Handle> Workspace_Impl::sort(const std::vector<Handle>& handles) const { | |
| 1507 | 3 | return m_workspaceObjectOrder.sort(handles); | |
| 1508 | } | ||
| 1509 | |||
| 1510 | // QUERIES | ||
| 1511 | |||
| 1512 | 51357 | unsigned Workspace_Impl::numObjects() const { | |
| 1513 |
1/1✓ Branch 1 taken 51357 times.
|
51357 | return objects().size(); |
| 1514 | } | ||
| 1515 | |||
| 1516 | 179670 | unsigned Workspace_Impl::numAllObjects() const { | |
| 1517 | 179670 | return m_workspaceObjectMap.size(); | |
| 1518 | } | ||
| 1519 | |||
| 1520 | 1050 | unsigned Workspace_Impl::numObjectsOfType(IddObjectType type) const { | |
| 1521 |
1/1✓ Branch 1 taken 1050 times.
|
1050 | auto iotmLoc = m_iddObjectTypeMap.find(type); |
| 1522 |
2/2✓ Branch 2 taken 885 times.
✓ Branch 3 taken 165 times.
|
1050 | if (iotmLoc == m_iddObjectTypeMap.end()) { |
| 1523 | 885 | return 0; | |
| 1524 | } | ||
| 1525 | 165 | return iotmLoc->second.size(); | |
| 1526 | } | ||
| 1527 | |||
| 1528 | ✗ | unsigned Workspace_Impl::numObjectsOfType(const IddObject& objectType) const { | |
| 1529 | ✗ | return getObjectsByType(objectType).size(); | |
| 1530 | } | ||
| 1531 | |||
| 1532 | 517751 | bool Workspace_Impl::isMember(const Handle& handle) const { | |
| 1533 |
1/1✓ Branch 1 taken 517751 times.
|
517751 | auto womIt = m_workspaceObjectMap.find(handle); |
| 1534 | 517751 | return (womIt != m_workspaceObjectMap.end()); | |
| 1535 | } | ||
| 1536 | |||
| 1537 | 1387487 | bool Workspace_Impl::canBeTarget(const Handle& handle, const std::set<std::string>& referenceListNames) const { | |
| 1538 |
2/2✓ Branch 5 taken 1392602 times.
✓ Branch 6 taken 42 times.
|
1392644 | for (const std::string& referenceName : referenceListNames) { |
| 1539 |
4/4✓ Branch 1 taken 1392602 times.
✓ Branch 4 taken 1392602 times.
✓ Branch 7 taken 31697 times.
✓ Branch 8 taken 1360905 times.
|
2785204 | if (istringEqual(referenceName, "AllObjects")) { |
| 1540 | 1387445 | return true; | |
| 1541 | } | ||
| 1542 |
1/1✓ Branch 1 taken 1360905 times.
|
1360905 | auto irmLoc = m_idfReferencesMap.find(referenceName); |
| 1543 |
2/2✓ Branch 2 taken 1356351 times.
✓ Branch 3 taken 4554 times.
|
1360905 | if (irmLoc != m_idfReferencesMap.end()) { |
| 1544 |
1/1✓ Branch 2 taken 1356351 times.
|
1356351 | auto it = irmLoc->second.find(handle); |
| 1545 |
2/2✓ Branch 3 taken 1355748 times.
✓ Branch 4 taken 603 times.
|
1356351 | if (it != irmLoc->second.end()) { |
| 1546 | 1355748 | return true; | |
| 1547 | } | ||
| 1548 | } | ||
| 1549 | } | ||
| 1550 | 42 | return false; | |
| 1551 | } | ||
| 1552 | |||
| 1553 | ✗ | bool Workspace_Impl::isInIddFile(IddObjectType type) const { | |
| 1554 | ✗ | return m_iddFileAndFactoryWrapper.isInFile(type); | |
| 1555 | } | ||
| 1556 | |||
| 1557 | 10524 | std::string Workspace_Impl::nextName(const std::string& name, bool fillIn) const { | |
| 1558 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 10459 times.
|
10524 | if (m_fastNaming) { |
| 1559 |
2/2✓ Branch 1 taken 65 times.
✓ Branch 4 taken 65 times.
|
65 | return toString(createUUID()); |
| 1560 | } | ||
| 1561 | |||
| 1562 |
1/1✓ Branch 1 taken 10459 times.
|
10459 | WorkspaceObjectVector objectsInSeries = getObjectsByName(name, false); |
| 1563 |
1/1✓ Branch 1 taken 10459 times.
|
10459 | return constructNextName(name, objectsInSeries, fillIn); |
| 1564 | 10459 | } | |
| 1565 | |||
| 1566 | 117545 | std::string Workspace_Impl::nextName(const IddObjectType& iddObjectType, bool fillIn) const { | |
| 1567 |
2/2✓ Branch 0 taken 6178 times.
✓ Branch 1 taken 111367 times.
|
117545 | if (m_fastNaming) { |
| 1568 |
2/2✓ Branch 1 taken 6178 times.
✓ Branch 4 taken 6178 times.
|
6178 | return toString(createUUID()); |
| 1569 | } | ||
| 1570 | |||
| 1571 |
1/1✓ Branch 1 taken 111367 times.
|
111367 | OptionalIddObject iddObject = getIddObject(iddObjectType); |
| 1572 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 111357 times.
|
111367 | if (!iddObject) { |
| 1573 | 10 | return {}; | |
| 1574 | } | ||
| 1575 |
3/3✓ Branch 1 taken 111357 times.
✓ Branch 4 taken 111357 times.
✓ Branch 7 taken 111357 times.
|
111357 | std::string name = iddObjectNameToIdfObjectName(iddObject->name()); |
| 1576 |
1/1✓ Branch 1 taken 111357 times.
|
111357 | WorkspaceObjectVector objectsInSeries = getObjectsByTypeAndName(iddObjectType, name); |
| 1577 |
1/1✓ Branch 1 taken 111357 times.
|
111357 | return constructNextName(name, objectsInSeries, fillIn); |
| 1578 | 111367 | } | |
| 1579 | |||
| 1580 | 18096 | bool Workspace_Impl::isValid() const { | |
| 1581 | 18096 | return isValid(strictnessLevel()); | |
| 1582 | } | ||
| 1583 | |||
| 1584 | 18478 | bool Workspace_Impl::isValid(StrictnessLevel level) const { | |
| 1585 |
1/1✓ Branch 1 taken 18478 times.
|
18478 | ValidityReport report = validityReport(level); |
| 1586 |
1/1✓ Branch 1 taken 18478 times.
|
36956 | return (report.numErrors() == 0); |
| 1587 | 18478 | } | |
| 1588 | |||
| 1589 | 7 | ValidityReport Workspace_Impl::validityReport() const { | |
| 1590 | 7 | return validityReport(strictnessLevel()); | |
| 1591 | } | ||
| 1592 | |||
| 1593 | 18494 | ValidityReport Workspace_Impl::validityReport(StrictnessLevel level) const { | |
| 1594 |
1/1✓ Branch 1 taken 18494 times.
|
18494 | ValidityReport report(level); |
| 1595 | |||
| 1596 | 18494 | int i = 0; | |
| 1597 |
2/2✓ Branch 1 taken 18494 times.
✓ Branch 4 taken 18494 times.
|
18494 | this->progressRange.nano_emit(0, static_cast<int>(numObjects())); |
| 1598 |
1/1✓ Branch 1 taken 18494 times.
|
18494 | this->progressValue.nano_emit(i); |
| 1599 |
1/1✓ Branch 1 taken 18494 times.
|
18494 | this->progressCaption.nano_emit("Checking Validity"); |
| 1600 | |||
| 1601 | // Accumulate information about names for later name checking | ||
| 1602 | 18494 | map<string, pair<bool, std::shared_ptr<WorkspaceObject_Impl>>> mapOfNames; | |
| 1603 | 18494 | map<string, list<std::shared_ptr<WorkspaceObject_Impl>>> objectsRepeatNames; | |
| 1604 | |||
| 1605 | // StrictnessLevel::Minimal | ||
| 1606 |
3/3✓ Branch 1 taken 18494 times.
✓ Branch 4 taken 18490 times.
✓ Branch 5 taken 4 times.
|
18494 | if (level > StrictnessLevel::None) { |
| 1607 | // DataErrorType::NoIdd | ||
| 1608 | // \todo Only way there can be no IddFile is if IddFileType is set to UserCustom | ||
| 1609 | |||
| 1610 | // by-object items | ||
| 1611 |
2/2✓ Branch 5 taken 396480 times.
✓ Branch 6 taken 18490 times.
|
414970 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 1612 | |||
| 1613 | //find all objects with the same name | ||
| 1614 | |||
| 1615 |
1/1✓ Branch 2 taken 396480 times.
|
396480 | OptionalString oName = p.second->name(); |
| 1616 |
2/2✓ Branch 0 taken 317797 times.
✓ Branch 1 taken 78683 times.
|
396480 | if (oName) { |
| 1617 |
2/2✓ Branch 1 taken 317797 times.
✓ Branch 4 taken 317797 times.
|
317797 | auto itr = mapOfNames.find(*oName); |
| 1618 |
2/2✓ Branch 2 taken 434 times.
✓ Branch 3 taken 317363 times.
|
317797 | if (itr != mapOfNames.end()) { |
| 1619 | |||
| 1620 |
2/2✓ Branch 1 taken 421 times.
✓ Branch 2 taken 13 times.
|
434 | if (!itr->second.first) { |
| 1621 | 421 | itr->second.first = true; | |
| 1622 | 421 | list<std::shared_ptr<WorkspaceObject_Impl>> l; | |
| 1623 |
1/1✓ Branch 2 taken 421 times.
|
421 | l.push_front(itr->second.second); |
| 1624 |
1/1✓ Branch 1 taken 421 times.
|
421 | l.push_front(p.second); |
| 1625 |
2/2✓ Branch 2 taken 421 times.
✓ Branch 5 taken 421 times.
|
421 | objectsRepeatNames[itr->first] = l; |
| 1626 | 421 | } else { | |
| 1627 | |||
| 1628 |
1/1✓ Branch 2 taken 13 times.
|
13 | auto j = objectsRepeatNames.find(itr->first); |
| 1629 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✗ Branch 5 not taken.
|
13 | OS_ASSERT(j != objectsRepeatNames.end()); |
| 1630 |
1/1✓ Branch 2 taken 13 times.
|
13 | j->second.push_front(p.second); |
| 1631 | } | ||
| 1632 | } else { | ||
| 1633 |
2/2✓ Branch 2 taken 317363 times.
✓ Branch 5 taken 317363 times.
|
317363 | mapOfNames[*oName] = pair<bool, std::shared_ptr<WorkspaceObject_Impl>>(false, p.second); |
| 1634 | } | ||
| 1635 | } | ||
| 1636 | |||
| 1637 | // object-level report | ||
| 1638 |
1/1✓ Branch 2 taken 396480 times.
|
396480 | ValidityReport objectReport = p.second->validityReport(level, false); |
| 1639 |
1/1✓ Branch 1 taken 396480 times.
|
396480 | OptionalDataError oError = objectReport.nextError(); |
| 1640 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 396480 times.
|
793018 | while (oError) { |
| 1641 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
|
58 | report.insertError(*oError); |
| 1642 |
1/1✓ Branch 1 taken 58 times.
|
58 | oError = objectReport.nextError(); |
| 1643 | } | ||
| 1644 | |||
| 1645 | // StrictnessLevel::Draft | ||
| 1646 |
3/3✓ Branch 1 taken 396480 times.
✓ Branch 4 taken 253747 times.
✓ Branch 5 taken 142733 times.
|
396480 | if (level > StrictnessLevel::Minimal) { |
| 1647 | // DataErrorType::NoIdd | ||
| 1648 | // object-level | ||
| 1649 |
4/4✓ Branch 1 taken 253747 times.
✓ Branch 4 taken 253747 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 253743 times.
|
253747 | if (iddFileType() == IddFileType::UserCustom) { |
| 1650 |
4/5✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
|
4 | if (!m_iddFileAndFactoryWrapper.isInFile(p.second->iddObject().name())) { |
| 1651 | ✗ | report.insertError(DataError(WorkspaceObject(p.second), DataErrorType(DataErrorType::NoIdd))); | |
| 1652 | } | ||
| 1653 | } else { | ||
| 1654 |
5/5✓ Branch 2 taken 253743 times.
✓ Branch 5 taken 253743 times.
✓ Branch 8 taken 253743 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 253741 times.
|
253743 | if (!m_iddFileAndFactoryWrapper.isInFile(p.second->iddObject().type())) { |
| 1655 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
|
2 | report.insertError(DataError(WorkspaceObject(p.second), DataErrorType(DataErrorType::NoIdd))); |
| 1656 | } | ||
| 1657 | } | ||
| 1658 | } // StrictnessLevel::Draft | ||
| 1659 | |||
| 1660 |
1/1✓ Branch 1 taken 396480 times.
|
396480 | this->progressValue.nano_emit(++i); |
| 1661 | 396480 | } | |
| 1662 | } | ||
| 1663 | |||
| 1664 | // StrictnessLevel::Draft | ||
| 1665 |
3/3✓ Branch 1 taken 18494 times.
✓ Branch 4 taken 16336 times.
✓ Branch 5 taken 2158 times.
|
18494 | if (level > StrictnessLevel::Minimal) { |
| 1666 | // Check Name Conflicts | ||
| 1667 | //worst case, EVERY name is the same, EVERY object has a conflicting reference list.... this in O(n^3) | ||
| 1668 | //however, that is so unlikely its not even funny | ||
| 1669 |
2/2✓ Branch 5 taken 167 times.
✓ Branch 6 taken 16336 times.
|
16503 | for (const auto& objectsRepeatName : objectsRepeatNames) { |
| 1670 | 167 | std::shared_ptr<WorkspaceObject_Impl> obj; | |
| 1671 | 167 | list<StringVector> checkList; | |
| 1672 |
2/2✓ Branch 5 taken 337 times.
✓ Branch 6 taken 167 times.
|
504 | for (const auto& elem : objectsRepeatName.second) { |
| 1673 |
2/2✓ Branch 2 taken 337 times.
✓ Branch 5 taken 337 times.
|
337 | StringVector refs = elem->iddObject().references(); |
| 1674 |
1/1✓ Branch 1 taken 337 times.
|
337 | checkList.push_front(refs); |
| 1675 | 337 | obj = elem; | |
| 1676 | 337 | } | |
| 1677 | |||
| 1678 |
2/2✓ Branch 4 taken 337 times.
✓ Branch 5 taken 167 times.
|
504 | for (auto y = checkList.begin(), yend = checkList.end(); y != yend; ++y) { |
| 1679 | 337 | auto z = y; | |
| 1680 | 337 | auto zend = yend; | |
| 1681 | 337 | ++z; | |
| 1682 |
2/2✓ Branch 2 taken 173 times.
✓ Branch 3 taken 337 times.
|
510 | for (; z != zend; ++z) { |
| 1683 |
1/1✓ Branch 3 taken 173 times.
|
173 | StringVector intersection = intersectReferenceLists(*y, *z); |
| 1684 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 167 times.
|
173 | if (!intersection.empty()) { |
| 1685 | //obj might NOT be the object that caused the collision, but it WILL have the same name | ||
| 1686 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 5 taken 6 times.
✓ Branch 8 taken 6 times.
✓ Branch 11 taken 6 times.
|
6 | report.insertError(DataError(obj->getObject<WorkspaceObject>(), DataErrorType(DataErrorType::NameConflict))); |
| 1687 | } | ||
| 1688 | 173 | } | |
| 1689 | } | ||
| 1690 | 167 | } // for objectsRepeatedNames | |
| 1691 | } // StrictnessLevel ::Draft | ||
| 1692 | |||
| 1693 | // StrictnessLevel::Final | ||
| 1694 |
3/3✓ Branch 1 taken 18494 times.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 18477 times.
|
18494 | if (level > StrictnessLevel::Draft) { |
| 1695 | // DataErrorType::NullAndRequired | ||
| 1696 | // collection-level: required object missing | ||
| 1697 |
1/1✓ Branch 1 taken 17 times.
|
17 | IddObjectVector requiredObjects = m_iddFileAndFactoryWrapper.requiredObjects(); |
| 1698 |
2/2✓ Branch 5 taken 38 times.
✓ Branch 6 taken 17 times.
|
55 | for (const IddObject& iddObject : requiredObjects) { |
| 1699 |
4/4✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 19 times.
|
38 | if (numObjectsOfType(iddObject.type()) < 1) { |
| 1700 |
4/4✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
✓ Branch 10 taken 19 times.
|
19 | report.insertError(DataError(DataErrorType(DataErrorType::NullAndRequired), iddObject.type())); |
| 1701 | } | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | // DataErrorType::Duplicate | ||
| 1705 | // collection-level: unique object duplicated | ||
| 1706 |
1/1✓ Branch 1 taken 17 times.
|
17 | IddObjectVector uniqueObjects = m_iddFileAndFactoryWrapper.uniqueObjects(); |
| 1707 |
2/2✓ Branch 5 taken 962 times.
✓ Branch 6 taken 17 times.
|
979 | for (const IddObject& iddObject : uniqueObjects) { |
| 1708 |
3/4✓ Branch 1 taken 962 times.
✓ Branch 4 taken 962 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 962 times.
|
962 | if (numObjectsOfType(iddObject.type()) > 1) { |
| 1709 | ✗ | report.insertError(DataError(DataErrorType(DataErrorType::Duplicate), iddObject.type())); | |
| 1710 | } | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | 17 | } // StrictnessLevel::Final | |
| 1714 | |||
| 1715 | 36988 | return report; | |
| 1716 | 18494 | } | |
| 1717 | |||
| 1718 | 1744 | IdfObject Workspace_Impl::versionObjectToAdd() const { | |
| 1719 |
1/1✓ Branch 1 taken 1744 times.
|
1744 | OptionalIddObject versionIdd = m_iddFileAndFactoryWrapper.versionObject(); |
| 1720 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1744 times.
|
1744 | if (!versionIdd) { |
| 1721 | ✗ | LOG_AND_THROW("Unable to determine a Version Idd object."); | |
| 1722 | } | ||
| 1723 |
2/2✓ Branch 1 taken 1744 times.
✓ Branch 4 taken 1744 times.
|
1744 | IdfObject result(*versionIdd); |
| 1724 | // look for field named "Version Identifier" | ||
| 1725 |
3/3✓ Branch 1 taken 1744 times.
✓ Branch 4 taken 1744 times.
✓ Branch 7 taken 1744 times.
|
5232 | OptionalInt index = result.iddObject().getFieldIndex("Version Identifier"); |
| 1726 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1744 times.
|
1744 | if (!index) { |
| 1727 | ✗ | LOG(Warn, "No 'Version Identifier' field found in the Version IddObject."); | |
| 1728 | } else { | ||
| 1729 |
4/4✓ Branch 1 taken 1744 times.
✓ Branch 4 taken 1744 times.
✓ Branch 7 taken 1744 times.
✓ Branch 10 taken 1744 times.
|
1744 | result.setString(*index, version().str()); |
| 1730 | } | ||
| 1731 | 3488 | return result; | |
| 1732 | 1744 | } | |
| 1733 | |||
| 1734 | // SERIALIZATION | ||
| 1735 | |||
| 1736 | 458 | bool Workspace_Impl::save(const openstudio::path& p, bool overwrite) { | |
| 1737 |
2/2✓ Branch 1 taken 458 times.
✓ Branch 4 taken 458 times.
|
458 | return toIdfFile().save(p, overwrite); |
| 1738 | } | ||
| 1739 | |||
| 1740 | 675 | IdfFile Workspace_Impl::toIdfFile() { | |
| 1741 | |||
| 1742 |
3/3✓ Branch 1 taken 675 times.
✓ Branch 4 taken 675 times.
✓ Branch 7 taken 675 times.
|
675 | IdfFile result; |
| 1743 |
2/3✓ Branch 1 taken 675 times.
✓ Branch 3 taken 675 times.
✗ Branch 4 not taken.
|
1350 | if (OptionalIdfObject vo = result.versionObject()) { |
| 1744 |
2/2✓ Branch 1 taken 675 times.
✓ Branch 4 taken 675 times.
|
675 | result.removeObject(*vo); |
| 1745 | 675 | } | |
| 1746 | |||
| 1747 | // header | ||
| 1748 |
1/1✓ Branch 1 taken 675 times.
|
675 | result.setHeader(m_header); |
| 1749 | |||
| 1750 | // specify IddFile | ||
| 1751 |
1/1✓ Branch 1 taken 675 times.
|
675 | result.setIddFileAndFactoryWrapper(m_iddFileAndFactoryWrapper); |
| 1752 | |||
| 1753 | // add version object | ||
| 1754 |
2/3✓ Branch 1 taken 675 times.
✓ Branch 3 taken 675 times.
✗ Branch 4 not taken.
|
1350 | if (OptionalWorkspaceObject vo = versionObject()) { |
| 1755 |
3/3✓ Branch 1 taken 675 times.
✓ Branch 4 taken 675 times.
✓ Branch 7 taken 675 times.
|
675 | result.addObject(vo->idfObject()); |
| 1756 | 675 | } | |
| 1757 | |||
| 1758 | // add objects and replace handle pointers with names | ||
| 1759 |
1/1✓ Branch 1 taken 675 times.
|
675 | WorkspaceObjectVector objs = objects(true); // sorted objects |
| 1760 |
2/2✓ Branch 4 taken 166945 times.
✓ Branch 5 taken 675 times.
|
167620 | for (const WorkspaceObject& obj : objs) { |
| 1761 |
2/2✓ Branch 1 taken 166945 times.
✓ Branch 4 taken 166945 times.
|
166945 | result.addObject(obj.idfObject()); |
| 1762 | } | ||
| 1763 | |||
| 1764 | 1350 | return result; | |
| 1765 | 675 | } | |
| 1766 | |||
| 1767 | // PRIVATE | ||
| 1768 | |||
| 1769 | // GETTER HELPERS | ||
| 1770 | |||
| 1771 | ✗ | HandleVector Workspace_Impl::handles(const std::set<Handle>& handles, bool sorted) const { | |
| 1772 | ✗ | HandleVector result(handles.begin(), handles.end()); | |
| 1773 | ✗ | if (sorted) { | |
| 1774 | ✗ | result = sort(result); | |
| 1775 | } | ||
| 1776 | ✗ | return result; | |
| 1777 | ✗ | } | |
| 1778 | |||
| 1779 | 8128848 | bool Workspace_Impl::baseNamesMatch(const std::string& baseName, const std::string& objectName) const { | |
| 1780 |
2/2✓ Branch 1 taken 8128848 times.
✓ Branch 4 taken 8128848 times.
|
8128848 | return istringEqual(baseName, getBaseName(objectName)); |
| 1781 | } | ||
| 1782 | |||
| 1783 | 865341 | std::tuple<boost::optional<int>, std::string> Workspace_Impl::getNameSuffix(const std::string& objectName) const { | |
| 1784 | |||
| 1785 | 865341 | std::size_t found1 = objectName.find_last_of(' '); | |
| 1786 | 865341 | std::size_t found2 = objectName.find_last_of('_'); | |
| 1787 | 865341 | std::size_t found = string::npos; | |
| 1788 |
1/1✓ Branch 1 taken 865341 times.
|
865341 | std::string spacer = " "; |
| 1789 |
4/4✓ Branch 0 taken 862234 times.
✓ Branch 1 taken 3107 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 862194 times.
|
865341 | if (found1 != string::npos && found2 != string::npos) { |
| 1790 | 40 | found = std::max(found1, found2); | |
| 1791 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 21 times.
|
40 | if (found2 > found1) { |
| 1792 |
1/1✓ Branch 1 taken 19 times.
|
19 | spacer = "_"; |
| 1793 | } | ||
| 1794 |
2/2✓ Branch 0 taken 862194 times.
✓ Branch 1 taken 3107 times.
|
865301 | } else if (found1 != string::npos) { |
| 1795 | 862194 | found = found1; | |
| 1796 |
1/1✓ Branch 1 taken 862194 times.
|
862194 | spacer = " "; |
| 1797 |
2/2✓ Branch 0 taken 182 times.
✓ Branch 1 taken 2925 times.
|
3107 | } else if (found2 != string::npos) { |
| 1798 | 182 | found = found2; | |
| 1799 |
1/1✓ Branch 1 taken 182 times.
|
182 | spacer = "_"; |
| 1800 | } | ||
| 1801 | |||
| 1802 |
2/2✓ Branch 0 taken 862416 times.
✓ Branch 1 taken 2925 times.
|
865341 | if (found != string::npos) { |
| 1803 |
1/1✓ Branch 1 taken 862416 times.
|
862416 | std::string strSuffix = objectName.substr(found + 1); |
| 1804 | 862416 | const char* p = strSuffix.c_str(); | |
| 1805 | 862416 | int suffix = 0; | |
| 1806 | 862416 | unsigned count = 0; | |
| 1807 |
4/4✓ Branch 0 taken 1705488 times.
✓ Branch 1 taken 857090 times.
✓ Branch 2 taken 1700162 times.
✓ Branch 3 taken 5326 times.
|
2562578 | while (*p >= '0' && *p <= '9') { |
| 1808 | 1700162 | suffix = (suffix * 10) + (*p - '0'); | |
| 1809 | 1700162 | ++p; | |
| 1810 | 1700162 | ++count; | |
| 1811 | } | ||
| 1812 |
6/6✓ Branch 0 taken 857083 times.
✓ Branch 1 taken 5333 times.
✓ Branch 3 taken 857074 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 857074 times.
✓ Branch 6 taken 5342 times.
|
862416 | if (suffix > 0 && count == strSuffix.size()) { |
| 1813 |
2/2✓ Branch 1 taken 857074 times.
✓ Branch 4 taken 857074 times.
|
857074 | return std::make_tuple(suffix, spacer); |
| 1814 | } | ||
| 1815 | 862416 | } | |
| 1816 |
2/2✓ Branch 1 taken 8267 times.
✓ Branch 4 taken 8267 times.
|
8267 | return std::make_tuple(boost::none, " "); |
| 1817 | 865341 | } | |
| 1818 | |||
| 1819 | 8375775 | std::string Workspace_Impl::getBaseName(const std::string& objectName) const { | |
| 1820 | |||
| 1821 | 8375775 | std::size_t found1 = objectName.find_last_of(' '); | |
| 1822 | 8375775 | std::size_t found2 = objectName.find_last_of('_'); | |
| 1823 | 8375775 | std::size_t found = string::npos; | |
| 1824 |
4/4✓ Branch 0 taken 8145623 times.
✓ Branch 1 taken 230152 times.
✓ Branch 2 taken 45404 times.
✓ Branch 3 taken 8100219 times.
|
8375775 | if (found1 != string::npos && found2 != string::npos) { |
| 1825 | 45404 | found = std::max(found1, found2); | |
| 1826 |
2/2✓ Branch 0 taken 8100219 times.
✓ Branch 1 taken 230152 times.
|
8330371 | } else if (found1 != string::npos) { |
| 1827 | 8100219 | found = found1; | |
| 1828 |
2/2✓ Branch 0 taken 30274 times.
✓ Branch 1 taken 199878 times.
|
230152 | } else if (found2 != string::npos) { |
| 1829 | 30274 | found = found2; | |
| 1830 | } | ||
| 1831 | |||
| 1832 |
2/2✓ Branch 0 taken 8175897 times.
✓ Branch 1 taken 199878 times.
|
8375775 | if (found != string::npos) { |
| 1833 |
1/1✓ Branch 1 taken 8175897 times.
|
8175897 | std::string strSuffix = objectName.substr(found + 1); |
| 1834 | 8175897 | const char* p = strSuffix.c_str(); | |
| 1835 | 8175897 | int suffix = 0; | |
| 1836 | 8175897 | unsigned count = 0; | |
| 1837 |
4/4✓ Branch 0 taken 21229722 times.
✓ Branch 1 taken 7278432 times.
✓ Branch 2 taken 20332257 times.
✓ Branch 3 taken 897465 times.
|
28508154 | while (*p >= '0' && *p <= '9') { |
| 1838 | 20332257 | suffix = (suffix * 10) + (*p - '0'); | |
| 1839 | 20332257 | ++p; | |
| 1840 | 20332257 | ++count; | |
| 1841 | } | ||
| 1842 |
6/6✓ Branch 0 taken 7272235 times.
✓ Branch 1 taken 903662 times.
✓ Branch 3 taken 7210887 times.
✓ Branch 4 taken 61348 times.
✓ Branch 5 taken 7210887 times.
✓ Branch 6 taken 965010 times.
|
8175897 | if (suffix > 0 && count == strSuffix.size()) { |
| 1843 |
1/1✓ Branch 1 taken 7210887 times.
|
7210887 | return objectName.substr(0, found); |
| 1844 | } | ||
| 1845 | 8175897 | } | |
| 1846 |
1/1✓ Branch 1 taken 1164888 times.
|
1164888 | return objectName; |
| 1847 | } | ||
| 1848 | |||
| 1849 | 2723 | boost::optional<WorkspaceObject> Workspace_Impl::getEquivalentObject(const IdfObject& other) const { | |
| 1850 | // never overwrite existing version object | ||
| 1851 |
3/4✓ Branch 1 taken 2723 times.
✓ Branch 4 taken 2723 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2723 times.
|
2723 | if (other.iddObject().isVersionObject()) { |
| 1852 | ✗ | return versionObject(); | |
| 1853 | } | ||
| 1854 | |||
| 1855 | // get candidates by type and name | ||
| 1856 |
1/1✓ Branch 1 taken 2723 times.
|
2723 | OptionalString oName = other.name(); |
| 1857 | 2723 | WorkspaceObjectVector candidates; | |
| 1858 |
6/7✓ Branch 0 taken 2717 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 2717 times.
✓ Branch 6 taken 2717 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2717 times.
✓ Branch 9 taken 6 times.
|
2723 | if (oName && !oName->empty()) { |
| 1859 |
4/4✓ Branch 1 taken 2717 times.
✓ Branch 4 taken 2717 times.
✓ Branch 7 taken 2717 times.
✓ Branch 10 taken 2717 times.
|
2717 | OptionalWorkspaceObject owo = getObjectByTypeAndName(other.iddObject().type(), *oName); |
| 1860 |
2/2✓ Branch 0 taken 2079 times.
✓ Branch 1 taken 638 times.
|
2717 | if (owo) { |
| 1861 |
2/2✓ Branch 1 taken 2079 times.
✓ Branch 4 taken 2079 times.
|
2079 | candidates.push_back(*owo); |
| 1862 | } | ||
| 1863 | 2717 | } else { | |
| 1864 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | candidates = getObjectsByType(other.iddObject().type()); |
| 1865 | } | ||
| 1866 | |||
| 1867 | // test for equivalency | ||
| 1868 | 2723 | OptionalWorkspaceObject result; | |
| 1869 |
1/1✓ Branch 1 taken 2723 times.
|
2723 | OptionalWorkspaceObject wsOther = other.optionalCast<WorkspaceObject>(); |
| 1870 |
2/2✓ Branch 5 taken 2081 times.
✓ Branch 6 taken 649 times.
|
2730 | for (const WorkspaceObject& candidate : candidates) { |
| 1871 |
2/2✓ Branch 0 taken 2069 times.
✓ Branch 1 taken 12 times.
|
2081 | if (wsOther) { |
| 1872 |
10/10✓ Branch 1 taken 2069 times.
✓ Branch 4 taken 2069 times.
✓ Branch 6 taken 2068 times.
✓ Branch 7 taken 1 time.
✓ Branch 9 taken 2068 times.
✓ Branch 12 taken 2068 times.
✓ Branch 14 taken 2067 times.
✓ Branch 15 taken 1 time.
✓ Branch 16 taken 2067 times.
✓ Branch 17 taken 2 times.
|
2069 | if (candidate.dataFieldsEqual(*wsOther) && candidate.objectListFieldsNonConflicting(*wsOther)) { |
| 1873 |
1/1✓ Branch 1 taken 2067 times.
|
2067 | result = candidate; |
| 1874 | 2067 | break; | |
| 1875 | } | ||
| 1876 |
7/8✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 5 times.
|
12 | } else if (other.dataFieldsEqual(candidate) && other.objectListFieldsNonConflicting(candidate)) { |
| 1877 |
1/1✓ Branch 1 taken 7 times.
|
7 | result = candidate; |
| 1878 | 7 | break; | |
| 1879 | } | ||
| 1880 | } | ||
| 1881 | |||
| 1882 | 2723 | return result; | |
| 1883 | 2723 | } | |
| 1884 | |||
| 1885 | // SETTER HELPERS | ||
| 1886 | |||
| 1887 | ✗ | bool Workspace_Impl::setIddFile(const IddFileAndFactoryWrapper& iddFileAndFactoryWrapper) { | |
| 1888 | ✗ | IddFileAndFactoryWrapper temp = m_iddFileAndFactoryWrapper; | |
| 1889 | ✗ | m_iddFileAndFactoryWrapper = iddFileAndFactoryWrapper; | |
| 1890 | ✗ | if (isValid()) { | |
| 1891 | ✗ | return true; | |
| 1892 | } else { | ||
| 1893 | ✗ | LOG(Warn, "Unable to set IddFile to IddFileType " << iddFileAndFactoryWrapper.iddFileType() << ". Resulting Workspace is not valid:" << '\n' | |
| 1894 | << validityReport(m_strictnessLevel)); | ||
| 1895 | ✗ | m_iddFileAndFactoryWrapper = temp; | |
| 1896 | ✗ | return false; | |
| 1897 | } | ||
| 1898 | ✗ | } | |
| 1899 | |||
| 1900 | 392254 | bool Workspace_Impl::nominallyAddObject(std::shared_ptr<WorkspaceObject_Impl>& ptr) { | |
| 1901 | |||
| 1902 |
1/1✓ Branch 2 taken 392254 times.
|
392254 | Handle h = ptr->handle(); |
| 1903 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 392254 times.
|
392254 | if (h.isNull()) { |
| 1904 | ✗ | return false; | |
| 1905 | } | ||
| 1906 | |||
| 1907 | // WorkspaceObjectMap | ||
| 1908 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | std::pair<WorkspaceObjectMap::iterator, bool> insertOK; |
| 1909 |
1/1✓ Branch 2 taken 392254 times.
|
392254 | insertOK = m_workspaceObjectMap.insert(WorkspaceObjectMap::value_type(h, ptr)); |
| 1910 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 392254 times.
|
392254 | if (!insertOK.second) { |
| 1911 | ✗ | return false; | |
| 1912 | } | ||
| 1913 | |||
| 1914 | // WorkspaceObjectOrder--push_back if ordered directly | ||
| 1915 |
2/3✓ Branch 1 taken 392254 times.
✓ Branch 3 taken 392254 times.
✗ Branch 4 not taken.
|
392254 | if (m_workspaceObjectOrder.isDirectOrder()) { |
| 1916 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | m_workspaceObjectOrder.push_back(h); |
| 1917 | } | ||
| 1918 | |||
| 1919 | // IddObjectTypeMap | ||
| 1920 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | insertIntoIddObjectTypeMap(ptr); |
| 1921 | |||
| 1922 | // IdfReferencesMap | ||
| 1923 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | insertIntoIdfReferencesMap(ptr); |
| 1924 | |||
| 1925 | 392254 | return true; | |
| 1926 | } | ||
| 1927 | |||
| 1928 | ✗ | void Workspace_Impl::insertIntoObjectMap(const Handle& handle, const std::shared_ptr<WorkspaceObject_Impl>& objectImplPtr) { | |
| 1929 | ✗ | m_workspaceObjectMap[handle] = objectImplPtr; | |
| 1930 | ✗ | } | |
| 1931 | |||
| 1932 | 572800 | void Workspace_Impl::insertIntoIddObjectTypeMap(const std::shared_ptr<WorkspaceObject_Impl>& objectImplPtr) { | |
| 1933 |
5/5✓ Branch 2 taken 572800 times.
✓ Branch 5 taken 572800 times.
✓ Branch 8 taken 572800 times.
✓ Branch 12 taken 572800 times.
✓ Branch 16 taken 572800 times.
|
572800 | m_iddObjectTypeMap[objectImplPtr->iddObject().type()].insert(std::make_pair(objectImplPtr->handle(), objectImplPtr)); |
| 1934 | 572800 | } | |
| 1935 | |||
| 1936 | 572800 | void Workspace_Impl::insertIntoIdfReferencesMap(const std::shared_ptr<WorkspaceObject_Impl>& objectImplPtr) { | |
| 1937 |
2/2✓ Branch 2 taken 572800 times.
✓ Branch 5 taken 572800 times.
|
572800 | StringVector references = objectImplPtr->iddObject().references(); |
| 1938 |
2/2✓ Branch 4 taken 2270927 times.
✓ Branch 5 taken 572800 times.
|
2843727 | for (const std::string& referenceName : references) { |
| 1939 |
3/3✓ Branch 1 taken 2270927 times.
✓ Branch 5 taken 2270927 times.
✓ Branch 9 taken 2270927 times.
|
2270927 | m_idfReferencesMap[referenceName].insert(std::make_pair(objectImplPtr->handle(), objectImplPtr)); |
| 1940 | } | ||
| 1941 | 572800 | } | |
| 1942 | 1203 | bool Workspace_Impl::resolvePotentialNameConflicts(Workspace& other) { | |
| 1943 |
1/1✓ Branch 2 taken 1203 times.
|
1203 | return resolvePotentialNameConflicts(other, std::vector<unsigned>()); |
| 1944 | } | ||
| 1945 | |||
| 1946 | 10860 | bool Workspace_Impl::resolvePotentialNameConflicts(Workspace& other, const std::vector<unsigned>& toIgnore) { | |
| 1947 | 10860 | bool changeMade = false; | |
| 1948 | |||
| 1949 | 10860 | WorkspaceObjectVector objectsToRename; | |
| 1950 | 10860 | WorkspaceObjectVector objectsToExamine; | |
| 1951 | 10860 | std::map<std::string, WorkspaceObjectVector> nameObjectMap; | |
| 1952 |
2/2✓ Branch 1 taken 1543 times.
✓ Branch 2 taken 9317 times.
|
10860 | if (!toIgnore.empty()) { |
| 1953 |
1/1✓ Branch 1 taken 1543 times.
|
1543 | objectsToExamine = other.objects(true); |
| 1954 | } else { | ||
| 1955 |
1/1✓ Branch 1 taken 9317 times.
|
9317 | objectsToExamine = other.objects(false); |
| 1956 | } | ||
| 1957 | 10860 | unsigned i = 0; | |
| 1958 |
2/2✓ Branch 1 taken 10860 times.
✓ Branch 4 taken 10860 times.
|
10860 | bool sameWorkspace(workspace() == other); |
| 1959 |
2/2✓ Branch 4 taken 155957 times.
✓ Branch 5 taken 10860 times.
|
166817 | for (const WorkspaceObject& object : objectsToExamine) { |
| 1960 |
10/13✓ Branch 1 taken 155957 times.
✓ Branch 4 taken 155957 times.
✓ Branch 6 taken 130424 times.
✓ Branch 7 taken 25533 times.
✓ Branch 12 taken 130424 times.
✓ Branch 15 taken 128352 times.
✓ Branch 16 taken 2072 times.
✓ Branch 17 taken 155957 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 128352 times.
✓ Branch 21 taken 27605 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
155957 | if (object.iddObject().hasNameField() && (std::find(toIgnore.begin(), toIgnore.end(), i) == toIgnore.end())) { |
| 1961 |
1/1✓ Branch 1 taken 128352 times.
|
128352 | OptionalString currentName = object.name(); |
| 1962 |
6/7✓ Branch 0 taken 128352 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 128352 times.
✓ Branch 6 taken 128341 times.
✓ Branch 7 taken 11 times.
✓ Branch 8 taken 128341 times.
✓ Branch 9 taken 11 times.
|
128352 | if (currentName && !currentName->empty()) { |
| 1963 |
11/13✓ Branch 0 taken 10176 times.
✓ Branch 1 taken 118165 times.
✓ Branch 3 taken 10176 times.
✓ Branch 6 taken 10176 times.
✓ Branch 9 taken 10176 times.
✓ Branch 11 taken 8138 times.
✓ Branch 12 taken 2038 times.
✓ Branch 13 taken 10176 times.
✓ Branch 14 taken 118165 times.
✓ Branch 16 taken 8138 times.
✓ Branch 17 taken 120203 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
128341 | if (!sameWorkspace && potentialNameConflict(*currentName, object.iddObject())) { |
| 1964 |
1/1✓ Branch 1 taken 8138 times.
|
8138 | objectsToRename.push_back(object); |
| 1965 | } else { | ||
| 1966 |
2/2✓ Branch 1 taken 120203 times.
✓ Branch 4 taken 120203 times.
|
120203 | std::string lName = *currentName; |
| 1967 |
1/1✓ Branch 2 taken 120203 times.
|
120203 | boost::to_lower(lName); |
| 1968 |
1/1✓ Branch 1 taken 120203 times.
|
120203 | auto it = nameObjectMap.find(lName); |
| 1969 |
2/2✓ Branch 2 taken 119934 times.
✓ Branch 3 taken 269 times.
|
120203 | if (it == nameObjectMap.end()) { |
| 1970 |
2/2✓ Branch 1 taken 119934 times.
✓ Branch 4 taken 119934 times.
|
239868 | nameObjectMap[lName] = WorkspaceObjectVector(1u, object); |
| 1971 | } else { | ||
| 1972 |
2/2✓ Branch 6 taken 273 times.
✓ Branch 7 taken 255 times.
|
528 | for (const WorkspaceObject& other : it->second) { |
| 1973 |
7/7✓ Branch 1 taken 273 times.
✓ Branch 4 taken 273 times.
✓ Branch 7 taken 273 times.
✓ Branch 10 taken 273 times.
✓ Branch 13 taken 273 times.
✓ Branch 21 taken 14 times.
✓ Branch 22 taken 259 times.
|
273 | if (!intersectReferenceLists(object.iddObject().references(), other.iddObject().references()).empty()) { |
| 1974 |
1/1✓ Branch 1 taken 14 times.
|
14 | objectsToRename.push_back(object); |
| 1975 | 14 | break; | |
| 1976 | } | ||
| 1977 | } | ||
| 1978 |
1/1✓ Branch 2 taken 269 times.
|
269 | it->second.push_back(object); |
| 1979 | } | ||
| 1980 | 120203 | } | |
| 1981 | } | ||
| 1982 | 128352 | } | |
| 1983 | 155957 | ++i; | |
| 1984 | } | ||
| 1985 | |||
| 1986 | 10860 | OptionalString newName; | |
| 1987 | 10860 | std::string originalDescription; | |
| 1988 |
2/2✓ Branch 4 taken 8152 times.
✓ Branch 5 taken 10860 times.
|
19012 | for (WorkspaceObject& object : objectsToRename) { |
| 1989 |
1/1✓ Branch 1 taken 8152 times.
|
8152 | originalDescription = object.briefDescription(); |
| 1990 |
4/4✓ Branch 1 taken 8152 times.
✓ Branch 4 taken 8152 times.
✓ Branch 7 taken 8152 times.
✓ Branch 10 taken 8152 times.
|
8152 | newName = nextName(object.name().get(), false); |
| 1991 |
2/2✓ Branch 1 taken 8152 times.
✓ Branch 4 taken 8152 times.
|
8152 | newName = object.setName(*newName); |
| 1992 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 8152 times.
✗ Branch 4 not taken.
|
8152 | OS_ASSERT(newName); |
| 1993 |
10/10✓ Branch 1 taken 8152 times.
✓ Branch 4 taken 8152 times.
✓ Branch 7 taken 8152 times.
✓ Branch 10 taken 8152 times.
✓ Branch 13 taken 8152 times.
✓ Branch 16 taken 8152 times.
✓ Branch 19 taken 8152 times.
✓ Branch 22 taken 8152 times.
✓ Branch 25 taken 8152 times.
✓ Branch 28 taken 8152 times.
|
8152 | LOG(Info, "Renamed " << originalDescription << " to '" << *newName << "' to avoid a name conflict upon WorkspaceObject addition."); |
| 1994 | 8152 | changeMade = true; | |
| 1995 | } | ||
| 1996 | |||
| 1997 | 10860 | return changeMade; | |
| 1998 | 10860 | } | |
| 1999 | |||
| 2000 | 16 | void Workspace_Impl::mergeIdfObjectAfterPotentialNameConflictResolution(IdfObject& mergedObject, const IdfObject& originalObject) const { | |
| 2001 |
4/6✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 12 not taken.
|
16 | OS_ASSERT(mergedObject.iddObject() == originalObject.iddObject()); |
| 2002 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
16 | OS_ASSERT(mergedObject.numFields() == originalObject.numFields()); |
| 2003 |
2/2✓ Branch 1 taken 77 times.
✓ Branch 2 taken 16 times.
|
93 | for (unsigned i = 0, n = mergedObject.numFields(); i < n; ++i) { |
| 2004 |
4/4✓ Branch 1 taken 77 times.
✓ Branch 4 taken 77 times.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 57 times.
|
77 | if (mergedObject.getString(i).get().empty()) { |
| 2005 |
3/3✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
|
20 | mergedObject.setString(i, originalObject.getString(i).get()); |
| 2006 | } | ||
| 2007 | } | ||
| 2008 | 16 | } | |
| 2009 | |||
| 2010 | 5461 | bool Workspace_Impl::addProvidedRelationships(const std::vector<Handle>& handles, const std::vector<UHPointer>& pointersIntoWorkspace, | |
| 2011 | const std::vector<HUPointer>& pointersFromWorkspace) { | ||
| 2012 | |||
| 2013 | 5461 | bool success = true; | |
| 2014 | |||
| 2015 |
2/2✓ Branch 5 taken 7652 times.
✓ Branch 6 taken 5461 times.
|
13113 | for (const UHPointer& intoPtr : pointersIntoWorkspace) { |
| 2016 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7652 times.
|
7652 | if (!success) { |
| 2017 | ✗ | break; | |
| 2018 | } | ||
| 2019 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 7652 times.
✗ Branch 4 not taken.
|
7652 | OS_ASSERT(intoPtr.source < handles.size()); |
| 2020 | // get source object | ||
| 2021 |
1/1✓ Branch 2 taken 7652 times.
|
7652 | OptionalWorkspaceObject oSource = getObject(handles[intoPtr.source]); |
| 2022 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7652 times.
|
7652 | if (!oSource) { |
| 2023 | ✗ | success = false; | |
| 2024 | } else { | ||
| 2025 |
2/2✓ Branch 1 taken 7652 times.
✓ Branch 6 taken 7652 times.
|
7652 | success = oSource->getImpl<WorkspaceObject_Impl>()->setPointer(intoPtr.fieldIndex, intoPtr.target, false); |
| 2026 | } | ||
| 2027 | 7652 | } | |
| 2028 | |||
| 2029 |
2/2✓ Branch 5 taken 40 times.
✓ Branch 6 taken 5461 times.
|
5501 | for (const HUPointer& fromPtr : pointersFromWorkspace) { |
| 2030 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (!success) { |
| 2031 | ✗ | break; | |
| 2032 | } | ||
| 2033 | // get target handle | ||
| 2034 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 4 not taken.
|
40 | OS_ASSERT(fromPtr.target < handles.size()); |
| 2035 | 40 | Handle targetHandle = handles[fromPtr.target]; | |
| 2036 | // get source object | ||
| 2037 |
1/1✓ Branch 1 taken 40 times.
|
40 | OptionalWorkspaceObject oSource = getObject(fromPtr.source); |
| 2038 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
|
40 | if (!oSource) { |
| 2039 | ✗ | success = false; | |
| 2040 | } else { | ||
| 2041 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 6 taken 40 times.
|
40 | success = oSource->getImpl<WorkspaceObject_Impl>()->setPointer(fromPtr.fieldIndex, targetHandle, false); |
| 2042 | } | ||
| 2043 | 40 | } | |
| 2044 | |||
| 2045 | 5461 | return success; | |
| 2046 | } | ||
| 2047 | |||
| 2048 | 7 | std::vector<WorkspaceObject> Workspace_Impl::simpleAddObjects(const std::vector<IdfObject>& idfObjects) { | |
| 2049 | 7 | WorkspaceObjectVector result; | |
| 2050 | 7 | WorkspaceObject_ImplPtrVector newObjects; | |
| 2051 | |||
| 2052 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | if (idfObjects.empty()) { |
| 2053 | ✗ | return result; | |
| 2054 | } | ||
| 2055 | |||
| 2056 |
2/2✓ Branch 2 taken 7 times.
✓ Branch 5 taken 7 times.
|
7 | bool keepHandles = idfObjects[0].iddObject().hasHandleField(); |
| 2057 | |||
| 2058 | 7 | auto it(idfObjects.begin()); | |
| 2059 | 7 | auto itEnd(idfObjects.end()); | |
| 2060 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 2 taken 7 times.
|
22 | for (; it != itEnd; ++it) { |
| 2061 |
2/2✓ Branch 2 taken 15 times.
✓ Branch 5 taken 15 times.
|
15 | newObjects.push_back(this->createObject(*it, keepHandles)); |
| 2062 | } | ||
| 2063 |
1/1✓ Branch 3 taken 7 times.
|
7 | result = addObjects(newObjects, UHPointerVector(), HUPointerVector(), true, true, false); |
| 2064 |
1/1✓ Branch 1 taken 7 times.
|
7 | Workspace thisWorkspace = workspace(); |
| 2065 |
1/1✓ Branch 1 taken 7 times.
|
7 | resolvePotentialNameConflicts(thisWorkspace); |
| 2066 | |||
| 2067 | 7 | return result; | |
| 2068 | 7 | } | |
| 2069 | |||
| 2070 | 9959 | Workspace_Impl::OptionalSavedWorkspaceObject Workspace_Impl::savedWorkspaceObject(const Handle& handle) { | |
| 2071 |
1/1✓ Branch 1 taken 9959 times.
|
9959 | OptionalWorkspaceObject oObject = getObject(handle); |
| 2072 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9959 times.
|
9959 | if (!oObject) { |
| 2073 | ✗ | return boost::none; | |
| 2074 | } | ||
| 2075 | |||
| 2076 | // required info | ||
| 2077 |
1/1✓ Branch 1 taken 9959 times.
|
9959 | SavedWorkspaceObject result(handle, oObject->getImpl<WorkspaceObject_Impl>()); |
| 2078 | |||
| 2079 | // direct order | ||
| 2080 |
1/1✓ Branch 1 taken 9959 times.
|
9959 | result.orderIndex = m_workspaceObjectOrder.indexInOrder(handle); |
| 2081 | |||
| 2082 |
1/1✓ Branch 1 taken 9959 times.
|
9959 | return result; |
| 2083 | 9959 | } | |
| 2084 | |||
| 2085 | 9974 | std::vector<WorkspaceObject> Workspace_Impl::nominallyRemoveObject(const Handle& handle) { | |
| 2086 | // get object. should exist since call came from within Workspace. | ||
| 2087 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | OptionalWorkspaceObject oObject = getObject(handle); |
| 2088 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9974 times.
|
9974 | if (!oObject) { |
| 2089 | ✗ | OS_ASSERT(oObject); | |
| 2090 | } | ||
| 2091 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | WorkspaceObject_ImplPtr objectImplPtr = oObject->getImpl<WorkspaceObject_Impl>(); |
| 2092 | |||
| 2093 | // unlink from other objects | ||
| 2094 | // handle -> others | ||
| 2095 |
1/1✓ Branch 2 taken 9974 times.
|
9974 | UnsignedVector ptrFields = objectImplPtr->objectListFields(); |
| 2096 |
2/2✓ Branch 4 taken 21044 times.
✓ Branch 5 taken 9974 times.
|
31018 | for (unsigned index : ptrFields) { |
| 2097 |
2/2✓ Branch 2 taken 21044 times.
✓ Branch 5 taken 21044 times.
|
21044 | objectImplPtr->setPointer(index, Handle(), false); |
| 2098 | } | ||
| 2099 | // others -> handle | ||
| 2100 | 9974 | WorkspaceObjectVector sources; | |
| 2101 |
1/1✓ Branch 2 taken 9974 times.
|
9974 | ReversePointerSet pointers = objectImplPtr->getReversePointers(); |
| 2102 |
2/2✓ Branch 5 taken 2025 times.
✓ Branch 6 taken 9974 times.
|
11999 | for (const ReversePointer& ptr : pointers) { |
| 2103 |
1/1✓ Branch 1 taken 2025 times.
|
2025 | OptionalWorkspaceObject source = getObject(ptr.sourceHandle); |
| 2104 | // OS_ASSERT(sourceImplPtr); | ||
| 2105 |
1/2✓ Branch 0 taken 2025 times.
✗ Branch 1 not taken.
|
2025 | if (source) { |
| 2106 |
3/3✓ Branch 1 taken 2025 times.
✓ Branch 6 taken 2025 times.
✓ Branch 9 taken 2025 times.
|
2025 | source->getImpl<WorkspaceObject_Impl>()->setPointer(ptr.fieldIndex, Handle(), false); |
| 2107 |
2/2✓ Branch 1 taken 2025 times.
✓ Branch 4 taken 2025 times.
|
2025 | sources.push_back(*source); |
| 2108 | } else { | ||
| 2109 | ✗ | OptionalString objectName = objectImplPtr->name(); | |
| 2110 | ✗ | if (objectName) { | |
| 2111 | ✗ | LOG(Debug, "Object of type '" << objectImplPtr->iddObject().name() << "' named '" << *objectName | |
| 2112 | << "' has a reverse pointer that cannot be followed."); | ||
| 2113 | } else { | ||
| 2114 | ✗ | LOG(Debug, "Object of type '" << objectImplPtr->iddObject().name() << "' has a reverse pointer that cannot be followed."); | |
| 2115 | } | ||
| 2116 | ✗ | } | |
| 2117 | 2025 | } | |
| 2118 | |||
| 2119 | // IdfReferencesMap | ||
| 2120 |
2/2✓ Branch 2 taken 9974 times.
✓ Branch 5 taken 9974 times.
|
9974 | StringVector references = objectImplPtr->iddObject().references(); |
| 2121 |
2/2✓ Branch 5 taken 25267 times.
✓ Branch 6 taken 9974 times.
|
35241 | for (const std::string& reference : references) { |
| 2122 |
1/1✓ Branch 1 taken 25267 times.
|
25267 | auto irmLoc = m_idfReferencesMap.find(reference); |
| 2123 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 25267 times.
✗ Branch 5 not taken.
|
25267 | OS_ASSERT(irmLoc != m_idfReferencesMap.end()); |
| 2124 |
1/1✓ Branch 2 taken 25267 times.
|
25267 | auto loc = irmLoc->second.find(handle); |
| 2125 |
1/3✗ Branch 3 not taken.
✓ Branch 4 taken 25267 times.
✗ Branch 6 not taken.
|
25267 | OS_ASSERT(loc != irmLoc->second.end()); |
| 2126 |
1/1✓ Branch 2 taken 25267 times.
|
25267 | irmLoc->second.erase(loc); |
| 2127 | // erase entry if set is empty | ||
| 2128 |
2/2✓ Branch 2 taken 2856 times.
✓ Branch 3 taken 22411 times.
|
25267 | if (irmLoc->second.empty()) { |
| 2129 |
1/1✓ Branch 1 taken 2856 times.
|
2856 | m_idfReferencesMap.erase(irmLoc); |
| 2130 | } | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | // IddObjectTypeMap | ||
| 2134 |
3/3✓ Branch 2 taken 9974 times.
✓ Branch 5 taken 9974 times.
✓ Branch 8 taken 9974 times.
|
9974 | auto iotmLoc = m_iddObjectTypeMap.find(objectImplPtr->iddObject().type()); |
| 2135 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9974 times.
✗ Branch 5 not taken.
|
9974 | OS_ASSERT(iotmLoc != m_iddObjectTypeMap.end()); |
| 2136 |
1/1✓ Branch 2 taken 9974 times.
|
9974 | auto loc = iotmLoc->second.find(handle); |
| 2137 |
1/3✗ Branch 3 not taken.
✓ Branch 4 taken 9974 times.
✗ Branch 6 not taken.
|
9974 | OS_ASSERT(loc != iotmLoc->second.end()); |
| 2138 |
1/1✓ Branch 2 taken 9974 times.
|
9974 | iotmLoc->second.erase(loc); |
| 2139 | // erase entry if set is empty | ||
| 2140 |
2/2✓ Branch 2 taken 2069 times.
✓ Branch 3 taken 7905 times.
|
9974 | if (iotmLoc->second.empty()) { |
| 2141 |
1/1✓ Branch 1 taken 2069 times.
|
2069 | m_iddObjectTypeMap.erase(iotmLoc); |
| 2142 | } | ||
| 2143 | |||
| 2144 | // WorkspaceObjectOrder | ||
| 2145 |
2/3✓ Branch 1 taken 9974 times.
✓ Branch 3 taken 9974 times.
✗ Branch 4 not taken.
|
9974 | if (m_workspaceObjectOrder.isDirectOrder()) { |
| 2146 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | m_workspaceObjectOrder.erase(handle); |
| 2147 | } | ||
| 2148 | |||
| 2149 | // WorkspaceObjectMap | ||
| 2150 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | auto womIt = m_workspaceObjectMap.find(handle); |
| 2151 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | m_workspaceObjectMap.erase(womIt); |
| 2152 | |||
| 2153 | 19948 | return sources; | |
| 2154 | 9974 | } | |
| 2155 | |||
| 2156 | 1797 | std::vector<std::vector<WorkspaceObject>> Workspace_Impl::nominallyRemoveObjects(const std::vector<Handle>& handles) { | |
| 2157 | 1797 | std::vector<std::vector<WorkspaceObject>> sources; | |
| 2158 |
2/2✓ Branch 4 taken 3735 times.
✓ Branch 5 taken 1797 times.
|
5532 | for (const Handle& handle : handles) { |
| 2159 |
2/2✓ Branch 1 taken 3735 times.
✓ Branch 4 taken 3735 times.
|
3735 | sources.push_back(nominallyRemoveObject(handle)); |
| 2160 | } | ||
| 2161 | 1797 | return sources; | |
| 2162 | ✗ | } | |
| 2163 | |||
| 2164 | 9959 | void Workspace_Impl::registerRemovalOfObject(std::shared_ptr<WorkspaceObject_Impl> ptr, const std::vector<WorkspaceObject>& sources, | |
| 2165 | const std::vector<Handle>& removedHandles) { | ||
| 2166 | //DLM@20110810: moved remove emits to occur before object is removed from workspace | ||
| 2167 | //ptr->emitChangeSignals(); // do not emit signals for changes that occurred during removal | ||
| 2168 |
2/2✓ Branch 5 taken 2025 times.
✓ Branch 6 taken 9959 times.
|
11984 | for (const WorkspaceObject& source : sources) { |
| 2169 | // do not emit signals if this source is also being removed | ||
| 2170 |
4/4✓ Branch 2 taken 2025 times.
✓ Branch 7 taken 2025 times.
✓ Branch 10 taken 820 times.
✓ Branch 11 taken 1205 times.
|
2025 | if (std::find(removedHandles.begin(), removedHandles.end(), source.handle()) == removedHandles.end()) { |
| 2171 |
1/1✓ Branch 3 taken 820 times.
|
820 | source.getImpl<detail::WorkspaceObject_Impl>()->emitChangeSignals(); |
| 2172 | } | ||
| 2173 | } | ||
| 2174 | 9959 | ptr->disconnect(); | |
| 2175 | 9959 | ptr.get()->onChange.disconnect<Workspace_Impl, &Workspace_Impl::change>(this); | |
| 2176 | 9959 | } | |
| 2177 | |||
| 2178 | 1790 | void Workspace_Impl::registerRemovalOfObjects(std::vector<SavedWorkspaceObject>& savedObjects, | |
| 2179 | const std::vector<std::vector<WorkspaceObject>>& sources, const std::vector<Handle>& removedHandles) { | ||
| 2180 |
2/2✓ Branch 1 taken 3720 times.
✓ Branch 2 taken 1790 times.
|
5510 | for (int i = 0, n = savedObjects.size(); i < n; ++i) { |
| 2181 |
1/1✓ Branch 4 taken 3720 times.
|
3720 | registerRemovalOfObject(savedObjects[i].objectImplPtr, sources[i], removedHandles); |
| 2182 | } | ||
| 2183 | 1790 | } | |
| 2184 | |||
| 2185 | 572785 | void Workspace_Impl::registerAdditionOfObject(const WorkspaceObject& object) { | |
| 2186 |
1/1✓ Branch 3 taken 572785 times.
|
572785 | object.getImpl<WorkspaceObject_Impl>().get()->WorkspaceObject_Impl::onChange.connect<Workspace_Impl, &Workspace_Impl::change>(this); |
| 2187 | 572785 | auto sh_ptr = object.getImpl<WorkspaceObject_Impl>(); | |
| 2188 |
4/4✓ Branch 1 taken 572785 times.
✓ Branch 4 taken 572785 times.
✓ Branch 7 taken 572785 times.
✓ Branch 10 taken 572785 times.
|
572785 | this->addWorkspaceObject.nano_emit(object, object.iddObject().type(), object.handle()); |
| 2189 |
4/4✓ Branch 1 taken 572785 times.
✓ Branch 4 taken 572785 times.
✓ Branch 7 taken 572785 times.
✓ Branch 10 taken 572785 times.
|
572785 | this->addWorkspaceObjectPtr.nano_emit(sh_ptr, object.iddObject().type(), object.handle()); |
| 2190 |
1/1✓ Branch 1 taken 572785 times.
|
572785 | this->onChange.nano_emit(); |
| 2191 | 572785 | } | |
| 2192 | |||
| 2193 | ✗ | void Workspace_Impl::restoreObject(SavedWorkspaceObject& savedObject) { | |
| 2194 | // WorkspaceObjectMap | ||
| 2195 | ✗ | m_workspaceObjectMap.insert(WorkspaceObjectMap::value_type(savedObject.handle, savedObject.objectImplPtr)); | |
| 2196 | |||
| 2197 | // WorkspaceObjectOrder | ||
| 2198 | ✗ | if (savedObject.orderIndex) { | |
| 2199 | ✗ | m_workspaceObjectOrder.insert(savedObject.handle, *(savedObject.orderIndex)); | |
| 2200 | } | ||
| 2201 | |||
| 2202 | // IddObjectTypeMap | ||
| 2203 | ✗ | insertIntoIddObjectTypeMap(savedObject.objectImplPtr); | |
| 2204 | |||
| 2205 | // IdfReferencesMap | ||
| 2206 | ✗ | insertIntoIdfReferencesMap(savedObject.objectImplPtr); | |
| 2207 | |||
| 2208 | // Fix Pointers | ||
| 2209 | ✗ | savedObject.objectImplPtr->restorePointers(); | |
| 2210 | |||
| 2211 | // Connect signals | ||
| 2212 | ✗ | WorkspaceObject workspaceObject(savedObject.objectImplPtr); | |
| 2213 | |||
| 2214 | // emit signals | ||
| 2215 | ✗ | registerAdditionOfObject(workspaceObject); | |
| 2216 | ✗ | } | |
| 2217 | |||
| 2218 | ✗ | void Workspace_Impl::restoreObjects(SavedWorkspaceObjectVector& savedObjects) { | |
| 2219 | ✗ | for (SavedWorkspaceObject& object : savedObjects) { | |
| 2220 | ✗ | restoreObject(object); | |
| 2221 | } | ||
| 2222 | ✗ | } | |
| 2223 | |||
| 2224 | // QUERIES | ||
| 2225 | |||
| 2226 | 121816 | std::string Workspace_Impl::constructNextName(const std::string& objectName, const std::vector<WorkspaceObject>& objectsInTheSeries, | |
| 2227 | bool fillIn) const { | ||
| 2228 | 121816 | vector<int> takenValues; | |
| 2229 | 121816 | std::tuple<boost::optional<int>, std::string> takenSuffix; | |
| 2230 |
2/2✓ Branch 5 taken 865341 times.
✓ Branch 6 taken 121816 times.
|
987157 | for (const WorkspaceObject& object : objectsInTheSeries) { |
| 2231 |
3/3✓ Branch 1 taken 865341 times.
✓ Branch 4 taken 865341 times.
✓ Branch 7 taken 865341 times.
|
865341 | takenSuffix = getNameSuffix(*(object.name())); |
| 2232 |
2/2✓ Branch 1 taken 857074 times.
✓ Branch 2 taken 8267 times.
|
1730682 | if (std::get<0>(takenSuffix)) { |
| 2233 |
2/2✓ Branch 2 taken 857074 times.
✓ Branch 5 taken 857074 times.
|
857074 | takenValues.push_back(*std::get<0>(takenSuffix)); |
| 2234 | } | ||
| 2235 | } | ||
| 2236 |
1/1✓ Branch 3 taken 121816 times.
|
121816 | std::sort(takenValues.begin(), takenValues.end()); |
| 2237 |
2/2✓ Branch 5 taken 121816 times.
✓ Branch 9 taken 121816 times.
|
121816 | takenValues.erase(std::unique(takenValues.begin(), takenValues.end()), takenValues.end()); |
| 2238 | |||
| 2239 | 121816 | int suffix(1); | |
| 2240 |
2/2✓ Branch 0 taken 111349 times.
✓ Branch 1 taken 10467 times.
|
121816 | if (fillIn) { |
| 2241 |
2/2✓ Branch 5 taken 782294 times.
✓ Branch 6 taken 110341 times.
|
892635 | for (int usedSuffix : takenValues) { |
| 2242 |
2/2✓ Branch 0 taken 781286 times.
✓ Branch 1 taken 1008 times.
|
782294 | if (usedSuffix == suffix) { |
| 2243 | 781286 | ++suffix; | |
| 2244 | } else { | ||
| 2245 | 1008 | break; | |
| 2246 | } | ||
| 2247 | } | ||
| 2248 | } else { | ||
| 2249 |
2/2✓ Branch 1 taken 5908 times.
✓ Branch 2 taken 4559 times.
|
10467 | if (!takenValues.empty()) { |
| 2250 | 5908 | suffix = *(takenValues.rbegin()) + 1; | |
| 2251 | } | ||
| 2252 | } | ||
| 2253 |
1/1✓ Branch 2 taken 121816 times.
|
121816 | std::string spacer = std::get<1>(takenSuffix); |
| 2254 |
2/2✓ Branch 1 taken 75268 times.
✓ Branch 2 taken 46548 times.
|
121816 | if (spacer.empty()) { |
| 2255 |
1/1✓ Branch 1 taken 75268 times.
|
75268 | spacer = " "; |
| 2256 | } | ||
| 2257 |
4/4✓ Branch 1 taken 121816 times.
✓ Branch 4 taken 121816 times.
✓ Branch 7 taken 121816 times.
✓ Branch 10 taken 121816 times.
|
243632 | return getBaseName(objectName) + spacer + boost::lexical_cast<std::string>(suffix); |
| 2258 | 121816 | } | |
| 2259 | |||
| 2260 | ✗ | std::vector<std::vector<WorkspaceObject>> Workspace_Impl::nameConflicts(const std::vector<WorkspaceObject>& candidates) const { | |
| 2261 | ✗ | std::vector<WorkspaceObjectVector> result; | |
| 2262 | ✗ | IStringSet examinedNames; | |
| 2263 | |||
| 2264 | ✗ | for (auto it = candidates.begin(), itEnd = candidates.end(); it != itEnd; ++it) { | |
| 2265 | ✗ | WorkspaceObject candidate = *it; | |
| 2266 | ✗ | OptionalString candidateName = candidate.name(); | |
| 2267 | ✗ | OS_ASSERT(candidateName); | |
| 2268 | ✗ | std::pair<IStringSet::iterator, bool> isNewName = examinedNames.insert(*candidateName); | |
| 2269 | ✗ | if (!isNewName.second) { | |
| 2270 | // conflict found -- add candidate to result | ||
| 2271 | ✗ | bool added = false; | |
| 2272 | ✗ | for (WorkspaceObjectVector& conflictGroup : result) { | |
| 2273 | ✗ | if (boost::iequals(*candidateName, conflictGroup[0].name().get())) { | |
| 2274 | ✗ | conflictGroup.push_back(candidate); | |
| 2275 | ✗ | added = true; | |
| 2276 | ✗ | break; | |
| 2277 | } | ||
| 2278 | } | ||
| 2279 | ✗ | if (!added) { | |
| 2280 | // create new group | ||
| 2281 | ✗ | WorkspaceObjectVector newConflictGroup; | |
| 2282 | // get first instance of name | ||
| 2283 | ✗ | for (auto jt = candidates.begin(); jt != it; ++jt) { | |
| 2284 | ✗ | if (boost::iequals(*candidateName, jt->name().get())) { | |
| 2285 | ✗ | newConflictGroup.push_back(*jt); | |
| 2286 | ✗ | added = true; | |
| 2287 | ✗ | break; | |
| 2288 | } | ||
| 2289 | } | ||
| 2290 | ✗ | OS_ASSERT(added); | |
| 2291 | ✗ | newConflictGroup.push_back(candidate); | |
| 2292 | ✗ | result.push_back(newConflictGroup); | |
| 2293 | ✗ | } | |
| 2294 | } | ||
| 2295 | ✗ | } | |
| 2296 | |||
| 2297 | ✗ | return result; | |
| 2298 | ✗ | } | |
| 2299 | |||
| 2300 | 10496 | bool Workspace_Impl::potentialNameConflict(const std::string& currentName, const IddObject& iddObject) const { | |
| 2301 | 10496 | bool result = false; | |
| 2302 |
1/1✓ Branch 1 taken 10496 times.
|
10496 | WorkspaceObjectVector candidates = getObjectsByName(currentName); |
| 2303 |
2/2✓ Branch 1 taken 2354 times.
✓ Branch 2 taken 8142 times.
|
10496 | if (candidates.empty()) { |
| 2304 | 2354 | return result; | |
| 2305 | } | ||
| 2306 | |||
| 2307 | // potential for conflicts. take set intersection of reference lists | ||
| 2308 |
1/1✓ Branch 1 taken 8142 times.
|
8142 | StringVector iddObjectReferences = iddObject.references(); |
| 2309 |
2/2✓ Branch 5 taken 8175 times.
✓ Branch 6 taken 1 time.
|
8176 | for (const WorkspaceObject& candidate : candidates) { |
| 2310 |
4/4✓ Branch 1 taken 8175 times.
✓ Branch 4 taken 8175 times.
✓ Branch 7 taken 8139 times.
✓ Branch 8 taken 36 times.
|
8175 | if (candidate.iddObject() == iddObject) { |
| 2311 | 8141 | return true; | |
| 2312 | } | ||
| 2313 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
|
36 | StringVector candidateReferences = candidate.iddObject().references(); |
| 2314 |
1/1✓ Branch 1 taken 36 times.
|
36 | StringVector intersection = intersectReferenceLists(iddObjectReferences, candidateReferences); |
| 2315 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 34 times.
|
36 | if (!intersection.empty()) { |
| 2316 | 2 | return true; | |
| 2317 | } | ||
| 2318 | 38 | } | |
| 2319 | 1 | return result; | |
| 2320 | 10496 | } | |
| 2321 | |||
| 2322 | 1203901 | void Workspace_Impl::change() { | |
| 2323 | 1203901 | this->onChange.nano_emit(); | |
| 2324 | 1203901 | } | |
| 2325 | |||
| 2326 | 1230 | void Workspace_Impl::createAndAddClonedObjects(const std::shared_ptr<detail::Workspace_Impl>& /*thisImpl*/, | |
| 2327 | std::shared_ptr<detail::Workspace_Impl> cloneImpl, bool keepHandles) const { | ||
| 2328 | 1230 | detail::WorkspaceObject_ImplPtrVector newObjectImplPtrs; | |
| 2329 | 1230 | HandleMap oldNewHandleMap; | |
| 2330 |
3/3✓ Branch 1 taken 1230 times.
✓ Branch 8 taken 76954 times.
✓ Branch 9 taken 1230 times.
|
78184 | for (const WorkspaceObject& object : allObjects()) { |
| 2331 |
2/2✓ Branch 3 taken 76954 times.
✓ Branch 6 taken 76954 times.
|
76954 | newObjectImplPtrs.push_back(cloneImpl->createObject(object.getImpl<detail::WorkspaceObject_Impl>(), keepHandles)); |
| 2332 |
1/1✓ Branch 3 taken 76954 times.
|
76954 | Handle h = newObjectImplPtrs.back()->handle(); |
| 2333 |
2/2✓ Branch 0 taken 7942 times.
✓ Branch 1 taken 69012 times.
|
76954 | if (!keepHandles) { |
| 2334 |
2/2✓ Branch 1 taken 7942 times.
✓ Branch 5 taken 7942 times.
|
7942 | oldNewHandleMap.insert(HandleMap::value_type(object.handle(), h)); |
| 2335 | } | ||
| 2336 | 1230 | } | |
| 2337 | // add Object_ImplPtrs to clone's Workspace_Impl | ||
| 2338 |
1/1✓ Branch 4 taken 1230 times.
|
1230 | cloneImpl->addClones(newObjectImplPtrs, oldNewHandleMap, true); |
| 2339 | 1230 | } | |
| 2340 | |||
| 2341 | 9759 | void Workspace_Impl::createAndAddSubsetClonedObjects(const std::shared_ptr<detail::Workspace_Impl>& thisImpl, | |
| 2342 | std::shared_ptr<detail::Workspace_Impl> cloneImpl, const std::vector<Handle>& handles, | ||
| 2343 | bool keepHandles) const { | ||
| 2344 | // make sure versionObject comes along for the ride | ||
| 2345 |
1/1✓ Branch 1 taken 9759 times.
|
9759 | HandleVector wHandles = handles; |
| 2346 |
2/3✓ Branch 1 taken 9759 times.
✓ Branch 3 taken 9759 times.
✗ Branch 4 not taken.
|
19518 | if (OptionalWorkspaceObject vo = versionObject()) { |
| 2347 |
4/5✓ Branch 2 taken 9759 times.
✓ Branch 5 taken 9759 times.
✓ Branch 10 taken 9759 times.
✓ Branch 13 taken 9759 times.
✗ Branch 14 not taken.
|
9759 | if (std::find(wHandles.begin(), wHandles.end(), vo->handle()) == wHandles.end()) { |
| 2348 |
3/3✓ Branch 1 taken 9759 times.
✓ Branch 4 taken 9759 times.
✓ Branch 9 taken 9759 times.
|
9759 | wHandles.insert(wHandles.begin(), vo->handle()); |
| 2349 | } | ||
| 2350 | 9759 | } | |
| 2351 | |||
| 2352 | // construct clone's WorkspaceObject_ImplPtrs | ||
| 2353 | 9759 | detail::WorkspaceObject_ImplPtrVector newObjectImplPtrs; | |
| 2354 | 9759 | HandleMap oldNewHandleMap; | |
| 2355 |
2/2✓ Branch 5 taken 9759 times.
✓ Branch 6 taken 9759 times.
|
19518 | for (const Handle& h : wHandles) { |
| 2356 |
1/1✓ Branch 2 taken 9759 times.
|
9759 | OptionalWorkspaceObject object = thisImpl->getObject(h); |
| 2357 |
1/2✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
|
9759 | if (object) { |
| 2358 |
3/3✓ Branch 2 taken 9759 times.
✓ Branch 6 taken 9759 times.
✓ Branch 9 taken 9759 times.
|
9759 | newObjectImplPtrs.push_back(cloneImpl->createObject(object->getImpl<detail::WorkspaceObject_Impl>(), keepHandles)); |
| 2359 |
1/1✓ Branch 3 taken 9759 times.
|
9759 | Handle newH = newObjectImplPtrs.back()->handle(); |
| 2360 |
1/2✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
|
9759 | if (!keepHandles) { |
| 2361 |
1/1✓ Branch 2 taken 9759 times.
|
9759 | oldNewHandleMap.insert(HandleMap::value_type(h, newH)); |
| 2362 | } | ||
| 2363 | } | ||
| 2364 | 9759 | } | |
| 2365 | |||
| 2366 | // add Object_ImplPtrs to clone's Workspace_Impl | ||
| 2367 |
1/1✓ Branch 4 taken 9759 times.
|
9759 | cloneImpl->addClones(newObjectImplPtrs, oldNewHandleMap, true); |
| 2368 | 9759 | } | |
| 2369 | |||
| 2370 | 1230 | std::vector<WorkspaceObject> Workspace_Impl::allObjects() const { | |
| 2371 | 1230 | WorkspaceObjectVector result; | |
| 2372 |
2/2✓ Branch 4 taken 76954 times.
✓ Branch 5 taken 1230 times.
|
78184 | for (const WorkspaceObjectMap::value_type& p : m_workspaceObjectMap) { |
| 2373 |
2/2✓ Branch 2 taken 76954 times.
✓ Branch 5 taken 76954 times.
|
76954 | result.push_back(WorkspaceObject(p.second)); |
| 2374 | } | ||
| 2375 | 1230 | return result; | |
| 2376 | ✗ | } | |
| 2377 | |||
| 2378 | } // namespace detail | ||
| 2379 | |||
| 2380 | // CONSTRUCTORS | ||
| 2381 | |||
| 2382 |
4/6✓ Branch 2 taken 179 times.
✓ Branch 5 taken 179 times.
✓ Branch 8 taken 179 times.
✓ Branch 11 taken 179 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
179 | Workspace::Workspace() : m_impl(new detail::Workspace_Impl(StrictnessLevel(StrictnessLevel::Draft), IddFileType(IddFileType::EnergyPlus))) { |
| 2383 |
1/1✓ Branch 1 taken 179 times.
|
179 | addVersionObject(); |
| 2384 | 179 | } | |
| 2385 | |||
| 2386 |
3/5✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
4 | Workspace::Workspace(StrictnessLevel level) : m_impl(new detail::Workspace_Impl(level, IddFileType(IddFileType::EnergyPlus))) { |
| 2387 |
1/1✓ Branch 1 taken 3 times.
|
4 | addVersionObject(); |
| 2388 | 4 | } | |
| 2389 | |||
| 2390 |
2/4✓ Branch 2 taken 1561 times.
✓ Branch 5 taken 1561 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1561 | Workspace::Workspace(StrictnessLevel level, IddFileType iddFileType) : m_impl(new detail::Workspace_Impl(level, iddFileType)) { |
| 2391 |
1/1✓ Branch 1 taken 1561 times.
|
1561 | addVersionObject(); |
| 2392 | 1561 | } | |
| 2393 | |||
| 2394 |
2/4✓ Branch 2 taken 241 times.
✓ Branch 5 taken 241 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
241 | Workspace::Workspace(const IdfFile& idfFile, StrictnessLevel level) : m_impl(new detail::Workspace_Impl(idfFile, level)) { |
| 2395 | // construct WorkspaceObject_ImplPtrs | ||
| 2396 | 241 | openstudio::detail::WorkspaceObject_ImplPtrVector objectImplPtrs; | |
| 2397 |
2/3✓ Branch 1 taken 241 times.
✓ Branch 3 taken 241 times.
✗ Branch 4 not taken.
|
482 | if (OptionalIdfObject vo = idfFile.versionObject()) { |
| 2398 |
3/3✓ Branch 2 taken 241 times.
✓ Branch 5 taken 241 times.
✓ Branch 8 taken 241 times.
|
241 | objectImplPtrs.push_back(m_impl->createObject(*vo, true)); |
| 2399 | 241 | } | |
| 2400 |
3/3✓ Branch 1 taken 241 times.
✓ Branch 7 taken 90824 times.
✓ Branch 8 taken 241 times.
|
91065 | for (const IdfObject& idfObject : idfFile.objects()) { |
| 2401 |
2/2✓ Branch 2 taken 90824 times.
✓ Branch 5 taken 90824 times.
|
90824 | objectImplPtrs.push_back(m_impl->createObject(idfObject, true)); |
| 2402 | 241 | } | |
| 2403 | // add Object_ImplPtrs to Workspace_Impl | ||
| 2404 |
1/1✓ Branch 2 taken 241 times.
|
241 | m_impl->addObjects(objectImplPtrs, false); |
| 2405 |
1/1✓ Branch 2 taken 241 times.
|
241 | Workspace copyOfThis(m_impl); |
| 2406 |
1/1✓ Branch 2 taken 241 times.
|
241 | m_impl->resolvePotentialNameConflicts(copyOfThis); |
| 2407 | 241 | } | |
| 2408 | |||
| 2409 | 37047 | Workspace::Workspace(const Workspace& other) = default; | |
| 2410 | |||
| 2411 | 1230 | Workspace Workspace::clone(bool keepHandles) const { | |
| 2412 | 1230 | Workspace result = m_impl->clone(keepHandles); | |
| 2413 | 1230 | return result; | |
| 2414 | } | ||
| 2415 | |||
| 2416 | ✗ | Workspace Workspace::cloneSubset(const std::vector<Handle>& handles, bool keepHandles, StrictnessLevel level) const { | |
| 2417 | ✗ | Workspace result = m_impl->cloneSubset(handles, keepHandles, level); | |
| 2418 | ✗ | result.addVersionObject(); | |
| 2419 | ✗ | return result; | |
| 2420 | ✗ | } | |
| 2421 | |||
| 2422 | 7 | void Workspace::swap(Workspace& other) { | |
| 2423 | // Can't do typeid(*(m_impl.get())) comparison due to -Wpotentially-evaluated-expression warning with clang | ||
| 2424 | // Operator* is equivalent to *get() | ||
| 2425 | 7 | auto& o1 = *m_impl; | |
| 2426 | 7 | auto& o2 = *(other.m_impl); | |
| 2427 | |||
| 2428 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1 time.
|
7 | if ((typeid(o1)) != typeid(o2)) { |
| 2429 |
15/15✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 22 taken 6 times.
✓ Branch 25 taken 6 times.
✓ Branch 28 taken 6 times.
✓ Branch 31 taken 6 times.
✓ Branch 34 taken 6 times.
✓ Branch 37 taken 6 times.
✓ Branch 40 taken 6 times.
✓ Branch 44 taken 6 times.
✓ Branch 47 taken 6 times.
|
6 | LOG_AND_THROW("Workspaces can only be swapped if they are both of the same type " << "(both Workspaces, both Models, or both Components)."); |
| 2430 | } | ||
| 2431 | 1 | m_impl->swap(other); | |
| 2432 | 1 | } | |
| 2433 | |||
| 2434 | // GETTERS | ||
| 2435 | |||
| 2436 | 3307 | StrictnessLevel Workspace::strictnessLevel() const { | |
| 2437 | 3307 | return m_impl->strictnessLevel(); | |
| 2438 | } | ||
| 2439 | |||
| 2440 | ✗ | VersionString Workspace::version() const { | |
| 2441 | ✗ | return m_impl->version(); | |
| 2442 | } | ||
| 2443 | |||
| 2444 | 1 | IddFile Workspace::iddFile() const { | |
| 2445 | 1 | return m_impl->iddFile(); | |
| 2446 | } | ||
| 2447 | |||
| 2448 | 258 | IddFileType Workspace::iddFileType() const { | |
| 2449 | 258 | return m_impl->iddFileType(); | |
| 2450 | } | ||
| 2451 | |||
| 2452 | ✗ | boost::optional<IddObject> Workspace::getIddObject(const IddObjectType& type) const { | |
| 2453 | ✗ | return m_impl->getIddObject(type); | |
| 2454 | } | ||
| 2455 | |||
| 2456 | ✗ | boost::optional<std::string> Workspace::name(const Handle& handle) const { | |
| 2457 | ✗ | return m_impl->name(handle); | |
| 2458 | } | ||
| 2459 | |||
| 2460 | 7985675 | boost::optional<WorkspaceObject> Workspace::getObject(Handle handle) const { | |
| 2461 | 7985675 | auto const result = m_impl->getObject(handle); | |
| 2462 |
2/2✓ Branch 0 taken 7973214 times.
✓ Branch 1 taken 12461 times.
|
7985675 | if (result) { |
| 2463 |
3/5✓ Branch 1 taken 7973214 times.
✓ Branch 4 taken 7973214 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7973214 times.
✗ Branch 9 not taken.
|
7973214 | OS_ASSERT(result->initialized()); |
| 2464 | } | ||
| 2465 | 7985675 | return result; | |
| 2466 | ✗ | } | |
| 2467 | |||
| 2468 | 17869 | std::vector<WorkspaceObject> Workspace::objects(bool sorted) const { | |
| 2469 | 17869 | return m_impl->objects(sorted); | |
| 2470 | } | ||
| 2471 | |||
| 2472 | 8 | std::vector<Handle> Workspace::handles(bool sorted) const { | |
| 2473 | 8 | return m_impl->handles(sorted); | |
| 2474 | } | ||
| 2475 | |||
| 2476 | 1 | std::vector<WorkspaceObject> Workspace::objectsWithURLFields() const { | |
| 2477 | 1 | return m_impl->objectsWithURLFields(); | |
| 2478 | } | ||
| 2479 | |||
| 2480 | 2820 | boost::optional<WorkspaceObject> Workspace::versionObject() const { | |
| 2481 | 2820 | return m_impl->versionObject(); | |
| 2482 | } | ||
| 2483 | |||
| 2484 | ✗ | std::vector<WorkspaceObject> Workspace::getObjects(const std::vector<Handle>& handles) const { | |
| 2485 | ✗ | return m_impl->getObjects(handles); | |
| 2486 | } | ||
| 2487 | |||
| 2488 | 807 | std::vector<WorkspaceObject> Workspace::getObjectsByName(const std::string& name, bool exactMatch) const { | |
| 2489 | 807 | return m_impl->getObjectsByName(name, exactMatch); | |
| 2490 | } | ||
| 2491 | |||
| 2492 | 399224 | std::vector<WorkspaceObject> Workspace::getObjectsByType(IddObjectType objectType) const { | |
| 2493 | 399224 | return m_impl->getObjectsByType(objectType); | |
| 2494 | } | ||
| 2495 | |||
| 2496 | 84 | std::vector<WorkspaceObject> Workspace::getObjectsByType(const IddObject& objectType) const { | |
| 2497 | 84 | return m_impl->getObjectsByType(objectType); | |
| 2498 | } | ||
| 2499 | |||
| 2500 | 3880 | boost::optional<WorkspaceObject> Workspace::getObjectByTypeAndName(IddObjectType objectType, const std::string& name) const { | |
| 2501 | 3880 | return m_impl->getObjectByTypeAndName(objectType, name); | |
| 2502 | } | ||
| 2503 | |||
| 2504 | 3282 | std::vector<WorkspaceObject> Workspace::getObjectsByTypeAndName(IddObjectType objectType, const std::string& name) const { | |
| 2505 | 3282 | return m_impl->getObjectsByTypeAndName(objectType, name); | |
| 2506 | } | ||
| 2507 | |||
| 2508 | 3 | std::vector<WorkspaceObject> Workspace::getObjectsByReference(const std::string& referenceName) const { | |
| 2509 | 3 | return m_impl->getObjectsByReference(referenceName); | |
| 2510 | } | ||
| 2511 | |||
| 2512 | ✗ | std::vector<WorkspaceObject> Workspace::getObjectsByReference(const std::vector<std::string>& referenceNames) const { | |
| 2513 | ✗ | return m_impl->getObjectsByReference(referenceNames); | |
| 2514 | } | ||
| 2515 | |||
| 2516 | ✗ | boost::optional<WorkspaceObject> Workspace::getObjectByNameAndReference(const std::string& name, const StringVector& referenceNames) const { | |
| 2517 | ✗ | return m_impl->getObjectByNameAndReference(name, referenceNames); | |
| 2518 | } | ||
| 2519 | |||
| 2520 | 5 | bool Workspace::fastNaming() const { | |
| 2521 | 5 | return m_impl->fastNaming(); | |
| 2522 | } | ||
| 2523 | |||
| 2524 | // SETTERS | ||
| 2525 | |||
| 2526 | 185 | bool Workspace::setStrictnessLevel(StrictnessLevel level) { | |
| 2527 | 185 | return m_impl->setStrictnessLevel(level); | |
| 2528 | } | ||
| 2529 | |||
| 2530 | 1713 | boost::optional<WorkspaceObject> Workspace::addObject(const IdfObject& idfObject) { | |
| 2531 | 1713 | return m_impl->addObject(idfObject); | |
| 2532 | } | ||
| 2533 | |||
| 2534 | ✗ | boost::optional<WorkspaceObject> Workspace::insertObject(const IdfObject& idfObject) { | |
| 2535 | ✗ | return m_impl->insertObject(idfObject); | |
| 2536 | } | ||
| 2537 | |||
| 2538 | 955 | std::vector<WorkspaceObject> Workspace::addObjects(const std::vector<IdfObject>& idfObjects, bool checkNames) { | |
| 2539 | 955 | return m_impl->addObjects(idfObjects, checkNames); | |
| 2540 | } | ||
| 2541 | |||
| 2542 | 4 | std::vector<WorkspaceObject> Workspace::insertObjects(const std::vector<IdfObject>& idfObjects) { | |
| 2543 | 4 | return m_impl->insertObjects(idfObjects); | |
| 2544 | } | ||
| 2545 | |||
| 2546 | 1 | std::vector<WorkspaceObject> Workspace::addAndInsertObjects(const std::vector<IdfObject>& objectsToAdd, | |
| 2547 | const std::vector<IdfObject>& objectsToInsert) { | ||
| 2548 | 1 | return m_impl->addAndInsertObjects(objectsToAdd, objectsToInsert); | |
| 2549 | } | ||
| 2550 | |||
| 2551 | 9673 | std::vector<WorkspaceObject> Workspace::addObjects(const std::vector<WorkspaceObject>& objects, bool checkNames) { | |
| 2552 | 9673 | return m_impl->addObjects(objects, checkNames); | |
| 2553 | } | ||
| 2554 | |||
| 2555 | 1 | std::vector<WorkspaceObject> Workspace::insertObjects(const std::vector<WorkspaceObject>& objects) { | |
| 2556 | 1 | return m_impl->insertObjects(objects); | |
| 2557 | } | ||
| 2558 | |||
| 2559 | 8151 | std::vector<WorkspaceObject> Workspace::addAndInsertObjects(const std::vector<WorkspaceObject>& objectsToAdd, | |
| 2560 | const std::vector<WorkspaceObject>& objectsToInsert) { | ||
| 2561 | 8151 | return m_impl->addAndInsertObjects(objectsToAdd, objectsToInsert); | |
| 2562 | } | ||
| 2563 | |||
| 2564 | 1500 | std::vector<WorkspaceObject> Workspace::addAndInsertObjects(const std::vector<WorkspaceObject>& objectsToAdd, | |
| 2565 | const std::vector<std::vector<WorkspaceObject>>& objectsToInsert) { | ||
| 2566 | 1500 | return m_impl->addAndInsertObjects(objectsToAdd, objectsToInsert); | |
| 2567 | } | ||
| 2568 | |||
| 2569 | 93 | bool Workspace::swap(WorkspaceObject& currentObject, IdfObject& newObject, bool keepTargets) { | |
| 2570 | 93 | return m_impl->swap(currentObject, newObject, keepTargets); | |
| 2571 | } | ||
| 2572 | |||
| 2573 | 6148 | bool Workspace::removeObject(const Handle& handle) { | |
| 2574 | 6148 | return m_impl->removeObject(handle); | |
| 2575 | } | ||
| 2576 | |||
| 2577 | 1791 | bool Workspace::removeObjects(const std::vector<Handle>& handles) { | |
| 2578 | 1791 | return m_impl->removeObjects(handles); | |
| 2579 | } | ||
| 2580 | |||
| 2581 | 2386 | void Workspace::setFastNaming(bool fastNaming) { | |
| 2582 | 2386 | m_impl->setFastNaming(fastNaming); | |
| 2583 | 2386 | } | |
| 2584 | |||
| 2585 | // ORDER | ||
| 2586 | |||
| 2587 | 13080 | WorkspaceObjectOrder Workspace::order() { | |
| 2588 | 13080 | return m_impl->order(); | |
| 2589 | } | ||
| 2590 | |||
| 2591 | ✗ | const WorkspaceObjectOrder Workspace::order() const { | |
| 2592 | ✗ | return m_impl->order(); | |
| 2593 | } | ||
| 2594 | |||
| 2595 | 2 | std::vector<WorkspaceObject> Workspace::sort(const std::vector<WorkspaceObject>& objects) const { | |
| 2596 | 2 | return m_impl->sort(objects); | |
| 2597 | } | ||
| 2598 | |||
| 2599 | ✗ | std::vector<Handle> Workspace::sort(const std::vector<Handle>& handles) const { | |
| 2600 | ✗ | return m_impl->sort(handles); | |
| 2601 | } | ||
| 2602 | |||
| 2603 | // QUERIES | ||
| 2604 | |||
| 2605 | 549 | unsigned Workspace::numObjects() const { | |
| 2606 | 549 | return m_impl->numObjects(); | |
| 2607 | } | ||
| 2608 | |||
| 2609 | 50 | unsigned Workspace::numObjectsOfType(IddObjectType type) const { | |
| 2610 | 50 | return m_impl->numObjectsOfType(type); | |
| 2611 | } | ||
| 2612 | |||
| 2613 | ✗ | unsigned Workspace::numObjectsOfType(const IddObject& objectType) const { | |
| 2614 | ✗ | return m_impl->numObjectsOfType(objectType); | |
| 2615 | } | ||
| 2616 | |||
| 2617 | 217291 | bool Workspace::isMember(const Handle& handle) const { | |
| 2618 | 217291 | return m_impl->isMember(handle); | |
| 2619 | } | ||
| 2620 | |||
| 2621 | ✗ | bool Workspace::canBeTarget(const Handle& handle, const StringSet& referenceListNames) const { | |
| 2622 | ✗ | return m_impl->canBeTarget(handle, referenceListNames); | |
| 2623 | } | ||
| 2624 | |||
| 2625 | ✗ | bool Workspace::isInIddFile(IddObjectType type) const { | |
| 2626 | ✗ | return m_impl->isInIddFile(type); | |
| 2627 | } | ||
| 2628 | |||
| 2629 | 2372 | std::string Workspace::nextName(const std::string& name, bool fillIn) const { | |
| 2630 | 2372 | return m_impl->nextName(name, fillIn); | |
| 2631 | } | ||
| 2632 | |||
| 2633 | 117543 | std::string Workspace::nextName(const IddObjectType& iddObjectType, bool fillIn) const { | |
| 2634 | 117543 | return m_impl->nextName(iddObjectType, fillIn); | |
| 2635 | } | ||
| 2636 | |||
| 2637 | 5 | bool Workspace::isValid() const { | |
| 2638 | 5 | return m_impl->isValid(); | |
| 2639 | } | ||
| 2640 | |||
| 2641 | 197 | bool Workspace::isValid(StrictnessLevel level) const { | |
| 2642 |
5/5✓ Branch 1 taken 197 times.
✓ Branch 4 taken 197 times.
✓ Branch 7 taken 197 times.
✓ Branch 10 taken 197 times.
✓ Branch 13 taken 197 times.
|
197 | LOG(Debug, "Workspace::isValid called."); |
| 2643 | 197 | return m_impl->isValid(level); | |
| 2644 | } | ||
| 2645 | |||
| 2646 | ✗ | ValidityReport Workspace::validityReport() const { | |
| 2647 | ✗ | return m_impl->validityReport(); | |
| 2648 | } | ||
| 2649 | |||
| 2650 | 9 | ValidityReport Workspace::validityReport(StrictnessLevel level) const { | |
| 2651 | 9 | return m_impl->validityReport(level); | |
| 2652 | } | ||
| 2653 | |||
| 2654 | 21471 | bool Workspace::operator==(const Workspace& other) const { | |
| 2655 | 21471 | return (m_impl == other.m_impl); | |
| 2656 | } | ||
| 2657 | |||
| 2658 | ✗ | bool Workspace::operator!=(const Workspace& other) const { | |
| 2659 | ✗ | return !(operator==(other)); | |
| 2660 | } | ||
| 2661 | |||
| 2662 | // connect a progress bar | ||
| 2663 | ✗ | bool Workspace::connectProgressBar(openstudio::ProgressBar& progressBar) { | |
| 2664 | ✗ | m_impl.get()->progressRange.connect<ProgressBar, &ProgressBar::setRange>(&progressBar); | |
| 2665 | ✗ | m_impl.get()->progressValue.connect<ProgressBar, &ProgressBar::setValue>(&progressBar); | |
| 2666 | ✗ | m_impl.get()->progressCaption.connect<ProgressBar, &ProgressBar::setWindowTitle>(&progressBar); | |
| 2667 | |||
| 2668 | // result = result && progressBar.connect(m_impl.get(), SIGNAL(progressRange(int, int)), SLOT(setRange(int, int))); | ||
| 2669 | // result = result && progressBar.connect(m_impl.get(), SIGNAL(progressValue(int)), SLOT(setValue(int))); | ||
| 2670 | // result = result && progressBar.connect(m_impl.get(), SIGNAL(progressCaption(const QString&)), SLOT(setWindowTitle(const QString&))); | ||
| 2671 | ✗ | return true; | |
| 2672 | } | ||
| 2673 | |||
| 2674 | // disconnect a progress bar | ||
| 2675 | ✗ | bool Workspace::disconnectProgressBar(openstudio::ProgressBar& progressBar) { | |
| 2676 | |||
| 2677 | ✗ | m_impl.get()->progressRange.disconnect<ProgressBar, &ProgressBar::setRange>(&progressBar); | |
| 2678 | ✗ | m_impl.get()->progressValue.disconnect<ProgressBar, &ProgressBar::setValue>(&progressBar); | |
| 2679 | ✗ | m_impl.get()->progressCaption.disconnect<ProgressBar, &ProgressBar::setWindowTitle>(&progressBar); | |
| 2680 | |||
| 2681 | ✗ | return true; /* m_impl.get()->disconnect(&progressBar); */ | |
| 2682 | } | ||
| 2683 | |||
| 2684 | // SERIALIZATION | ||
| 2685 | |||
| 2686 | 345 | bool Workspace::save(const openstudio::path& p, bool overwrite) { | |
| 2687 | 345 | return m_impl->save(p, overwrite); | |
| 2688 | } | ||
| 2689 | |||
| 2690 | 16 | boost::optional<Workspace> Workspace::load(const openstudio::path& p) { | |
| 2691 |
1/1✓ Branch 1 taken 16 times.
|
16 | OptionalIdfFile oIdfFile = IdfFile::load(p); |
| 2692 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (oIdfFile) { |
| 2693 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
|
14 | return Workspace(*oIdfFile); |
| 2694 | } | ||
| 2695 | 2 | return boost::none; | |
| 2696 | 16 | } | |
| 2697 | |||
| 2698 | ✗ | boost::optional<Workspace> Workspace::load(const openstudio::path& p, const IddFileType& iddFileType) { | |
| 2699 | ✗ | OptionalIdfFile oIdfFile = IdfFile::load(p, iddFileType); | |
| 2700 | ✗ | if (oIdfFile) { | |
| 2701 | ✗ | return Workspace(*oIdfFile); | |
| 2702 | } | ||
| 2703 | ✗ | return boost::none; | |
| 2704 | ✗ | } | |
| 2705 | |||
| 2706 | ✗ | boost::optional<Workspace> Workspace::load(const openstudio::path& p, const IddFile& iddFile) { | |
| 2707 | ✗ | OptionalIdfFile oIdfFile = IdfFile::load(p, iddFile); | |
| 2708 | ✗ | if (oIdfFile) { | |
| 2709 | ✗ | return Workspace(*oIdfFile); | |
| 2710 | } | ||
| 2711 | ✗ | return boost::none; | |
| 2712 | ✗ | } | |
| 2713 | |||
| 2714 | 217 | IdfFile Workspace::toIdfFile() const { | |
| 2715 | 217 | return m_impl->toIdfFile(); | |
| 2716 | } | ||
| 2717 | |||
| 2718 | // OVERLOADED FUNCTIONS THAT TAKE IN A std::string INSTEAD OF AN IddObjecTtype | ||
| 2719 | |||
| 2720 | 220 | std::vector<WorkspaceObject> Workspace::getObjectsByType(const std::string& objectTypeName) const { | |
| 2721 |
2/2✓ Branch 1 taken 218 times.
✓ Branch 4 taken 218 times.
|
220 | return getObjectsByType(IddObjectType(objectTypeName)); |
| 2722 | } | ||
| 2723 | |||
| 2724 | 16 | boost::optional<WorkspaceObject> Workspace::getObjectByTypeAndName(const std::string& objectTypeName, const std::string& name) const { | |
| 2725 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
16 | return getObjectByTypeAndName(IddObjectType(objectTypeName), name); |
| 2726 | } | ||
| 2727 | |||
| 2728 | 3 | std::vector<WorkspaceObject> Workspace::getObjectsByTypeAndName(const std::string& objectTypeName, const std::string& name) const { | |
| 2729 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
3 | return getObjectsByTypeAndName(IddObjectType(objectTypeName), name); |
| 2730 | } | ||
| 2731 | |||
| 2732 | // PROTECTED | ||
| 2733 | |||
| 2734 | 9179476 | Workspace::Workspace(std::shared_ptr<detail::Workspace_Impl> impl) : m_impl(impl) {} | |
| 2735 | |||
| 2736 | ✗ | std::vector<WorkspaceObject> Workspace::allObjects() const { | |
| 2737 | ✗ | return m_impl->allObjects(); | |
| 2738 | } | ||
| 2739 | |||
| 2740 | 1744 | void Workspace::addVersionObject() { | |
| 2741 |
2/3✓ Branch 1 taken 1744 times.
✓ Branch 5 taken 1744 times.
✗ Branch 6 not taken.
|
1744 | if (!versionObject()) { |
| 2742 |
1/1✓ Branch 2 taken 1744 times.
|
1744 | IdfObject idfVersionObject = m_impl->versionObjectToAdd(); |
| 2743 | 1744 | openstudio::detail::WorkspaceObject_ImplPtrVector objectImplPtrs; | |
| 2744 |
2/2✓ Branch 2 taken 1744 times.
✓ Branch 5 taken 1744 times.
|
1744 | objectImplPtrs.push_back(m_impl->createObject(idfVersionObject, false)); |
| 2745 |
1/1✓ Branch 4 taken 1744 times.
|
1744 | WorkspaceObjectVector objects = m_impl->addObjects(objectImplPtrs); |
| 2746 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1743 times.
|
1744 | if (objects.size() != 1u) { |
| 2747 |
13/13✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
|
1 | LOG_AND_THROW("Unable to add version object to Workspace.") |
| 2748 | } | ||
| 2749 | 1746 | } | |
| 2750 | 1743 | } | |
| 2751 | |||
| 2752 | 39 | std::ostream& operator<<(std::ostream& os, const Workspace& workspace) { | |
| 2753 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | os << workspace.toIdfFile(); |
| 2754 | 39 | return os; | |
| 2755 | } | ||
| 2756 | |||
| 2757 | } // namespace openstudio | ||
| 2758 |