src/utilities/idf/WorkspaceObject.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 "WorkspaceObject.hpp" | ||
| 7 | |||
| 8 | #include "Workspace.hpp" | ||
| 9 | #include "Workspace_Impl.hpp" | ||
| 10 | #include "WorkspaceObjectDiff.hpp" | ||
| 11 | #include "WorkspaceObjectDiff_Impl.hpp" | ||
| 12 | #include "WorkspaceExtensibleGroup.hpp" | ||
| 13 | #include "ValidityReport.hpp" | ||
| 14 | |||
| 15 | #include <utilities/idd/IddEnums.hxx> | ||
| 16 | |||
| 17 | #include "../core/Assert.hpp" | ||
| 18 | #include "../core/StringHelpers.hpp" | ||
| 19 | |||
| 20 | using namespace std; | ||
| 21 | |||
| 22 | using openstudio::detail::WorkspaceObject_Impl; | ||
| 23 | using std::dynamic_pointer_cast; | ||
| 24 | |||
| 25 | namespace openstudio { | ||
| 26 | |||
| 27 | namespace detail { | ||
| 28 | |||
| 29 | // CONSTRUCTORS | ||
| 30 | |||
| 31 | 392163 | WorkspaceObject_Impl::WorkspaceObject_Impl(const IdfObject& idfObject, Workspace_Impl* workspace, bool keepHandle) | |
| 32 | 784326 | : IdfObject_Impl(*(idfObject.getImpl<detail::IdfObject_Impl>()), keepHandle), // clones idfObject data | |
| 33 | 392163 | m_initialized(false), | |
| 34 |
1/1✓ Branch 2 taken 392163 times.
|
1176489 | m_workspace(workspace) { |
| 35 |
3/3✓ Branch 1 taken 392163 times.
✓ Branch 5 taken 301981 times.
✓ Branch 6 taken 90182 times.
|
392163 | if (!m_iddObject.objectLists().empty()) { |
| 36 | // can nominally be source | ||
| 37 |
1/1✓ Branch 2 taken 301981 times.
|
301981 | m_sourceData = SourceData(); |
| 38 | } | ||
| 39 |
12/17✓ Branch 1 taken 392163 times.
✓ Branch 4 taken 295880 times.
✓ Branch 5 taken 96283 times.
✓ Branch 7 taken 295880 times.
✓ Branch 10 taken 295880 times.
✓ Branch 13 taken 117434 times.
✓ Branch 14 taken 178446 times.
✓ Branch 15 taken 295880 times.
✓ Branch 16 taken 96283 times.
✓ Branch 18 taken 392163 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 117434 times.
✓ Branch 22 taken 274729 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
784326 | if (idfObject.name() && idfObject.name(true).get().empty()) { |
| 40 | // create name if their is a name field and no default value | ||
| 41 |
1/1✓ Branch 1 taken 117434 times.
|
117434 | createName(); |
| 42 | } | ||
| 43 | 392163 | } | |
| 44 | |||
| 45 | 180637 | WorkspaceObject_Impl::WorkspaceObject_Impl(const WorkspaceObject_Impl& other, Workspace_Impl* workspace, bool keepHandle) | |
| 46 | : IdfObject_Impl(other, keepHandle), | ||
| 47 | 180637 | m_initialized(false), | |
| 48 | 180637 | m_workspace(workspace), | |
| 49 |
1/1✓ Branch 1 taken 180637 times.
|
180637 | m_sourceData(other.m_sourceData), |
| 50 |
1/1✓ Branch 5 taken 180637 times.
|
361274 | m_targetData(other.m_targetData) {} |
| 51 | |||
| 52 | 5235 | std::vector<IdfObject> WorkspaceObject_Impl::remove() { | |
| 53 | 5235 | std::vector<IdfObject> result; | |
| 54 |
2/2✓ Branch 1 taken 5235 times.
✓ Branch 4 taken 5235 times.
|
5235 | result.push_back(this->idfObject()); |
| 55 |
3/3✓ Branch 1 taken 5235 times.
✓ Branch 4 taken 5235 times.
✓ Branch 7 taken 5235 times.
|
5235 | bool ok = this->workspace().removeObject(this->handle()); |
| 56 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 5235 times.
✗ Branch 3 not taken.
|
5235 | OS_ASSERT(ok); |
| 57 | 5235 | return result; | |
| 58 | ✗ | } | |
| 59 | |||
| 60 | 392254 | void WorkspaceObject_Impl::initializeOnAdd(bool expectToLosePointers) { | |
| 61 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 392254 times.
✗ Branch 3 not taken.
|
392254 | OS_ASSERT(m_workspace); |
| 62 |
2/2✓ Branch 1 taken 392254 times.
✓ Branch 4 taken 392254 times.
|
392254 | bool ptrsAsHandles = iddObject().hasHandleField(); |
| 63 | // loop through object list fields | ||
| 64 |
1/1✓ Branch 1 taken 392254 times.
|
392254 | UnsignedVector fields = objectListFields(); |
| 65 |
2/2✓ Branch 5 taken 752248 times.
✓ Branch 6 taken 392254 times.
|
1144502 | for (unsigned index : fields) { |
| 66 | // determine if field should be managed | ||
| 67 |
2/2✓ Branch 1 taken 752248 times.
✓ Branch 4 taken 752248 times.
|
752248 | OptionalIddField iddField = iddObject().getField(index); |
| 68 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 752248 times.
✗ Branch 4 not taken.
|
752248 | OS_ASSERT(iddField); |
| 69 | |||
| 70 | // for each one, try to match targetName | ||
| 71 |
3/3✓ Branch 1 taken 752248 times.
✓ Branch 4 taken 752248 times.
✓ Branch 7 taken 752248 times.
|
752248 | std::string targetName = IdfObject_Impl::getString(index).get(); |
| 72 |
2/2✓ Branch 1 taken 462367 times.
✓ Branch 2 taken 289881 times.
|
752248 | if (targetName.empty()) { // set null pointer |
| 73 |
2/2✓ Branch 1 taken 462367 times.
✓ Branch 4 taken 462367 times.
|
462367 | setPointerImpl(index, Handle()); |
| 74 | 462367 | continue; | |
| 75 | } | ||
| 76 | |||
| 77 | // look for target | ||
| 78 |
1/1✓ Branch 1 taken 289881 times.
|
289881 | Handle targetHandle; |
| 79 |
2/2✓ Branch 0 taken 217280 times.
✓ Branch 1 taken 72601 times.
|
289881 | if (ptrsAsHandles) { |
| 80 |
1/1✓ Branch 1 taken 217280 times.
|
217280 | targetHandle = toUUID(targetName); |
| 81 |
4/4✓ Branch 1 taken 217280 times.
✓ Branch 4 taken 217280 times.
✓ Branch 7 taken 46 times.
✓ Branch 8 taken 217234 times.
|
217280 | if (!workspace().isMember(targetHandle)) { |
| 82 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | if (!expectToLosePointers) { |
| 83 |
15/15✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
✓ Branch 7 taken 46 times.
✓ Branch 10 taken 46 times.
✓ Branch 13 taken 46 times.
✓ Branch 16 taken 46 times.
✓ Branch 19 taken 46 times.
✓ Branch 22 taken 46 times.
✓ Branch 25 taken 46 times.
✓ Branch 28 taken 46 times.
✓ Branch 31 taken 46 times.
✓ Branch 34 taken 46 times.
✓ Branch 40 taken 46 times.
✓ Branch 43 taken 46 times.
✓ Branch 46 taken 46 times.
|
46 | LOG(Trace, "Field " << index << " of '" << iddObject().name() << "' object points to an object with handle " << toString(targetHandle) |
| 84 | << ", but there is not object with that handle in the Workspace. Will try to " << "interpret as a name."); | ||
| 85 | } | ||
| 86 |
1/1✓ Branch 1 taken 46 times.
|
46 | targetHandle = Handle(); |
| 87 | } | ||
| 88 | } | ||
| 89 |
2/2✓ Branch 1 taken 72647 times.
✓ Branch 2 taken 217234 times.
|
289881 | if (targetHandle.isNull()) { |
| 90 |
2/2✓ Branch 1 taken 72647 times.
✓ Branch 4 taken 72647 times.
|
72647 | StringSet intermediate = iddObject().objectLists(index); |
| 91 |
1/1✓ Branch 3 taken 72647 times.
|
72647 | StringVector referenceLists(intermediate.begin(), intermediate.end()); |
| 92 |
1/1✓ Branch 1 taken 72647 times.
|
72647 | OptionalWorkspaceObject target = m_workspace->getObjectByNameAndReference(targetName, referenceLists); |
| 93 |
2/2✓ Branch 0 taken 72409 times.
✓ Branch 1 taken 238 times.
|
72647 | if (target) { |
| 94 |
2/2✓ Branch 1 taken 72409 times.
✓ Branch 4 taken 72409 times.
|
72409 | targetHandle = target->handle(); |
| 95 | } | ||
| 96 | 72647 | } | |
| 97 |
1/1✓ Branch 1 taken 289881 times.
|
289881 | setPointerImpl(index, targetHandle); |
| 98 |
2/2✓ Branch 1 taken 238 times.
✓ Branch 2 taken 289643 times.
|
289881 | if (targetHandle.isNull()) { |
| 99 |
2/2✓ Branch 0 taken 235 times.
✓ Branch 1 taken 3 times.
|
238 | if (!expectToLosePointers) { |
| 100 |
11/11✓ Branch 1 taken 235 times.
✓ Branch 4 taken 235 times.
✓ Branch 7 taken 235 times.
✓ Branch 10 taken 235 times.
✓ Branch 13 taken 235 times.
✓ Branch 16 taken 235 times.
✓ Branch 19 taken 235 times.
✓ Branch 22 taken 235 times.
✓ Branch 26 taken 235 times.
✓ Branch 29 taken 235 times.
✓ Branch 32 taken 235 times.
|
235 | LOG(Warn, briefDescription() << ", points to an object named " << targetName << " from field " << index |
| 101 | << ", but that object cannot be located."); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | 1214615 | } | |
| 105 | 392254 | } | |
| 106 | |||
| 107 | 41865 | void WorkspaceObject_Impl::initializeOnClone(const HandleMap& oldNewHandleMap) { | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41865 times.
|
41865 | OS_ASSERT(m_workspace); |
| 109 |
2/2✓ Branch 1 taken 26311 times.
✓ Branch 2 taken 15554 times.
|
83730 | if (m_sourceData) { |
| 110 | 26311 | SourceData::pointer_set mappedPointers; | |
| 111 |
3/3✓ Branch 1 taken 26311 times.
✓ Branch 8 taken 63262 times.
✓ Branch 9 taken 26311 times.
|
89573 | for (const ForwardPointer& fp : m_sourceData->pointers) { |
| 112 |
1/1✓ Branch 1 taken 63262 times.
|
63262 | Handle th = openstudio::applyHandleMap(fp.targetHandle, oldNewHandleMap); |
| 113 |
7/8✓ Branch 1 taken 50038 times.
✓ Branch 2 taken 13224 times.
✓ Branch 4 taken 9676 times.
✓ Branch 5 taken 40362 times.
✓ Branch 7 taken 9676 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 9676 times.
✓ Branch 10 taken 53586 times.
|
63262 | if (th.isNull() && !fp.targetHandle.isNull() && !oldNewHandleMap.empty()) { |
| 114 | // if cloned object is also in this workspace, and fp.targetHandle not in | ||
| 115 | // the map, may be in the workspace | ||
| 116 |
2/2✓ Branch 1 taken 9676 times.
✓ Branch 4 taken 9676 times.
|
9676 | OptionalWorkspaceObject target = workspace().getObject(fp.targetHandle); |
| 117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9676 times.
|
9676 | if (target) { |
| 118 | // need to set reverse pointer | ||
| 119 | ✗ | target->getImpl<WorkspaceObject_Impl>()->setReversePointer(handle(), fp.fieldIndex); | |
| 120 | ✗ | th = fp.targetHandle; | |
| 121 | } | ||
| 122 | 9676 | } | |
| 123 |
1/1✓ Branch 2 taken 63262 times.
|
63262 | mappedPointers.insert(ForwardPointer(fp.fieldIndex, th)); |
| 124 |
2/2✓ Branch 1 taken 13224 times.
✓ Branch 2 taken 50038 times.
|
63262 | if (!th.isNull()) { |
| 125 |
1/1✓ Branch 1 taken 13224 times.
|
13224 | m_workspace->forwardReferences(m_handle, fp.fieldIndex, th); |
| 126 | } | ||
| 127 | } | ||
| 128 |
2/2✓ Branch 1 taken 26311 times.
✓ Branch 4 taken 26311 times.
|
26311 | m_sourceData->pointers = mappedPointers; |
| 129 | 26311 | } | |
| 130 |
2/2✓ Branch 1 taken 12559 times.
✓ Branch 2 taken 29306 times.
|
83730 | if (m_targetData) { |
| 131 | 12559 | TargetData::pointer_set mappedPointers; | |
| 132 |
3/3✓ Branch 1 taken 12559 times.
✓ Branch 8 taken 33984 times.
✓ Branch 9 taken 12559 times.
|
46543 | for (const ReversePointer& rp : m_targetData->reversePointers) { |
| 133 |
1/1✓ Branch 1 taken 33984 times.
|
33984 | Handle sh = openstudio::applyHandleMap(rp.sourceHandle, oldNewHandleMap); |
| 134 |
2/2✓ Branch 1 taken 13224 times.
✓ Branch 2 taken 20760 times.
|
33984 | if (!sh.isNull()) { |
| 135 |
1/1✓ Branch 2 taken 13224 times.
|
13224 | mappedPointers.insert(ReversePointer(sh, rp.fieldIndex)); |
| 136 | } | ||
| 137 | } | ||
| 138 |
2/2✓ Branch 1 taken 12559 times.
✓ Branch 4 taken 12559 times.
|
12559 | m_targetData->reversePointers = mappedPointers; |
| 139 | 12559 | } | |
| 140 | 41865 | } | |
| 141 | |||
| 142 | // GETTERS | ||
| 143 | |||
| 144 | 8667244 | Workspace_Impl* WorkspaceObject_Impl::workspaceImpl() const { | |
| 145 | 8667244 | return m_workspace; | |
| 146 | } | ||
| 147 | |||
| 148 | 8667244 | Workspace WorkspaceObject_Impl::workspace() const { | |
| 149 |
3/3✓ Branch 1 taken 8667244 times.
✓ Branch 4 taken 8667244 times.
✓ Branch 7 taken 8667244 times.
|
8667244 | return {workspaceImpl()->shared_from_this()}; |
| 150 | } | ||
| 151 | |||
| 152 | 15431187 | boost::optional<std::string> WorkspaceObject_Impl::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const { | |
| 153 |
9/12✓ Branch 2 taken 15431187 times.
✓ Branch 4 taken 58302 times.
✓ Branch 5 taken 15372885 times.
✓ Branch 7 taken 58302 times.
✓ Branch 9 taken 58177 times.
✓ Branch 10 taken 125 times.
✓ Branch 11 taken 15431187 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 58177 times.
✓ Branch 15 taken 15373010 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
15431187 | if (canBeSource(index) && (index < numFields())) { |
| 154 |
2/3✓ Branch 1 taken 58177 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 58177 times.
|
58177 | if (!initialized()) { |
| 155 | ✗ | return boost::none; | |
| 156 | } | ||
| 157 | |||
| 158 | // pointer field, return name of pointed-to object | ||
| 159 | // TODO: what about when the object doesn't have a name field? | ||
| 160 |
1/1✓ Branch 1 taken 58177 times.
|
58177 | OptionalWorkspaceObject oTarget = getTarget(index); |
| 161 |
2/2✓ Branch 1 taken 29475 times.
✓ Branch 2 taken 28702 times.
|
58177 | if (!oTarget) { |
| 162 | // implicitly or explicitly a null pointer | ||
| 163 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 29436 times.
|
29475 | if (returnDefault) { |
| 164 | // get default from idd and return if exists | ||
| 165 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | OptionalIddField iddField = iddObject().getField(index); |
| 166 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 4 not taken.
|
39 | OS_ASSERT(iddField); |
| 167 |
3/4✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39 times.
|
78 | if (iddField->properties().stringDefault) { |
| 168 | ✗ | return iddField->properties().stringDefault; | |
| 169 | } | ||
| 170 | 39 | } | |
| 171 |
2/2✓ Branch 0 taken 29368 times.
✓ Branch 1 taken 107 times.
|
29475 | if (returnUninitializedEmpty) { |
| 172 | 29368 | return boost::none; | |
| 173 | } | ||
| 174 |
1/1✓ Branch 2 taken 107 times.
|
107 | return std::string(); |
| 175 | } else { | ||
| 176 | // return target's name | ||
| 177 |
4/4✓ Branch 1 taken 28702 times.
✓ Branch 4 taken 28702 times.
✓ Branch 6 taken 28690 times.
✓ Branch 7 taken 12 times.
|
57404 | if (auto s = oTarget->name()) { |
| 178 |
2/2✓ Branch 1 taken 28690 times.
✓ Branch 4 taken 28690 times.
|
28690 | return s.get(); |
| 179 | } else { | ||
| 180 | // Fall back to handle if it doesn't have a name | ||
| 181 |
4/4✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
|
12 | return openstudio::toString(oTarget->handle()); |
| 182 | 28702 | } | |
| 183 | } | ||
| 184 | 58177 | } | |
| 185 | |||
| 186 | // regular field, let IdfObject_Impl take care of it | ||
| 187 | 15373010 | return IdfObject_Impl::getString(index, returnDefault, returnUninitializedEmpty); | |
| 188 | } | ||
| 189 | |||
| 190 | 698483 | boost::optional<std::string> WorkspaceObject_Impl::getField(unsigned index, bool returnDefault) const { | |
| 191 | 698483 | boost::optional<std::string> result; | |
| 192 | |||
| 193 | // IdfObject_Impl::getString won't work if this is a source field... since m_fields will be blank | ||
| 194 | // So we handle that case too | ||
| 195 | |||
| 196 | // If it's a source field: | ||
| 197 |
8/12✓ Branch 2 taken 698483 times.
✓ Branch 4 taken 2016 times.
✓ Branch 5 taken 696467 times.
✓ Branch 7 taken 2016 times.
✓ Branch 9 taken 2016 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 698483 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 2016 times.
✓ Branch 15 taken 696467 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
698483 | if (canBeSource(index) && (index < numFields())) { |
| 198 |
2/3✓ Branch 1 taken 2016 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2016 times.
|
2016 | if (!initialized()) { |
| 199 | ✗ | return boost::none; | |
| 200 | } | ||
| 201 | |||
| 202 |
1/2✓ Branch 1 taken 2016 times.
✗ Branch 2 not taken.
|
4032 | if (m_sourceData) { |
| 203 | // find index and return target if handle not null | ||
| 204 |
2/2✓ Branch 1 taken 2016 times.
✓ Branch 4 taken 2016 times.
|
2016 | auto fpIt = getConstIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 205 |
2/3✓ Branch 1 taken 2016 times.
✓ Branch 5 taken 2016 times.
✗ Branch 6 not taken.
|
2016 | if (fpIt != m_sourceData->pointers.end()) { |
| 206 | 2016 | Handle th = fpIt->targetHandle; | |
| 207 |
2/2✓ Branch 1 taken 1745 times.
✓ Branch 2 taken 271 times.
|
2016 | if (!th.isNull()) { |
| 208 |
2/2✓ Branch 1 taken 1745 times.
✓ Branch 4 taken 1745 times.
|
1745 | result = openstudio::toString(th); |
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | } else { | ||
| 213 | // If not source, then call getString | ||
| 214 |
1/1✓ Branch 1 taken 696467 times.
|
696467 | result = IdfObject_Impl::getString(index, returnDefault, false); |
| 215 | } | ||
| 216 | |||
| 217 | 698483 | return result; | |
| 218 | 698483 | } | |
| 219 | |||
| 220 | 6232946 | OptionalWorkspaceObject WorkspaceObject_Impl::getTarget(unsigned index) const { | |
| 221 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 6232942 times.
|
6232946 | if (!initialized()) { |
| 222 | 4 | return boost::none; | |
| 223 | } | ||
| 224 | |||
| 225 |
1/2✓ Branch 1 taken 6232942 times.
✗ Branch 2 not taken.
|
12465884 | if (m_sourceData) { |
| 226 | // find index and return target if handle not null | ||
| 227 |
2/2✓ Branch 1 taken 6232942 times.
✓ Branch 4 taken 6232942 times.
|
6232942 | auto fpIt = getConstIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 228 |
3/3✓ Branch 1 taken 6232942 times.
✓ Branch 5 taken 6097434 times.
✓ Branch 6 taken 135508 times.
|
6232942 | if (fpIt != m_sourceData->pointers.end()) { |
| 229 | 6097434 | Handle th = fpIt->targetHandle; | |
| 230 |
2/2✓ Branch 1 taken 3182400 times.
✓ Branch 2 taken 2915034 times.
|
6097434 | if (!th.isNull()) { |
| 231 |
2/2✓ Branch 1 taken 3182400 times.
✓ Branch 4 taken 3182400 times.
|
3182400 | return this->workspace().getObject(th); |
| 232 | } | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | 3050542 | return boost::none; | |
| 237 | } | ||
| 238 | |||
| 239 | 31563 | std::vector<WorkspaceObject> WorkspaceObject_Impl::targets() const { | |
| 240 | 31563 | WorkspaceObjectVector result; | |
| 241 |
2/3✓ Branch 1 taken 31563 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31563 times.
|
31563 | if (!initialized()) { |
| 242 | ✗ | return result; | |
| 243 | } | ||
| 244 |
2/2✓ Branch 1 taken 28620 times.
✓ Branch 2 taken 2943 times.
|
63126 | if (m_sourceData) { |
| 245 |
3/3✓ Branch 1 taken 28620 times.
✓ Branch 8 taken 69868 times.
✓ Branch 9 taken 28620 times.
|
98488 | for (const ForwardPointer& ptr : m_sourceData->pointers) { |
| 246 |
2/2✓ Branch 1 taken 20156 times.
✓ Branch 2 taken 49712 times.
|
69868 | if (!ptr.targetHandle.isNull()) { |
| 247 |
2/2✓ Branch 1 taken 20156 times.
✓ Branch 4 taken 20156 times.
|
20156 | OptionalWorkspaceObject owo = this->workspace().getObject(ptr.targetHandle); |
| 248 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 20156 times.
✗ Branch 4 not taken.
|
20156 | OS_ASSERT(owo); |
| 249 |
2/2✓ Branch 1 taken 20156 times.
✓ Branch 4 taken 20156 times.
|
20156 | result.push_back(*owo); |
| 250 | 20156 | } | |
| 251 | } | ||
| 252 | } | ||
| 253 | 31563 | return result; | |
| 254 | ✗ | } | |
| 255 | |||
| 256 | 7440 | std::vector<unsigned> WorkspaceObject_Impl::getSourceIndices(const Handle& targetHandle) const { | |
| 257 | 7440 | UnsignedVector result; | |
| 258 |
1/2✓ Branch 1 taken 7440 times.
✗ Branch 2 not taken.
|
14880 | if (m_sourceData) { |
| 259 |
3/3✓ Branch 1 taken 7440 times.
✓ Branch 8 taken 30719 times.
✓ Branch 9 taken 7440 times.
|
38159 | for (const ForwardPointer& ptr : m_sourceData->pointers) { |
| 260 |
3/3✓ Branch 1 taken 30719 times.
✓ Branch 3 taken 7682 times.
✓ Branch 4 taken 23037 times.
|
30719 | if (ptr.targetHandle == targetHandle) { |
| 261 |
1/1✓ Branch 1 taken 7682 times.
|
7682 | result.push_back(ptr.fieldIndex); |
| 262 | } | ||
| 263 | } | ||
| 264 | } | ||
| 265 | 7440 | return result; | |
| 266 | ✗ | } | |
| 267 | |||
| 268 | 136352 | WorkspaceObjectVector WorkspaceObject_Impl::sources() const { | |
| 269 | 136352 | WorkspaceObjectVector result; | |
| 270 |
3/3✓ Branch 1 taken 136352 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 136348 times.
|
136352 | if (!initialized()) { |
| 271 | 4 | return result; | |
| 272 | } | ||
| 273 |
2/2✓ Branch 1 taken 96076 times.
✓ Branch 2 taken 40272 times.
|
272696 | if (m_targetData) { |
| 274 |
3/3✓ Branch 1 taken 96076 times.
✓ Branch 8 taken 216509 times.
✓ Branch 9 taken 96076 times.
|
312585 | for (const ReversePointer& ptr : m_targetData->reversePointers) { |
| 275 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 216509 times.
✗ Branch 4 not taken.
|
216509 | OS_ASSERT(!ptr.sourceHandle.isNull()); |
| 276 |
2/2✓ Branch 1 taken 216509 times.
✓ Branch 4 taken 216509 times.
|
216509 | OptionalWorkspaceObject owo = this->workspace().getObject(ptr.sourceHandle); |
| 277 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 216509 times.
✗ Branch 4 not taken.
|
216509 | OS_ASSERT(owo); |
| 278 |
2/2✓ Branch 1 taken 216509 times.
✓ Branch 4 taken 216509 times.
|
216509 | result.push_back(*owo); |
| 279 | 216509 | } | |
| 280 |
1/1✓ Branch 3 taken 96076 times.
|
96076 | std::sort(result.begin(), result.end()); |
| 281 |
2/2✓ Branch 5 taken 96076 times.
✓ Branch 9 taken 96076 times.
|
96076 | result.erase(std::unique(result.begin(), result.end()), result.end()); |
| 282 | } | ||
| 283 | 136348 | return result; | |
| 284 | ✗ | } | |
| 285 | |||
| 286 | 2106402 | WorkspaceObjectVector WorkspaceObject_Impl::getSources(IddObjectType type) const { | |
| 287 | 2106402 | WorkspaceObjectVector result; | |
| 288 |
3/3✓ Branch 1 taken 2106402 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2106398 times.
|
2106402 | if (!initialized()) { |
| 289 | 4 | return result; | |
| 290 | } | ||
| 291 |
2/2✓ Branch 1 taken 631362 times.
✓ Branch 2 taken 1475036 times.
|
4212796 | if (m_targetData) { |
| 292 |
3/3✓ Branch 1 taken 631362 times.
✓ Branch 8 taken 4520586 times.
✓ Branch 9 taken 631362 times.
|
5151948 | for (const ReversePointer& ptr : m_targetData->reversePointers) { |
| 293 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4520586 times.
✗ Branch 4 not taken.
|
4520586 | OS_ASSERT(!ptr.sourceHandle.isNull()); |
| 294 |
2/2✓ Branch 1 taken 4520586 times.
✓ Branch 4 taken 4520586 times.
|
4520586 | OptionalWorkspaceObject owo = this->workspace().getObject(ptr.sourceHandle); |
| 295 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4520586 times.
✗ Branch 4 not taken.
|
4520586 | OS_ASSERT(owo); |
| 296 |
5/5✓ Branch 1 taken 4520586 times.
✓ Branch 4 taken 4520586 times.
✓ Branch 7 taken 4520586 times.
✓ Branch 11 taken 1756921 times.
✓ Branch 12 taken 2763665 times.
|
4520586 | if (owo->iddObject().type() == type) { |
| 297 |
2/2✓ Branch 1 taken 1756921 times.
✓ Branch 4 taken 1756921 times.
|
1756921 | result.push_back(*owo); |
| 298 | } | ||
| 299 | 4520586 | } | |
| 300 |
1/1✓ Branch 3 taken 631362 times.
|
631362 | std::sort(result.begin(), result.end()); |
| 301 |
2/2✓ Branch 5 taken 631362 times.
✓ Branch 9 taken 631362 times.
|
631362 | result.erase(std::unique(result.begin(), result.end()), result.end()); |
| 302 | } | ||
| 303 | 2106398 | return result; | |
| 304 | ✗ | } | |
| 305 | |||
| 306 | 9974 | ReversePointerSet WorkspaceObject_Impl::getReversePointers() const { | |
| 307 | 9974 | ReversePointerSet result; | |
| 308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9974 times.
|
9974 | if (m_handle.isNull()) { |
| 309 | ✗ | return result; | |
| 310 | } | ||
| 311 |
2/2✓ Branch 1 taken 7152 times.
✓ Branch 2 taken 2822 times.
|
19948 | if (m_targetData) { |
| 312 |
2/2✓ Branch 1 taken 7152 times.
✓ Branch 4 taken 7152 times.
|
7152 | result = m_targetData->reversePointers; |
| 313 | } | ||
| 314 | 9974 | return result; | |
| 315 | ✗ | } | |
| 316 | |||
| 317 | // SETTERS | ||
| 318 | |||
| 319 | 192693 | boost::optional<std::string> WorkspaceObject_Impl::setName(const std::string& newName) { | |
| 320 | 192693 | boost::optional<std::string> result = setName(newName, true); | |
| 321 |
2/2✓ Branch 0 taken 192635 times.
✓ Branch 1 taken 58 times.
|
192693 | if (result) { |
| 322 |
1/1✓ Branch 1 taken 192635 times.
|
192635 | this->emitChangeSignals(); |
| 323 | } | ||
| 324 | 192693 | return result; | |
| 325 | ✗ | } | |
| 326 | |||
| 327 | 200941 | boost::optional<std::string> WorkspaceObject_Impl::setName(const std::string& newName, bool checkValidity) { | |
| 328 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 200941 times.
|
200941 | if (m_handle.isNull()) { |
| 329 | ✗ | return boost::none; | |
| 330 | } | ||
| 331 |
1/1✓ Branch 1 taken 200941 times.
|
200941 | StrictnessLevel level = m_workspace->strictnessLevel(); |
| 332 | |||
| 333 |
2/2✓ Branch 1 taken 200941 times.
✓ Branch 4 taken 200941 times.
|
200941 | OptionalUnsigned index = iddObject().nameFieldIndex(); |
| 334 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 2 taken 200924 times.
|
200941 | if (!index) { |
| 335 | 17 | return boost::none; | |
| 336 | } | ||
| 337 | |||
| 338 | //if (checkValidity && (level > StrictnessLevel::Minimal)) { // if None or Minimal, we'd get duplicate names | ||
| 339 |
2/2✓ Branch 0 taken 200836 times.
✓ Branch 1 taken 88 times.
|
200924 | if (checkValidity) { |
| 340 | |||
| 341 | // do not set if would violate field NullAndRequired | ||
| 342 |
14/16✓ Branch 1 taken 200836 times.
✓ Branch 4 taken 200349 times.
✓ Branch 5 taken 487 times.
✓ Branch 7 taken 3208 times.
✓ Branch 8 taken 197141 times.
✓ Branch 10 taken 3208 times.
✓ Branch 13 taken 3208 times.
✓ Branch 16 taken 3208 times.
✓ Branch 18 taken 46 times.
✓ Branch 19 taken 3162 times.
✓ Branch 20 taken 3208 times.
✓ Branch 21 taken 197628 times.
✓ Branch 23 taken 46 times.
✓ Branch 24 taken 200790 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
200836 | if ((level >= StrictnessLevel::Draft) && newName.empty() && iddObject().isRequiredField(*index)) { |
| 343 | 46 | return boost::none; | |
| 344 | } | ||
| 345 | |||
| 346 |
1/1✓ Branch 1 taken 200790 times.
|
200790 | OptionalString oldName = name(); |
| 347 |
1/1✓ Branch 1 taken 200790 times.
|
200790 | OptionalString result = IdfObject_Impl::setName(newName, false); |
| 348 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 200790 times.
|
200790 | if (!result) { |
| 349 | ✗ | return result; | |
| 350 | } | ||
| 351 | |||
| 352 | // check collection NameConflict | ||
| 353 |
14/16✓ Branch 1 taken 197627 times.
✓ Branch 2 taken 3163 times.
✓ Branch 4 taken 197627 times.
✓ Branch 7 taken 197627 times.
✓ Branch 10 taken 197627 times.
✓ Branch 12 taken 189917 times.
✓ Branch 13 taken 7710 times.
✓ Branch 15 taken 189917 times.
✓ Branch 17 taken 2372 times.
✓ Branch 18 taken 187545 times.
✓ Branch 19 taken 197627 times.
✓ Branch 20 taken 3163 times.
✓ Branch 22 taken 2372 times.
✓ Branch 23 taken 198418 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
200790 | if (!newName.empty() && iddObject().isRequiredField(*index) && !uniquelyIdentifiableByName()) { |
| 354 |
4/4✓ Branch 1 taken 2372 times.
✓ Branch 4 taken 2372 times.
✓ Branch 7 taken 2372 times.
✓ Branch 10 taken 2372 times.
|
2372 | result = IdfObject_Impl::setName(workspace().nextName(*result, false)); |
| 355 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2372 times.
✗ Branch 4 not taken.
|
2372 | OS_ASSERT(result); |
| 356 | } | ||
| 357 | |||
| 358 | 200790 | return result; | |
| 359 | 200790 | } | |
| 360 | |||
| 361 |
1/1✓ Branch 1 taken 88 times.
|
88 | return IdfObject_Impl::setName(newName, checkValidity); |
| 362 | } | ||
| 363 | |||
| 364 | 117434 | boost::optional<std::string> WorkspaceObject_Impl::createName() { | |
| 365 | 117434 | return createName(true); | |
| 366 | } | ||
| 367 | |||
| 368 | 117531 | boost::optional<std::string> WorkspaceObject_Impl::createName(bool overwrite) { | |
| 369 | 117531 | OptionalString result; | |
| 370 |
3/4✓ Branch 1 taken 117531 times.
✓ Branch 4 taken 117531 times.
✓ Branch 8 taken 117531 times.
✗ Branch 9 not taken.
|
235062 | if (OptionalUnsigned index = iddObject().nameFieldIndex()) { |
| 371 |
1/1✓ Branch 1 taken 117531 times.
|
117531 | OptionalString oName = name(); |
| 372 |
6/9✓ Branch 1 taken 117531 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 117531 times.
✓ Branch 7 taken 97 times.
✓ Branch 8 taken 117434 times.
✓ Branch 9 taken 97 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 117531 times.
✗ Branch 12 not taken.
|
117531 | if (!oName || oName->empty() || overwrite) { |
| 373 |
1/1✓ Branch 1 taken 117531 times.
|
117531 | Workspace workspace = this->workspace(); |
| 374 | |||
| 375 | // determine name, then set | ||
| 376 | 117531 | std::string newName; | |
| 377 |
4/5✓ Branch 1 taken 117531 times.
✓ Branch 4 taken 117531 times.
✓ Branch 7 taken 117531 times.
✓ Branch 11 taken 117531 times.
✗ Branch 12 not taken.
|
117531 | if (iddObject().type() != IddObjectType::UserCustom) { |
| 378 |
3/3✓ Branch 1 taken 117531 times.
✓ Branch 4 taken 117531 times.
✓ Branch 7 taken 117531 times.
|
117531 | newName = workspace.nextName(iddObject().type(), true); |
| 379 | } else { | ||
| 380 | ✗ | newName = iddObjectNameToIdfObjectName(iddObject().name()); | |
| 381 | ✗ | newName = workspace.nextName(newName, true); | |
| 382 | } | ||
| 383 |
1/1✓ Branch 1 taken 117531 times.
|
117531 | result = setName(newName); |
| 384 | 117531 | } | |
| 385 | 117531 | } | |
| 386 | 117531 | return result; | |
| 387 | ✗ | } | |
| 388 | |||
| 389 | 218308 | bool WorkspaceObject_Impl::setString(unsigned index, const std::string& value) { | |
| 390 | 218308 | bool result = setString(index, value, true); | |
| 391 |
2/2✓ Branch 0 taken 218059 times.
✓ Branch 1 taken 249 times.
|
218308 | if (result) { |
| 392 | 218059 | this->emitChangeSignals(); | |
| 393 | } | ||
| 394 | 218308 | return result; | |
| 395 | } | ||
| 396 | |||
| 397 | // Pre-condition: Object valid at Workspace's strictness level. | ||
| 398 | 2372065 | bool WorkspaceObject_Impl::setString(unsigned index, const std::string& value, bool checkValidity) { | |
| 399 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2372065 times.
|
2372065 | if (m_handle.isNull()) { |
| 400 | ✗ | return false; | |
| 401 | } | ||
| 402 |
1/1✓ Branch 1 taken 2372065 times.
|
2372065 | StrictnessLevel level = m_workspace->strictnessLevel(); |
| 403 | |||
| 404 |
3/3✓ Branch 2 taken 2372065 times.
✓ Branch 5 taken 43595 times.
✓ Branch 6 taken 2328470 times.
|
2372065 | if (canBeSource(index)) { |
| 405 | // pointer field | ||
| 406 |
3/3✓ Branch 1 taken 43595 times.
✓ Branch 4 taken 43595 times.
✓ Branch 7 taken 43595 times.
|
43595 | OptionalHandle targetHandle = convertToTargetHandle(value, iddObject().objectLists(index), checkValidity); |
| 407 |
2/2✓ Branch 0 taken 43574 times.
✓ Branch 1 taken 21 times.
|
43595 | if (targetHandle) { |
| 408 |
2/2✓ Branch 1 taken 43574 times.
✓ Branch 4 taken 43574 times.
|
43574 | return setPointer(index, *targetHandle, checkValidity); |
| 409 | } | ||
| 410 | 21 | return false; | |
| 411 | 43595 | } | |
| 412 | |||
| 413 | // regular field -- name or data | ||
| 414 |
14/19✓ Branch 1 taken 2328470 times.
✓ Branch 4 taken 2328470 times.
✓ Branch 6 taken 2076548 times.
✓ Branch 7 taken 251922 times.
✓ Branch 9 taken 2076548 times.
✓ Branch 12 taken 2076548 times.
✓ Branch 15 taken 2076548 times.
✓ Branch 17 taken 8160 times.
✓ Branch 18 taken 2068388 times.
✓ Branch 19 taken 2076548 times.
✓ Branch 20 taken 251922 times.
✓ Branch 22 taken 2328470 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 8160 times.
✓ Branch 26 taken 2320310 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
|
2328470 | if ((iddObject().hasNameField()) && (index == iddObject().nameFieldIndex().get())) { |
| 415 |
1/1✓ Branch 1 taken 8160 times.
|
8160 | return setName(value, checkValidity).has_value(); |
| 416 | } // name | ||
| 417 | |||
| 418 | // record diffs at start | ||
| 419 | 2320310 | unsigned diffSize = m_diffs.size(); | |
| 420 | |||
| 421 | // field already exists | ||
| 422 |
3/3✓ Branch 1 taken 2320310 times.
✓ Branch 3 taken 2224142 times.
✓ Branch 4 taken 96168 times.
|
2320310 | if (index < numFields()) { |
| 423 | // validity checking and reconstitution is limited to field index | ||
| 424 |
1/1✓ Branch 1 taken 2224142 times.
|
2224142 | OptionalString oldValue = getString(index); |
| 425 |
1/1✓ Branch 1 taken 2224142 times.
|
2224142 | bool result = IdfObject_Impl::setString(index, value, false); |
| 426 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2224142 times.
|
2224142 | if (!result) { |
| 427 | ✗ | return false; | |
| 428 | } | ||
| 429 |
7/7✓ Branch 0 taken 1108017 times.
✓ Branch 1 taken 1116125 times.
✓ Branch 3 taken 1108017 times.
✓ Branch 6 taken 1107801 times.
✓ Branch 7 taken 216 times.
✓ Branch 8 taken 1107801 times.
✓ Branch 9 taken 1116341 times.
|
2224142 | if (checkValidity && level > StrictnessLevel::None) { |
| 430 |
3/3✓ Branch 1 taken 1107801 times.
✓ Branch 5 taken 713 times.
✓ Branch 6 taken 1107088 times.
|
1107801 | if (!fieldDataIsValid(index, level).empty()) { |
| 431 | // rollback | ||
| 432 |
2/2✓ Branch 1 taken 713 times.
✓ Branch 4 taken 713 times.
|
713 | IdfObject_Impl::setString(index, *oldValue, false); |
| 433 | |||
| 434 | // remove the diffs | ||
| 435 |
1/1✓ Branch 1 taken 713 times.
|
713 | m_diffs.resize(diffSize); |
| 436 | |||
| 437 | 713 | return false; | |
| 438 | } | ||
| 439 | } | ||
| 440 | 2223429 | return true; | |
| 441 | 2224142 | } | |
| 442 | |||
| 443 | // field does not yet exist. need to check whole object for validity, and pop fields if | ||
| 444 | // any operations are unsuccessful or result in an invalid object | ||
| 445 |
1/1✓ Branch 1 taken 96168 times.
|
96168 | unsigned n = numFields(); |
| 446 | 96168 | bool result = false; | |
| 447 |
8/8✓ Branch 1 taken 96168 times.
✓ Branch 3 taken 749 times.
✓ Branch 4 taken 95419 times.
✓ Branch 6 taken 749 times.
✓ Branch 8 taken 738 times.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 96157 times.
✓ Branch 11 taken 11 times.
|
96168 | if (m_iddObject.isNonextensibleField(index) || m_iddObject.isExtensibleField(index)) { |
| 448 | 96157 | result = true; | |
| 449 |
6/6✓ Branch 0 taken 262887 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 166733 times.
✓ Branch 4 taken 96154 times.
✓ Branch 5 taken 166733 times.
✓ Branch 6 taken 96157 times.
|
262890 | while (result && (index >= m_fields.size())) { |
| 450 |
1/1✓ Branch 2 taken 166733 times.
|
166733 | result = pushString(std::string(), false); |
| 451 | } | ||
| 452 | 96157 | result = true; | |
| 453 |
5/6✓ Branch 0 taken 96161 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96157 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96157 times.
|
96161 | while (result && (index >= m_fields.size())) { |
| 454 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
|
4 | result = !pushExtensibleGroup(StringVector(), false).empty(); |
| 455 | } | ||
| 456 |
1/1✓ Branch 1 taken 96157 times.
|
96157 | result = IdfObject_Impl::setString(index, value, false); |
| 457 |
2/2✓ Branch 0 taken 92479 times.
✓ Branch 1 taken 3678 times.
|
96157 | if (checkValidity) { |
| 458 |
5/6✓ Branch 0 taken 92479 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 92479 times.
✓ Branch 6 taken 92479 times.
✓ Branch 8 taken 92464 times.
✓ Branch 9 taken 15 times.
|
92479 | result = result && isValid(m_workspace->strictnessLevel()); |
| 459 | } | ||
| 460 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 96142 times.
|
96157 | if (!result) { |
| 461 |
1/1✓ Branch 1 taken 15 times.
|
15 | restoreOriginalNumFields(n); |
| 462 | |||
| 463 | // remove the diffs | ||
| 464 |
1/1✓ Branch 1 taken 15 times.
|
15 | m_diffs.resize(diffSize); |
| 465 | |||
| 466 | 15 | return false; | |
| 467 | } | ||
| 468 | } | ||
| 469 | |||
| 470 | 96153 | return result; | |
| 471 | } | ||
| 472 | |||
| 473 | 285095 | bool WorkspaceObject_Impl::setPointer(unsigned index, const Handle& targetHandle) { | |
| 474 | 285095 | bool result = setPointer(index, targetHandle, true); | |
| 475 |
2/2✓ Branch 0 taken 285077 times.
✓ Branch 1 taken 18 times.
|
285095 | if (result) { |
| 476 | 285077 | this->emitChangeSignals(); | |
| 477 | } | ||
| 478 | 285095 | return result; | |
| 479 | } | ||
| 480 | |||
| 481 | 420272 | bool WorkspaceObject_Impl::setPointer(unsigned index, const Handle& targetHandle, bool checkValidity) { | |
| 482 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 420272 times.
|
420272 | if (m_handle.isNull()) { |
| 483 | ✗ | return false; | |
| 484 | } | ||
| 485 | |||
| 486 | // essential hurdles | ||
| 487 |
11/14✓ Branch 2 taken 420272 times.
✓ Branch 4 taken 420271 times.
✓ Branch 5 taken 1 time.
✓ Branch 7 taken 300367 times.
✓ Branch 8 taken 119904 times.
✓ Branch 10 taken 300367 times.
✓ Branch 12 taken 300360 times.
✓ Branch 13 taken 7 times.
✓ Branch 14 taken 420272 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 420264 times.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
420272 | if (canBeSource(index) && (targetHandle.isNull() || m_workspace->isMember(targetHandle))) { |
| 488 | |||
| 489 |
1/1✓ Branch 1 taken 420264 times.
|
420264 | StrictnessLevel level = m_workspace->strictnessLevel(); |
| 490 | |||
| 491 | // field NullAndRequired | ||
| 492 |
6/17✓ Branch 0 taken 323943 times.
✓ Branch 1 taken 96321 times.
✓ Branch 3 taken 323943 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 323943 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 420264 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 420264 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
420264 | if (checkValidity && (level > StrictnessLevel::Draft) && targetHandle.isNull() && iddObject().isRequiredField(index)) { |
| 493 | ✗ | return false; | |
| 494 | } | ||
| 495 | |||
| 496 | // field PointerType | ||
| 497 |
5/5✓ Branch 1 taken 323943 times.
✓ Branch 4 taken 323425 times.
✓ Branch 5 taken 518 times.
✓ Branch 7 taken 291986 times.
✓ Branch 8 taken 31439 times.
|
323943 | if (checkValidity && (level > StrictnessLevel::Minimal) && (!targetHandle.isNull()) |
| 498 |
13/17✓ Branch 0 taken 323943 times.
✓ Branch 1 taken 96321 times.
✓ Branch 3 taken 291986 times.
✓ Branch 6 taken 291986 times.
✓ Branch 9 taken 291986 times.
✓ Branch 11 taken 19 times.
✓ Branch 12 taken 291967 times.
✓ Branch 13 taken 291986 times.
✓ Branch 14 taken 128278 times.
✓ Branch 16 taken 291986 times.
✓ Branch 17 taken 128278 times.
✓ Branch 19 taken 19 times.
✓ Branch 20 taken 420245 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
744207 | && (!m_workspace->canBeTarget(targetHandle, iddObject().objectLists(index)))) { |
| 499 | 19 | return false; | |
| 500 | } | ||
| 501 | |||
| 502 | // record diffs at start | ||
| 503 | 420245 | unsigned diffSize = m_diffs.size(); | |
| 504 | 420245 | bool checkValid = false; // check validity at object level? | |
| 505 |
11/11✓ Branch 0 taken 323924 times.
✓ Branch 1 taken 96321 times.
✓ Branch 3 taken 323924 times.
✓ Branch 6 taken 323406 times.
✓ Branch 7 taken 518 times.
✓ Branch 9 taken 323406 times.
✓ Branch 12 taken 323406 times.
✓ Branch 15 taken 323361 times.
✓ Branch 16 taken 45 times.
✓ Branch 17 taken 323361 times.
✓ Branch 18 taken 96884 times.
|
420245 | if (checkValidity && (level > StrictnessLevel::Minimal) && (m_workspace->iddFileType() == IddFileType::OpenStudio)) { |
| 506 | // there may be model-level checks on this field | ||
| 507 | 323361 | checkValid = true; | |
| 508 | } | ||
| 509 | 420245 | OptionalUnsigned n; | |
| 510 |
3/3✓ Branch 1 taken 420245 times.
✓ Branch 3 taken 26896 times.
✓ Branch 4 taken 393349 times.
|
420245 | if (index >= numFields()) { |
| 511 |
7/7✓ Branch 0 taken 24208 times.
✓ Branch 1 taken 2688 times.
✓ Branch 3 taken 24208 times.
✓ Branch 6 taken 24200 times.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 24200 times.
✓ Branch 9 taken 2696 times.
|
26896 | if (checkValidity && level > StrictnessLevel::None) { |
| 512 | 24200 | checkValid = true; | |
| 513 | } | ||
| 514 |
2/2✓ Branch 1 taken 26896 times.
✓ Branch 4 taken 26896 times.
|
26896 | n = numFields(); |
| 515 |
3/3✓ Branch 1 taken 26896 times.
✓ Branch 3 taken 5942 times.
✓ Branch 4 taken 20954 times.
|
26896 | if (index - 1 >= numFields()) { |
| 516 | // call set string to add all fields up to this one | ||
| 517 |
1/1✓ Branch 2 taken 5942 times.
|
5942 | setString(index - 1, std::string(), false); |
| 518 | } | ||
| 519 | } | ||
| 520 | |||
| 521 |
1/1✓ Branch 1 taken 420245 times.
|
420245 | Handle oldHandle = setPointerImpl(index, targetHandle); |
| 522 | |||
| 523 | 420245 | OptionalString oldValue; | |
| 524 | 420245 | OptionalString newValue; | |
| 525 |
4/4✓ Branch 1 taken 420245 times.
✓ Branch 4 taken 420245 times.
✓ Branch 7 taken 419446 times.
✓ Branch 8 taken 799 times.
|
420245 | if (iddObject().hasHandleField()) { |
| 526 |
2/2✓ Branch 1 taken 419446 times.
✓ Branch 4 taken 419446 times.
|
419446 | oldValue = toString(oldHandle); |
| 527 |
2/2✓ Branch 1 taken 419446 times.
✓ Branch 4 taken 419446 times.
|
419446 | newValue = toString(targetHandle); |
| 528 | } else { | ||
| 529 |
1/1✓ Branch 1 taken 799 times.
|
799 | oldValue = m_workspace->name(oldHandle); |
| 530 |
1/1✓ Branch 1 taken 799 times.
|
799 | newValue = m_workspace->name(targetHandle); |
| 531 | } | ||
| 532 | |||
| 533 |
6/6✓ Branch 1 taken 420245 times.
✓ Branch 4 taken 420245 times.
✓ Branch 7 taken 420245 times.
✓ Branch 10 taken 420245 times.
✓ Branch 13 taken 420245 times.
✓ Branch 16 taken 420245 times.
|
420245 | m_diffs.push_back(WorkspaceObjectDiff(index, oldValue, newValue, oldHandle, targetHandle)); |
| 534 | |||
| 535 |
5/7✓ Branch 0 taken 323411 times.
✓ Branch 1 taken 96834 times.
✓ Branch 3 taken 323411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 323411 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 420245 times.
|
420245 | if (checkValid && !isValid(level, false)) { |
| 536 | ✗ | if (n) { | |
| 537 | ✗ | restoreOriginalNumFields(*n); | |
| 538 | } else { | ||
| 539 | ✗ | setPointerImpl(index, oldHandle); | |
| 540 | } | ||
| 541 | |||
| 542 | // remove the diffs | ||
| 543 | ✗ | m_diffs.resize(diffSize); | |
| 544 | |||
| 545 | ✗ | return false; | |
| 546 | } | ||
| 547 | |||
| 548 | 420245 | return true; | |
| 549 | 420245 | } | |
| 550 | |||
| 551 | 8 | return false; | |
| 552 | } | ||
| 553 | |||
| 554 | ✗ | bool WorkspaceObject_Impl::pushString() { | |
| 555 | ✗ | bool result = pushString(std::string(), true); | |
| 556 | ✗ | if (result) { | |
| 557 | ✗ | this->emitChangeSignals(); | |
| 558 | } | ||
| 559 | ✗ | return result; | |
| 560 | } | ||
| 561 | |||
| 562 | 21975 | bool WorkspaceObject_Impl::pushString(bool checkValidity) { | |
| 563 |
1/1✓ Branch 2 taken 21975 times.
|
21975 | return pushString(std::string(), checkValidity); |
| 564 | } | ||
| 565 | |||
| 566 | ✗ | bool WorkspaceObject_Impl::pushString(const std::string& value) { | |
| 567 | ✗ | bool result = pushString(value, true); | |
| 568 | ✗ | if (result) { | |
| 569 | ✗ | this->emitChangeSignals(); | |
| 570 | } | ||
| 571 | ✗ | return result; | |
| 572 | } | ||
| 573 | |||
| 574 | 188708 | bool WorkspaceObject_Impl::pushString(const std::string& value, bool checkValidity) { | |
| 575 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 188708 times.
|
188708 | if (m_handle.isNull()) { |
| 576 | ✗ | return false; | |
| 577 | } | ||
| 578 | |||
| 579 | 188708 | unsigned index = numFields(); | |
| 580 | |||
| 581 | // pointer field? | ||
| 582 |
3/3✓ Branch 2 taken 188708 times.
✓ Branch 5 taken 53731 times.
✓ Branch 6 taken 134977 times.
|
188708 | if (canBeSource(index)) { |
| 583 |
3/3✓ Branch 1 taken 53731 times.
✓ Branch 4 taken 53731 times.
✓ Branch 7 taken 53731 times.
|
53731 | OptionalHandle targetHandle = convertToTargetHandle(value, iddObject().objectLists(index), checkValidity); |
| 584 |
1/2✓ Branch 0 taken 53731 times.
✗ Branch 1 not taken.
|
53731 | if (targetHandle) { |
| 585 |
2/2✓ Branch 1 taken 53731 times.
✓ Branch 4 taken 53731 times.
|
53731 | return pushPointer(*targetHandle, checkValidity); |
| 586 | } | ||
| 587 | ✗ | return false; | |
| 588 | 53731 | } | |
| 589 | |||
| 590 | 134977 | unsigned diffSize = m_diffs.size(); | |
| 591 | |||
| 592 | // regular field | ||
| 593 | 134977 | bool result = IdfObject_Impl::pushString(value, checkValidity); // nominally add | |
| 594 |
1/2✓ Branch 0 taken 134977 times.
✗ Branch 1 not taken.
|
134977 | if (result) { |
| 595 | // let WorkspaceObject_Impl::setString check validity | ||
| 596 | 134977 | result = setString(index, value, checkValidity); | |
| 597 | } | ||
| 598 | |||
| 599 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 134977 times.
|
134977 | if (!result) { |
| 600 | ✗ | restoreOriginalNumFields(index); | |
| 601 | |||
| 602 | // remove diffs | ||
| 603 | ✗ | m_diffs.resize(diffSize); | |
| 604 | } | ||
| 605 | |||
| 606 | 134977 | return result; | |
| 607 | } | ||
| 608 | |||
| 609 | ✗ | bool WorkspaceObject_Impl::pushPointer(const Handle& targetHandle) { | |
| 610 | ✗ | bool result = pushPointer(targetHandle, true); | |
| 611 | ✗ | if (result) { | |
| 612 | ✗ | this->emitChangeSignals(); | |
| 613 | } | ||
| 614 | ✗ | return result; | |
| 615 | } | ||
| 616 | |||
| 617 | 53731 | bool WorkspaceObject_Impl::pushPointer(const Handle& targetHandle, bool checkValidity) { | |
| 618 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53731 times.
|
53731 | if (m_handle.isNull()) { |
| 619 | ✗ | return false; | |
| 620 | } | ||
| 621 | |||
| 622 |
1/1✓ Branch 1 taken 53731 times.
|
53731 | unsigned index = numFields(); |
| 623 | |||
| 624 |
1/1✓ Branch 1 taken 53731 times.
|
53731 | StrictnessLevel level = m_workspace->strictnessLevel(); |
| 625 | // essential hurdles | ||
| 626 |
6/18✓ Branch 2 taken 53731 times.
✓ Branch 4 taken 53731 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 53731 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 53731 times.
✓ Branch 18 taken 53731 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 53731 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
53731 | if (canBeSource(index) && (targetHandle.isNull() || m_workspace->name(targetHandle))) { |
| 627 | // field NullAndRequired (applicable if extensible group of size 1) | ||
| 628 |
3/17✗ Branch 0 not taken.
✓ Branch 1 taken 53731 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 53731 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 53731 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
53731 | if (checkValidity && (level > StrictnessLevel::Draft) && targetHandle.isNull() && iddObject().isRequiredField(index)) { |
| 629 | ✗ | return false; | |
| 630 | } | ||
| 631 | // field PointerType | ||
| 632 | ✗ | if (checkValidity && (level > StrictnessLevel::Minimal) && (!targetHandle.isNull()) | |
| 633 |
4/17✗ Branch 0 not taken.
✓ Branch 1 taken 53731 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 53731 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 53731 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 53731 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
53731 | && (!m_workspace->canBeTarget(targetHandle, iddObject().objectLists(index)))) { |
| 634 | ✗ | return false; | |
| 635 | } | ||
| 636 |
1/1✓ Branch 1 taken 53731 times.
|
53731 | bool result = IdfObject_Impl::pushString(checkValidity); |
| 637 |
2/2✓ Branch 0 taken 53728 times.
✓ Branch 1 taken 3 times.
|
53731 | if (result) { |
| 638 |
1/1✓ Branch 1 taken 53728 times.
|
53728 | result = setPointer(index, targetHandle, checkValidity); |
| 639 | } | ||
| 640 | 53731 | return result; | |
| 641 | } | ||
| 642 | ✗ | return false; | |
| 643 | } | ||
| 644 | |||
| 645 | 3120 | std::vector<std::string> WorkspaceObject_Impl::popExtensibleGroup() { | |
| 646 | 3120 | StringVector result = popExtensibleGroup(true); | |
| 647 |
2/2✓ Branch 1 taken 2411 times.
✓ Branch 2 taken 709 times.
|
3120 | if (!result.empty()) { |
| 648 |
1/1✓ Branch 1 taken 2411 times.
|
2411 | this->emitChangeSignals(); |
| 649 | } | ||
| 650 | 3120 | return result; | |
| 651 | ✗ | } | |
| 652 | |||
| 653 | 107362 | std::vector<std::string> WorkspaceObject_Impl::popExtensibleGroup(bool checkValidity) { | |
| 654 | 107362 | StringVector result; | |
| 655 |
2/3✓ Branch 1 taken 107362 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 107362 times.
|
107362 | if (!initialized()) { |
| 656 | ✗ | UnsignedVector olFields = iddObject().objectListFields(); | |
| 657 | ✗ | if (!olFields.empty() && iddObject().isExtensibleField(olFields.back())) { | |
| 658 | ✗ | return result; | |
| 659 | } | ||
| 660 | ✗ | } | |
| 661 | |||
| 662 | // check minFields in Final Strictness | ||
| 663 |
4/4✓ Branch 1 taken 107362 times.
✓ Branch 4 taken 107362 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 107360 times.
|
107362 | if (m_workspace->strictnessLevel() == StrictnessLevel::Final) { |
| 664 |
1/1✓ Branch 1 taken 2 times.
|
2 | unsigned groupSize = m_iddObject.properties().numExtensible; |
| 665 |
1/1✓ Branch 1 taken 2 times.
|
2 | unsigned numAfterPop = numFields() - groupSize; |
| 666 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | if (numAfterPop < m_iddObject.properties().minFields) { |
| 667 | 1 | return result; | |
| 668 | } | ||
| 669 | } | ||
| 670 | |||
| 671 | // erase fields, handling pointers as necessary | ||
| 672 |
1/1✓ Branch 1 taken 107361 times.
|
107361 | result = IdfObject_Impl::popExtensibleGroup(checkValidity); |
| 673 |
6/6✓ Branch 1 taken 107294 times.
✓ Branch 2 taken 67 times.
✓ Branch 4 taken 106599 times.
✓ Branch 5 taken 695 times.
✓ Branch 6 taken 106599 times.
✓ Branch 7 taken 762 times.
|
214722 | if (m_sourceData && !result.empty()) { |
| 674 |
1/1✓ Branch 1 taken 106599 times.
|
106599 | unsigned n = numFields(); |
| 675 | 106599 | UnsignedVector outOfRangePtrs; | |
| 676 |
3/3✓ Branch 1 taken 106599 times.
✓ Branch 8 taken 314331 times.
✓ Branch 9 taken 106599 times.
|
420930 | for (const ForwardPointer& ptr : m_sourceData->pointers) { |
| 677 |
2/2✓ Branch 0 taken 1023 times.
✓ Branch 1 taken 313308 times.
|
314331 | if (ptr.fieldIndex >= n) { |
| 678 |
1/1✓ Branch 1 taken 1023 times.
|
1023 | outOfRangePtrs.push_back(ptr.fieldIndex); |
| 679 | } | ||
| 680 | } | ||
| 681 |
2/2✓ Branch 5 taken 1023 times.
✓ Branch 6 taken 106599 times.
|
107622 | for (const unsigned index : outOfRangePtrs) { |
| 682 |
1/1✓ Branch 1 taken 1023 times.
|
1023 | nullifyPointer(index); |
| 683 |
2/2✓ Branch 1 taken 1023 times.
✓ Branch 4 taken 1023 times.
|
1023 | auto fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 684 |
2/4✓ Branch 1 taken 1023 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1023 times.
✗ Branch 8 not taken.
|
1023 | OS_ASSERT(fpIt != m_sourceData->pointers.end()); |
| 685 |
2/2✓ Branch 1 taken 1023 times.
✓ Branch 4 taken 1023 times.
|
1023 | m_sourceData->pointers.erase(fpIt); |
| 686 | } | ||
| 687 | 106599 | } | |
| 688 | |||
| 689 | 107361 | return result; | |
| 690 | ✗ | } | |
| 691 | |||
| 692 | // QUERIES | ||
| 693 | |||
| 694 | 18247734 | bool WorkspaceObject_Impl::initialized() const { | |
| 695 |
4/4✓ Branch 0 taken 18073008 times.
✓ Branch 1 taken 174726 times.
✓ Branch 3 taken 18072990 times.
✓ Branch 4 taken 18 times.
|
18247734 | return m_initialized && (!m_handle.isNull()); |
| 696 | } | ||
| 697 | |||
| 698 | 48 | unsigned WorkspaceObject_Impl::numSources() const { | |
| 699 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
|
48 | if (m_handle.isNull()) { |
| 700 | ✗ | return 0u; | |
| 701 | } | ||
| 702 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
96 | if (m_targetData) { |
| 703 | 48 | return m_targetData->reversePointers.size(); | |
| 704 | } | ||
| 705 | ✗ | return 0; | |
| 706 | } | ||
| 707 | |||
| 708 | 5 | bool WorkspaceObject_Impl::isSource() const { | |
| 709 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (!initialized()) { |
| 710 | ✗ | return false; | |
| 711 | } | ||
| 712 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | if (m_sourceData) { |
| 713 |
2/3✓ Branch 1 taken 5 times.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
|
5 | for (const ForwardPointer& fPtr : m_sourceData->pointers) { |
| 714 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | if (!fPtr.targetHandle.isNull()) { |
| 715 | 5 | return true; | |
| 716 | } | ||
| 717 | } | ||
| 718 | } | ||
| 719 | ✗ | return false; | |
| 720 | } | ||
| 721 | |||
| 722 | 5 | bool WorkspaceObject_Impl::isSource(unsigned index) const { | |
| 723 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (m_handle.isNull()) { |
| 724 | ✗ | return false; | |
| 725 | } | ||
| 726 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | if (m_sourceData) { |
| 727 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | auto it = getConstIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 728 |
7/7✓ Branch 1 taken 5 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✓ Branch 12 taken 4 times.
|
5 | if ((it != m_sourceData->pointers.end()) && (!it->targetHandle.isNull())) { |
| 729 | 1 | return true; | |
| 730 | } | ||
| 731 | } | ||
| 732 | 4 | return false; | |
| 733 | } | ||
| 734 | |||
| 735 | 5 | bool WorkspaceObject_Impl::canBeSource() const { | |
| 736 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (m_handle.isNull()) { |
| 737 | ✗ | return false; | |
| 738 | } | ||
| 739 | 5 | return m_sourceData.has_value(); | |
| 740 | } | ||
| 741 | |||
| 742 | 19164505 | bool WorkspaceObject_Impl::canBeSource(unsigned index, const StringVector& refLists) const { | |
| 743 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 19164503 times.
|
19164505 | if (m_handle.isNull()) { |
| 744 | 2 | return false; | |
| 745 | } | ||
| 746 |
2/2✓ Branch 1 taken 19164503 times.
✓ Branch 4 taken 19164503 times.
|
19164503 | OptionalIddField iddField = iddObject().getField(index); |
| 747 |
2/2✓ Branch 0 taken 19164492 times.
✓ Branch 1 taken 11 times.
|
19164503 | if (iddField) { |
| 748 |
2/2✓ Branch 1 taken 19164452 times.
✓ Branch 2 taken 40 times.
|
19164492 | if (refLists.empty()) { |
| 749 |
2/2✓ Branch 1 taken 19164452 times.
✓ Branch 4 taken 19164452 times.
|
19164452 | return iddField->isObjectListField(); |
| 750 | } else { | ||
| 751 |
3/3✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 40 times.
|
40 | StringVector objLists = iddField->properties().objectLists; |
| 752 |
1/1✓ Branch 1 taken 40 times.
|
40 | StringVector intersection = intersectReferenceLists(refLists, objLists); |
| 753 | 40 | return !intersection.empty(); | |
| 754 | 40 | } | |
| 755 | } | ||
| 756 | 11 | return false; | |
| 757 | 19164503 | } | |
| 758 | |||
| 759 | 11 | bool WorkspaceObject_Impl::isTarget() const { | |
| 760 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if (m_handle.isNull()) { |
| 761 | ✗ | return false; | |
| 762 | } | ||
| 763 | 11 | return m_targetData.has_value(); | |
| 764 | } | ||
| 765 | |||
| 766 | ✗ | std::vector<std::string> WorkspaceObject_Impl::canBeTarget() const { | |
| 767 | ✗ | StringVector result; | |
| 768 | ✗ | if (!m_handle.isNull() && name()) { | |
| 769 | ✗ | result = iddObject().references(); | |
| 770 | } | ||
| 771 | ✗ | return result; | |
| 772 | ✗ | } | |
| 773 | |||
| 774 | ✗ | bool WorkspaceObject_Impl::objectListFieldsEqual(const WorkspaceObject& other) const { | |
| 775 | // Looks for object equality of targets if same workspace(), otherwise, looks for data | ||
| 776 | // field equality of targets. | ||
| 777 | ✗ | if (iddObject() != other.iddObject()) { | |
| 778 | ✗ | return false; | |
| 779 | } | ||
| 780 | ✗ | UnsignedVector myFields = objectListFields(); | |
| 781 | ✗ | UnsignedVector otherFields = other.objectListFields(); | |
| 782 | ✗ | if (myFields != otherFields) { | |
| 783 | ✗ | return false; | |
| 784 | } | ||
| 785 | |||
| 786 | // iddObject() same, field indices same--compare data | ||
| 787 | ✗ | for (const unsigned i : myFields) { | |
| 788 | ✗ | OptionalWorkspaceObject oMyTarget = getTarget(i); | |
| 789 | ✗ | OptionalWorkspaceObject oOtherTarget = other.getTarget(i); | |
| 790 | ✗ | if (oMyTarget || oOtherTarget) { | |
| 791 | // at least one is non-null | ||
| 792 | ✗ | if (!(oMyTarget && oOtherTarget)) { | |
| 793 | ✗ | return false; | |
| 794 | } | ||
| 795 | ✗ | WorkspaceObject myTarget = *oMyTarget; | |
| 796 | ✗ | WorkspaceObject otherTarget = *oOtherTarget; | |
| 797 | ✗ | if (workspace() == other.workspace()) { | |
| 798 | ✗ | if (myTarget != otherTarget) { | |
| 799 | ✗ | return false; | |
| 800 | } | ||
| 801 | } else { | ||
| 802 | ✗ | if (!myTarget.dataFieldsEqual(otherTarget)) { | |
| 803 | ✗ | return false; | |
| 804 | } | ||
| 805 | } | ||
| 806 | ✗ | } | |
| 807 | ✗ | } | |
| 808 | |||
| 809 | ✗ | return true; | |
| 810 | ✗ | } | |
| 811 | |||
| 812 | 2068 | bool WorkspaceObject_Impl::objectListFieldsNonConflicting(const WorkspaceObject& other) const { | |
| 813 | // Looks for object equality of targets if same workspace(), otherwise, looks for data | ||
| 814 | // field equality of targets. | ||
| 815 |
4/5✓ Branch 1 taken 2068 times.
✓ Branch 4 taken 2068 times.
✓ Branch 7 taken 2068 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2068 times.
|
2068 | if (iddObject() != other.iddObject()) { |
| 816 | ✗ | return false; | |
| 817 | } | ||
| 818 |
1/1✓ Branch 1 taken 2068 times.
|
2068 | UnsignedVector myFields = objectListFields(); |
| 819 |
1/1✓ Branch 1 taken 2068 times.
|
2068 | UnsignedVector otherFields = other.objectListFields(); |
| 820 | // require same managedObjectLists fields to at least exist | ||
| 821 |
3/3✓ Branch 1 taken 2068 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 2067 times.
|
2068 | if (myFields != otherFields) { |
| 822 | 1 | return false; | |
| 823 | } | ||
| 824 | |||
| 825 | // iddObject() same--compare data | ||
| 826 |
2/2✓ Branch 5 taken 1437 times.
✓ Branch 6 taken 2067 times.
|
3504 | for (const unsigned i : myFields) { |
| 827 |
1/1✓ Branch 1 taken 1437 times.
|
1437 | OptionalWorkspaceObject oMyTarget = getTarget(i); |
| 828 | // always ok if I am not pointing to anyone | ||
| 829 |
2/2✓ Branch 1 taken 480 times.
✓ Branch 2 taken 957 times.
|
1437 | if (!oMyTarget) { |
| 830 | 480 | continue; | |
| 831 | } | ||
| 832 | |||
| 833 |
1/1✓ Branch 1 taken 957 times.
|
957 | OptionalWorkspaceObject oOtherTarget = other.getTarget(i); |
| 834 | // ok if other is not pointing to anyone | ||
| 835 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 957 times.
|
957 | if (!oOtherTarget) { |
| 836 | ✗ | continue; | |
| 837 | } | ||
| 838 | |||
| 839 |
2/2✓ Branch 1 taken 957 times.
✓ Branch 4 taken 957 times.
|
957 | WorkspaceObject myTarget = *oMyTarget; |
| 840 |
2/2✓ Branch 1 taken 957 times.
✓ Branch 4 taken 957 times.
|
957 | WorkspaceObject otherTarget = *oOtherTarget; |
| 841 |
5/5✓ Branch 1 taken 957 times.
✓ Branch 4 taken 957 times.
✓ Branch 7 taken 957 times.
✓ Branch 11 taken 895 times.
✓ Branch 12 taken 62 times.
|
957 | if (workspace() == other.workspace()) { |
| 842 |
2/3✓ Branch 1 taken 895 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 895 times.
|
895 | if (myTarget != otherTarget) { |
| 843 | ✗ | return false; | |
| 844 | } | ||
| 845 | } else { | ||
| 846 |
2/3✓ Branch 1 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
|
62 | if (!myTarget.dataFieldsEqual(otherTarget)) { |
| 847 | ✗ | return false; | |
| 848 | } | ||
| 849 | } | ||
| 850 | 1437 | } | |
| 851 | |||
| 852 | 2067 | return true; | |
| 853 | 2068 | } | |
| 854 | |||
| 855 | // SERIALIZATION | ||
| 856 | |||
| 857 | 181241 | IdfObject_ImplPtr WorkspaceObject_Impl::idfObjectImplPtr() { | |
| 858 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 181241 times.
|
181241 | if (!initialized()) { |
| 859 | ✗ | LOG_AND_THROW("Attempt to write a disconnected WorkspaceObject out to Idf."); | |
| 860 | } | ||
| 861 | |||
| 862 | // construct new IdfObject from WorkspaceObject's data | ||
| 863 |
2/4✓ Branch 2 taken 181241 times.
✓ Branch 5 taken 181241 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
181241 | IdfObject_ImplPtr result(new IdfObject_Impl(m_handle, m_comment, m_iddObject, m_fields, m_fieldComments)); |
| 864 | // add name references based on WorkspaceObject's pointer data | ||
| 865 |
2/2✓ Branch 1 taken 152970 times.
✓ Branch 2 taken 28271 times.
|
362482 | if (m_sourceData) { |
| 866 |
1/1✓ Branch 1 taken 152970 times.
|
152970 | bool serializeHandle = m_iddObject.hasHandleField(); |
| 867 |
3/3✓ Branch 1 taken 152970 times.
✓ Branch 8 taken 420661 times.
✓ Branch 9 taken 152970 times.
|
573631 | for (const ForwardPointer& ptr : m_sourceData->pointers) { |
| 868 |
2/2✓ Branch 1 taken 270158 times.
✓ Branch 2 taken 150503 times.
|
420661 | if (!ptr.targetHandle.isNull()) { |
| 869 |
2/2✓ Branch 0 taken 236320 times.
✓ Branch 1 taken 33838 times.
|
270158 | if (serializeHandle) { |
| 870 |
2/2✓ Branch 2 taken 236320 times.
✓ Branch 5 taken 236320 times.
|
236320 | result->setString(ptr.fieldIndex, toString(ptr.targetHandle)); |
| 871 | } else { | ||
| 872 |
1/1✓ Branch 1 taken 33838 times.
|
33838 | OptionalString targetName = m_workspace->name(ptr.targetHandle); |
| 873 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 33838 times.
✗ Branch 4 not taken.
|
33838 | OS_ASSERT(targetName); |
| 874 |
2/3✓ Branch 1 taken 33838 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 33838 times.
|
33838 | if (targetName->empty()) { |
| 875 | // give target a name | ||
| 876 | ✗ | OptionalWorkspaceObject target = m_workspace->getObject(ptr.targetHandle); | |
| 877 | ✗ | OS_ASSERT(target); | |
| 878 | ✗ | target->createName(false); | |
| 879 | ✗ | targetName = target->name(); | |
| 880 | ✗ | OS_ASSERT(targetName); | |
| 881 | ✗ | } | |
| 882 |
2/2✓ Branch 2 taken 33838 times.
✓ Branch 5 taken 33838 times.
|
33838 | result->setString(ptr.fieldIndex, *targetName); |
| 883 | 33838 | } | |
| 884 | } | ||
| 885 | } | ||
| 886 | } | ||
| 887 | 181241 | return result; | |
| 888 | ✗ | } | |
| 889 | |||
| 890 | ✗ | IdfObject_ImplPtr WorkspaceObject_Impl::idfObjectImplPtr() const { | |
| 891 | ✗ | if (!initialized()) { | |
| 892 | ✗ | LOG_AND_THROW("Attempt to write a disconnected WorkspaceObject out to Idf."); | |
| 893 | } | ||
| 894 | |||
| 895 | // construct new IdfObject from WorkspaceObject's data | ||
| 896 | ✗ | IdfObject_ImplPtr result(new IdfObject_Impl(m_handle, m_comment, m_iddObject, m_fields, m_fieldComments)); | |
| 897 | // add name references based on WorkspaceObject's pointer data | ||
| 898 | ✗ | if (m_sourceData) { | |
| 899 | ✗ | bool serializeHandle = m_iddObject.hasHandleField(); | |
| 900 | ✗ | for (const ForwardPointer& ptr : m_sourceData->pointers) { | |
| 901 | ✗ | if (!ptr.targetHandle.isNull()) { | |
| 902 | ✗ | if (serializeHandle) { | |
| 903 | ✗ | result->setString(ptr.fieldIndex, toString(ptr.targetHandle)); | |
| 904 | } else { | ||
| 905 | ✗ | OptionalString targetName = m_workspace->name(ptr.targetHandle); | |
| 906 | ✗ | OS_ASSERT(targetName); | |
| 907 | ✗ | result->setString(ptr.fieldIndex, *targetName); | |
| 908 | ✗ | } | |
| 909 | } | ||
| 910 | } | ||
| 911 | } | ||
| 912 | ✗ | return result; | |
| 913 | ✗ | } | |
| 914 | |||
| 915 | /** Returns equivalent IdfObject, naming targets if necessary. All data is cloned. */ | ||
| 916 | 5235 | IdfObject WorkspaceObject_Impl::idfObject() { | |
| 917 |
2/2✓ Branch 1 taken 5235 times.
✓ Branch 4 taken 5235 times.
|
5235 | return getObject<WorkspaceObject>().idfObject(); |
| 918 | } | ||
| 919 | |||
| 920 | /** Returns equivalent IdfObject, leaving unnamed target objects unnamed. All data is cloned. */ | ||
| 921 | ✗ | IdfObject WorkspaceObject_Impl::idfObject() const { | |
| 922 | ✗ | return getObject<WorkspaceObject>().idfObject(); | |
| 923 | } | ||
| 924 | |||
| 925 | 1325671 | void WorkspaceObject_Impl::emitChangeSignals() { | |
| 926 |
2/2✓ Branch 1 taken 2492 times.
✓ Branch 2 taken 1323179 times.
|
1325671 | if (m_diffs.empty()) { |
| 927 | 2492 | return; | |
| 928 | } | ||
| 929 | |||
| 930 | 1323179 | bool nameChange = false; | |
| 931 | 1323179 | bool dataChange = false; | |
| 932 | |||
| 933 |
2/2✓ Branch 5 taken 3815013 times.
✓ Branch 6 taken 1323179 times.
|
5138192 | for (const IdfObjectDiff& diff : m_diffs) { |
| 934 | |||
| 935 |
3/3✓ Branch 1 taken 3815013 times.
✓ Branch 3 taken 984055 times.
✓ Branch 4 taken 2830958 times.
|
3815013 | if (diff.isNull()) { |
| 936 | 984055 | continue; | |
| 937 | } | ||
| 938 | |||
| 939 |
1/1✓ Branch 1 taken 2830958 times.
|
2830958 | boost::optional<unsigned> index = diff.index(); |
| 940 |
1/2✓ Branch 0 taken 2830958 times.
✗ Branch 1 not taken.
|
2830958 | if (index) { |
| 941 | |||
| 942 |
3/3✓ Branch 1 taken 2830958 times.
✓ Branch 4 taken 2830958 times.
✓ Branch 7 taken 2830958 times.
|
2830958 | OptionalIddField oIddField = iddObject().getField(*index); |
| 943 | |||
| 944 |
12/15✓ Branch 1 taken 2830958 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2830958 times.
✓ Branch 7 taken 2830958 times.
✓ Branch 9 taken 358950 times.
✓ Branch 10 taken 2472008 times.
✓ Branch 12 taken 358950 times.
✓ Branch 15 taken 276508 times.
✓ Branch 16 taken 82442 times.
✓ Branch 17 taken 358950 times.
✓ Branch 18 taken 2472008 times.
✓ Branch 20 taken 276508 times.
✓ Branch 21 taken 2554450 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
6020866 | if (oIddField && oIddField->isObjectListField() && diff.optionalCast<WorkspaceObjectDiff>()) { |
| 945 | |||
| 946 |
1/1✓ Branch 1 taken 276508 times.
|
276508 | auto workspaceObjectDiff = diff.cast<WorkspaceObjectDiff>(); |
| 947 | |||
| 948 |
1/1✓ Branch 1 taken 276508 times.
|
276508 | Handle newHandle; |
| 949 |
2/3✓ Branch 1 taken 276508 times.
✓ Branch 4 taken 276508 times.
✗ Branch 5 not taken.
|
553016 | if (workspaceObjectDiff.newHandle()) { |
| 950 |
2/2✓ Branch 1 taken 276508 times.
✓ Branch 4 taken 276508 times.
|
276508 | newHandle = workspaceObjectDiff.newHandle().get(); |
| 951 | } | ||
| 952 | |||
| 953 |
1/1✓ Branch 1 taken 276508 times.
|
276508 | Handle oldHandle; |
| 954 |
2/3✓ Branch 1 taken 276508 times.
✓ Branch 4 taken 276508 times.
✗ Branch 5 not taken.
|
553016 | if (workspaceObjectDiff.oldHandle()) { |
| 955 |
2/2✓ Branch 1 taken 276508 times.
✓ Branch 4 taken 276508 times.
|
276508 | oldHandle = workspaceObjectDiff.oldHandle().get(); |
| 956 | } | ||
| 957 | |||
| 958 |
2/2✓ Branch 1 taken 276508 times.
✓ Branch 4 taken 276508 times.
|
276508 | this->onRelationshipChange.nano_emit(*index, newHandle, oldHandle); |
| 959 | |||
| 960 |
7/8✓ Branch 1 taken 2554450 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2554450 times.
✓ Branch 7 taken 2554450 times.
✓ Branch 9 taken 201896 times.
✓ Branch 10 taken 2352554 times.
✓ Branch 11 taken 201896 times.
✓ Branch 12 taken 2352554 times.
|
2830958 | } else if (oIddField && oIddField->isNameField()) { |
| 961 | 201896 | nameChange = true; | |
| 962 | } else { | ||
| 963 | 2352554 | dataChange = true; | |
| 964 | } | ||
| 965 | 2830958 | } | |
| 966 | } | ||
| 967 | |||
| 968 |
2/2✓ Branch 0 taken 199524 times.
✓ Branch 1 taken 1123655 times.
|
1323179 | if (nameChange) { |
| 969 | 199524 | this->onNameChange.nano_emit(); | |
| 970 | } | ||
| 971 | |||
| 972 |
2/2✓ Branch 0 taken 701415 times.
✓ Branch 1 taken 621764 times.
|
1323179 | if (dataChange) { |
| 973 | 701415 | this->onDataChange.nano_emit(); | |
| 974 | } | ||
| 975 | |||
| 976 | 1323179 | this->onChange.nano_emit(); | |
| 977 | |||
| 978 | 1323179 | m_diffs.clear(); | |
| 979 | } | ||
| 980 | |||
| 981 | // PROTECTED | ||
| 982 | |||
| 983 | 572800 | void WorkspaceObject_Impl::setInitialized() { | |
| 984 | 572800 | m_initialized = true; | |
| 985 | 572800 | } | |
| 986 | |||
| 987 | 9974 | void WorkspaceObject_Impl::disconnect() { | |
| 988 | 9974 | this->onRemoveFromWorkspace.nano_emit(m_handle); | |
| 989 |
1/1✓ Branch 1 taken 9974 times.
|
9974 | m_handle = Handle(); |
| 990 | 9974 | m_workspace = nullptr; | |
| 991 | 9974 | } | |
| 992 | |||
| 993 | // Pre-condition: field index is a pointer, and its targetHandle is either null or valid in | ||
| 994 | // m_workspace. | ||
| 995 | // Post-condition: field index is a pointer with a null targetHandle. | ||
| 996 | 29634 | void WorkspaceObject_Impl::nullifyPointer(unsigned index) { | |
| 997 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29634 times.
✗ Branch 4 not taken.
|
29634 | OS_ASSERT(!m_handle.isNull()); |
| 998 | // reverse pointer | ||
| 999 |
1/1✓ Branch 1 taken 29634 times.
|
29634 | OptionalWorkspaceObject oTarget = getTarget(index); |
| 1000 |
2/2✓ Branch 0 taken 29433 times.
✓ Branch 1 taken 201 times.
|
29634 | if (oTarget) { |
| 1001 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
|
29433 | WorkspaceObject target = *oTarget; |
| 1002 |
1/1✓ Branch 3 taken 29433 times.
|
29433 | target.getImpl<WorkspaceObject_Impl>()->nullifyReversePointer(m_handle, index); |
| 1003 | // remove forwarded reference if no other source sets the same | ||
| 1004 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
|
29433 | m_workspace->removeForwardedReferences(handle(), index, target); |
| 1005 | 29433 | } | |
| 1006 | |||
| 1007 | // forward pointer | ||
| 1008 |
2/2✓ Branch 1 taken 29634 times.
✓ Branch 4 taken 29634 times.
|
29634 | auto fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 1009 |
2/4✓ Branch 1 taken 29634 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29634 times.
✗ Branch 8 not taken.
|
29634 | OS_ASSERT(fpIt != m_sourceData->pointers.end()); |
| 1010 |
2/2✓ Branch 1 taken 29634 times.
✓ Branch 4 taken 29634 times.
|
29634 | m_sourceData->pointers.erase(fpIt); |
| 1011 | 29634 | std::pair<SourceData::pointer_set::iterator, bool> insertResult; | |
| 1012 |
3/3✓ Branch 1 taken 29634 times.
✓ Branch 4 taken 29634 times.
✓ Branch 8 taken 29634 times.
|
29634 | insertResult = m_sourceData->pointers.insert(ForwardPointer(index, Handle())); |
| 1013 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 29634 times.
✗ Branch 3 not taken.
|
29634 | OS_ASSERT(insertResult.second); |
| 1014 | 29634 | } | |
| 1015 | |||
| 1016 | // Pre-condition: Object sourceHandle points to this object from field index. | ||
| 1017 | // Post-condition: That information is removed from this object's m_targetData (in preparation for | ||
| 1018 | // a change to the source pointer). | ||
| 1019 | 29433 | void WorkspaceObject_Impl::nullifyReversePointer(const Handle& sourceHandle, unsigned index) { | |
| 1020 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29433 times.
✗ Branch 4 not taken.
|
29433 | OS_ASSERT(!m_handle.isNull()); |
| 1021 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 29433 times.
✗ Branch 4 not taken.
|
29433 | OS_ASSERT(m_targetData); |
| 1022 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 5 taken 29433 times.
|
29433 | auto it = m_targetData->reversePointers.find(ReversePointer(sourceHandle, index)); |
| 1023 |
2/4✓ Branch 1 taken 29433 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29433 times.
✗ Branch 8 not taken.
|
29433 | OS_ASSERT(it != m_targetData->reversePointers.end()); |
| 1024 |
2/2✓ Branch 1 taken 29433 times.
✓ Branch 4 taken 29433 times.
|
29433 | m_targetData->reversePointers.erase(it); |
| 1025 | 29433 | } | |
| 1026 | |||
| 1027 | // Pre-condition: ReversePointer(sourceHandle,index) is not in m_targetData. | ||
| 1028 | // Post-condition: m_targetData indicates that object sourceHandle points to this object from | ||
| 1029 | // field index. | ||
| 1030 | 558554 | void WorkspaceObject_Impl::setReversePointer(const Handle& sourceHandle, unsigned index) { | |
| 1031 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 558554 times.
✗ Branch 4 not taken.
|
558554 | OS_ASSERT(!m_handle.isNull()); |
| 1032 |
2/2✓ Branch 1 taken 235947 times.
✓ Branch 2 taken 322607 times.
|
558554 | if (!m_targetData) { |
| 1033 |
1/1✓ Branch 2 taken 235947 times.
|
235947 | m_targetData = TargetData(); |
| 1034 | } | ||
| 1035 | // automatically maintains uniqueness | ||
| 1036 | 558554 | std::pair<TargetData::pointer_set::iterator, bool> insertResult; | |
| 1037 |
2/2✓ Branch 1 taken 558554 times.
✓ Branch 5 taken 558554 times.
|
558554 | insertResult = m_targetData->reversePointers.insert(ReversePointer(sourceHandle, index)); |
| 1038 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 558554 times.
✗ Branch 3 not taken.
|
558554 | OS_ASSERT(insertResult.second); |
| 1039 | 558554 | } | |
| 1040 | |||
| 1041 | ✗ | void WorkspaceObject_Impl::restorePointers() { | |
| 1042 | ✗ | OS_ASSERT(!m_handle.isNull()); | |
| 1043 | ✗ | if (m_sourceData) { | |
| 1044 | ✗ | for (const ForwardPointer& ptr : m_sourceData->pointers) { | |
| 1045 | ✗ | if (!ptr.targetHandle.isNull()) { | |
| 1046 | ✗ | OptionalWorkspaceObject target = m_workspace->getObject(ptr.targetHandle); | |
| 1047 | ✗ | if (target) { | |
| 1048 | ✗ | WorkspaceObjectVector sources = target->getSources(iddObject().type()); | |
| 1049 | ✗ | HandleVector h = getHandles<WorkspaceObject>(sources); | |
| 1050 | ✗ | if (std::find(h.begin(), h.end(), m_handle) == h.end()) { | |
| 1051 | ✗ | target->getImpl<WorkspaceObject_Impl>()->setReversePointer(m_handle, ptr.fieldIndex); | |
| 1052 | } | ||
| 1053 | ✗ | } | |
| 1054 | ✗ | } | |
| 1055 | } | ||
| 1056 | } | ||
| 1057 | ✗ | if (m_targetData) { | |
| 1058 | ✗ | for (const ReversePointer& ptr : m_targetData->reversePointers) { | |
| 1059 | ✗ | OptionalWorkspaceObject source = m_workspace->getObject(ptr.sourceHandle); | |
| 1060 | ✗ | if (source) { | |
| 1061 | ✗ | OptionalWorkspaceObject oTarget = source->getTarget(ptr.fieldIndex); | |
| 1062 | ✗ | OptionalHandle h; | |
| 1063 | ✗ | if (oTarget) { | |
| 1064 | ✗ | h = oTarget->handle(); | |
| 1065 | } | ||
| 1066 | ✗ | if ((!h) || (*h != m_handle)) { | |
| 1067 | ✗ | source->getImpl<WorkspaceObject_Impl>()->setPointer(ptr.fieldIndex, m_handle, false); | |
| 1068 | } | ||
| 1069 | ✗ | } | |
| 1070 | ✗ | } | |
| 1071 | } | ||
| 1072 | ✗ | } | |
| 1073 | |||
| 1074 | // PRIVATE | ||
| 1075 | |||
| 1076 | // SETTERS | ||
| 1077 | |||
| 1078 | // Pre-condition: targetHandle is null or in m_workspace. index is an object-list field. | ||
| 1079 | // Post-condition: Field index points to object targetHandle. | ||
| 1080 | 1172493 | Handle WorkspaceObject_Impl::setPointerImpl(unsigned index, const Handle& targetHandle) { | |
| 1081 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1172493 times.
✗ Branch 4 not taken.
|
1172493 | OS_ASSERT(!m_handle.isNull()); |
| 1082 |
1/1✓ Branch 1 taken 1172493 times.
|
1172493 | Handle result; |
| 1083 | // check current status | ||
| 1084 |
2/2✓ Branch 1 taken 1172493 times.
✓ Branch 4 taken 1172493 times.
|
1172493 | auto fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 1085 |
3/3✓ Branch 1 taken 1172493 times.
✓ Branch 5 taken 845723 times.
✓ Branch 6 taken 326770 times.
|
1172493 | if (fpIt == m_sourceData->pointers.end()) { |
| 1086 |
1/1✓ Branch 2 taken 845723 times.
|
845723 | /*bool result =*/IdfObject_Impl::setString(index, std::string(), false); |
| 1087 | } else { // entry exists | ||
| 1088 |
2/2✓ Branch 2 taken 60041 times.
✓ Branch 3 taken 266729 times.
|
326770 | if (!fpIt->targetHandle.isNull()) { |
| 1089 | 60041 | result = fpIt->targetHandle; | |
| 1090 |
3/3✓ Branch 2 taken 60041 times.
✓ Branch 4 taken 31430 times.
✓ Branch 5 taken 28611 times.
|
60041 | if (fpIt->targetHandle == targetHandle) { |
| 1091 | 31430 | return result; | |
| 1092 | } // nothing to do | ||
| 1093 |
1/1✓ Branch 1 taken 28611 times.
|
28611 | nullifyPointer(index); // takes care of reverse pointer |
| 1094 | } | ||
| 1095 | } | ||
| 1096 | // add pointer | ||
| 1097 |
2/2✓ Branch 1 taken 1141063 times.
✓ Branch 4 taken 1141063 times.
|
1141063 | fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); |
| 1098 |
3/3✓ Branch 1 taken 1141063 times.
✓ Branch 5 taken 322236 times.
✓ Branch 6 taken 818827 times.
|
1141063 | if (fpIt != m_sourceData->pointers.end()) { |
| 1099 |
2/2✓ Branch 1 taken 322236 times.
✓ Branch 4 taken 322236 times.
|
322236 | m_sourceData->pointers.erase(fpIt); |
| 1100 | } | ||
| 1101 | 1141063 | std::pair<SourceData::pointer_set::iterator, bool> insertResult; | |
| 1102 |
2/2✓ Branch 1 taken 1141063 times.
✓ Branch 5 taken 1141063 times.
|
1141063 | insertResult = m_sourceData->pointers.insert(ForwardPointer(index, targetHandle)); |
| 1103 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1141063 times.
✗ Branch 3 not taken.
|
1141063 | OS_ASSERT(insertResult.second); |
| 1104 | |||
| 1105 | // add reverse pointer | ||
| 1106 |
2/2✓ Branch 1 taken 558554 times.
✓ Branch 2 taken 582509 times.
|
1141063 | if (!targetHandle.isNull()) { |
| 1107 |
1/1✓ Branch 1 taken 558554 times.
|
558554 | OptionalWorkspaceObject target = m_workspace->getObject(targetHandle); |
| 1108 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 558554 times.
✗ Branch 4 not taken.
|
558554 | OS_ASSERT(target); |
| 1109 |
2/2✓ Branch 1 taken 558554 times.
✓ Branch 6 taken 558554 times.
|
558554 | target->getImpl<WorkspaceObject_Impl>()->setReversePointer(m_handle, index); |
| 1110 | // forward references if is object-list and defines references simultaneously | ||
| 1111 |
1/1✓ Branch 1 taken 558554 times.
|
558554 | m_workspace->forwardReferences(m_handle, index, targetHandle); |
| 1112 | 558554 | } | |
| 1113 | |||
| 1114 | 1141063 | return result; | |
| 1115 | } | ||
| 1116 | |||
| 1117 | 97326 | boost::optional<Handle> WorkspaceObject_Impl::convertToTargetHandle(const std::string& name, const std::set<std::string>& referenceLists, | |
| 1118 | bool checkValidity) const { | ||
| 1119 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 97326 times.
✗ Branch 4 not taken.
|
97326 | OS_ASSERT(!m_handle.isNull()); |
| 1120 | |||
| 1121 |
2/2✓ Branch 1 taken 96834 times.
✓ Branch 2 taken 492 times.
|
97326 | if (name.empty()) { |
| 1122 |
2/2✓ Branch 1 taken 96834 times.
✓ Branch 4 taken 96834 times.
|
96834 | return Handle(); |
| 1123 | } // null pointer | ||
| 1124 | |||
| 1125 | // name is already handle | ||
| 1126 |
4/4✓ Branch 1 taken 492 times.
✓ Branch 4 taken 492 times.
✓ Branch 6 taken 226 times.
✓ Branch 7 taken 266 times.
|
492 | if (boost::regex_match(name, uuidInString())) { |
| 1127 |
1/1✓ Branch 1 taken 226 times.
|
226 | Handle handle = toUUID(name); |
| 1128 |
1/1✓ Branch 1 taken 226 times.
|
226 | boost::optional<WorkspaceObject> object = m_workspace->getObject(handle); |
| 1129 |
2/2✓ Branch 0 taken 221 times.
✓ Branch 1 taken 5 times.
|
226 | if (object) { |
| 1130 |
1/1✓ Branch 1 taken 221 times.
|
221 | return handle; |
| 1131 | } else { | ||
| 1132 | // name is a UUID but no object with that handle exists in the workspace, continue checking if this is a name? | ||
| 1133 | } | ||
| 1134 | 226 | } | |
| 1135 | |||
| 1136 |
1/1✓ Branch 1 taken 271 times.
|
271 | WorkspaceObjectVector candidates = m_workspace->getObjectsByName(name); |
| 1137 | |||
| 1138 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 250 times.
|
271 | if (candidates.empty()) { |
| 1139 | 21 | return boost::none; | |
| 1140 | } | ||
| 1141 |
2/2✓ Branch 1 taken 211 times.
✓ Branch 2 taken 39 times.
|
250 | if (candidates.size() == 1) { |
| 1142 |
2/2✓ Branch 2 taken 211 times.
✓ Branch 5 taken 211 times.
|
211 | return candidates[0].handle(); |
| 1143 | } | ||
| 1144 | |||
| 1145 | // multiple. choose first in appropriate reference list. | ||
| 1146 |
1/2✓ Branch 5 taken 62 times.
✗ Branch 6 not taken.
|
62 | for (const WorkspaceObject& candidate : candidates) { |
| 1147 |
4/4✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
✓ Branch 6 taken 39 times.
✓ Branch 7 taken 23 times.
|
62 | if (m_workspace->canBeTarget(candidate.handle(), referenceLists)) { |
| 1148 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | return candidate.handle(); |
| 1149 | } | ||
| 1150 | } | ||
| 1151 | // none found. connect to first candidate if no strictness. | ||
| 1152 | ✗ | if ((!checkValidity) || (m_workspace->strictnessLevel() < StrictnessLevel::Draft)) { | |
| 1153 | ✗ | return candidates[0].handle(); | |
| 1154 | } | ||
| 1155 | ✗ | return boost::none; | |
| 1156 | 271 | } | |
| 1157 | |||
| 1158 | 15 | void WorkspaceObject_Impl::restoreOriginalNumFields(unsigned n) { | |
| 1159 | 15 | bool popResult = true; | |
| 1160 |
6/6✓ Branch 0 taken 17 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 16 times.
✓ Branch 6 taken 15 times.
|
31 | while (popResult && (numFields() > n)) { |
| 1161 |
1/1✓ Branch 1 taken 16 times.
|
16 | popResult = !popExtensibleGroup().empty(); |
| 1162 | } | ||
| 1163 | 15 | popResult = true; | |
| 1164 |
5/6✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 15 times.
|
29 | while (popResult && (numFields() > n)) { |
| 1165 | 14 | popResult = popField(); | |
| 1166 | } | ||
| 1167 | 15 | } | |
| 1168 | |||
| 1169 | 14 | bool WorkspaceObject_Impl::popField() { | |
| 1170 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
|
14 | if (m_handle.isNull()) { |
| 1171 | ✗ | return false; | |
| 1172 | } | ||
| 1173 | |||
| 1174 |
1/1✓ Branch 1 taken 14 times.
|
14 | unsigned index = numFields() - 1; |
| 1175 | // last field must be nonextensible, and final size must satisfy minimum number of fields | ||
| 1176 |
5/8✓ Branch 1 taken 14 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 14 times.
✓ Branch 8 taken 14 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
|
14 | if ((index >= minFields()) && (numExtensibleGroups() == 0)) { |
| 1177 | // delete field | ||
| 1178 |
4/4✓ Branch 3 taken 14 times.
✓ Branch 6 taken 14 times.
✓ Branch 9 taken 14 times.
✓ Branch 12 taken 14 times.
|
14 | m_diffs.push_back(IdfObjectDiff(index, m_fields[index], boost::none)); |
| 1179 | 14 | m_fields.pop_back(); | |
| 1180 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
14 | if (m_fieldComments.size() > m_fields.size()) { |
| 1181 | ✗ | m_fieldComments.resize(m_fields.size()); | |
| 1182 | } | ||
| 1183 | } else { | ||
| 1184 | ✗ | return false; | |
| 1185 | } | ||
| 1186 | |||
| 1187 |
2/3✓ Branch 2 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
|
14 | if (canBeSource(index)) { |
| 1188 | // pointer field | ||
| 1189 | ✗ | OS_ASSERT(m_sourceData); | |
| 1190 | // nullify the pointer | ||
| 1191 | ✗ | nullifyPointer(index); | |
| 1192 | // get the pointer | ||
| 1193 | ✗ | auto fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index); | |
| 1194 | ✗ | OS_ASSERT(fpIt != m_sourceData->pointers.end()); | |
| 1195 | // erase the pointer | ||
| 1196 | ✗ | m_sourceData->pointers.erase(fpIt); | |
| 1197 | } | ||
| 1198 | |||
| 1199 | 14 | return true; | |
| 1200 | } | ||
| 1201 | |||
| 1202 | // QUERY HELPERS | ||
| 1203 | |||
| 1204 | 995303 | void WorkspaceObject_Impl::populateValidityReport(ValidityReport& report, bool checkNames) const { | |
| 1205 | // StrictnessLevel::Minimal | ||
| 1206 |
4/4✓ Branch 1 taken 995303 times.
✓ Branch 4 taken 995303 times.
✓ Branch 7 taken 995072 times.
✓ Branch 8 taken 231 times.
|
995303 | if (report.level() > StrictnessLevel::None) { |
| 1207 | // DataErrorType::NotInitialized | ||
| 1208 | // object-level | ||
| 1209 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 995069 times.
|
995072 | if (!initialized()) { |
| 1210 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | report.insertError(DataError(getObject<WorkspaceObject>(), DataErrorType(DataErrorType::NotInitialized))); |
| 1211 | 3 | return; | |
| 1212 | } | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | // NOW INHERIT FROM IDFOBJECT | ||
| 1216 | 995300 | IdfObject_Impl::populateValidityReport(report, checkNames); | |
| 1217 | |||
| 1218 | // StrictnessLevel::Draft | ||
| 1219 |
4/4✓ Branch 1 taken 995300 times.
✓ Branch 4 taken 995300 times.
✓ Branch 7 taken 850238 times.
✓ Branch 8 taken 145062 times.
|
995300 | if (report.level() > StrictnessLevel::Minimal) { |
| 1220 | // DataErrorType::NameConflict | ||
| 1221 | // object-level | ||
| 1222 |
6/6✓ Branch 0 taken 466 times.
✓ Branch 1 taken 849772 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 460 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 850232 times.
|
850238 | if (checkNames && !uniquelyIdentifiableByName()) { |
| 1223 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
|
6 | report.insertError(DataError(getObject<WorkspaceObject>(), DataErrorType(DataErrorType::NameConflict))); |
| 1224 | } | ||
| 1225 | } // StrictnessLevel::Draft | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | 190383 | bool WorkspaceObject_Impl::uniquelyIdentifiableByName() const { | |
| 1229 |
1/1✓ Branch 1 taken 190383 times.
|
190383 | OptionalString oName = name(); |
| 1230 |
2/2✓ Branch 1 taken 47 times.
✓ Branch 2 taken 190336 times.
|
190383 | if (!oName) { |
| 1231 | 47 | return true; | |
| 1232 | } | ||
| 1233 |
3/3✓ Branch 1 taken 190336 times.
✓ Branch 4 taken 190336 times.
✓ Branch 7 taken 190336 times.
|
190336 | WorkspaceObjectVector candidates = m_workspace->getObjectsByReference(iddObject().references()); |
| 1234 |
2/2✓ Branch 5 taken 17647467 times.
✓ Branch 6 taken 187958 times.
|
17835425 | for (const WorkspaceObject& candidate : candidates) { |
| 1235 |
4/6✓ Branch 1 taken 17647467 times.
✓ Branch 4 taken 17647467 times.
✓ Branch 8 taken 561192 times.
✓ Branch 9 taken 17086275 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
35294934 | if ((candidate.iddObject().type() == openstudio::IddObjectType::OS_Connection) |
| 1236 |
9/14✓ Branch 1 taken 17647467 times.
✓ Branch 3 taken 17647467 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 17647467 times.
✓ Branch 9 taken 17647467 times.
✓ Branch 12 taken 17647467 times.
✓ Branch 15 taken 561192 times.
✓ Branch 16 taken 17086275 times.
✓ Branch 17 taken 17647467 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 17647467 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
35294934 | || (candidate.iddObject().type() == openstudio::IddObjectType::OS_PortList)) { |
| 1237 | 561192 | continue; | |
| 1238 | } | ||
| 1239 |
1/1✓ Branch 1 taken 17086275 times.
|
17086275 | OptionalString candidateName = candidate.name(); |
| 1240 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 17086275 times.
✗ Branch 4 not taken.
|
17086275 | OS_ASSERT(candidateName); |
| 1241 |
16/18✓ Branch 1 taken 17086275 times.
✓ Branch 4 taken 17086275 times.
✓ Branch 7 taken 17086275 times.
✓ Branch 9 taken 73165 times.
✓ Branch 10 taken 17013110 times.
✓ Branch 12 taken 73165 times.
✓ Branch 14 taken 73147 times.
✓ Branch 15 taken 18 times.
✓ Branch 17 taken 73147 times.
✓ Branch 20 taken 73147 times.
✓ Branch 22 taken 2360 times.
✓ Branch 23 taken 70787 times.
✓ Branch 24 taken 73147 times.
✓ Branch 25 taken 17013128 times.
✓ Branch 27 taken 2378 times.
✓ Branch 28 taken 17083897 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
|
17086275 | if ((istringEqual(*oName, *candidateName) && (!initialized() || (getObject<WorkspaceObject>() != candidate)))) { |
| 1242 | 2378 | return false; | |
| 1243 | } | ||
| 1244 | 17086275 | } | |
| 1245 | 187958 | return true; | |
| 1246 | 190383 | } | |
| 1247 | |||
| 1248 | 10952479 | bool WorkspaceObject_Impl::fieldDataIsCorrectType(unsigned index) const { | |
| 1249 |
2/2✓ Branch 1 taken 10952479 times.
✓ Branch 4 taken 10952479 times.
|
10952479 | OptionalIddField oIddField = iddObject().getField(index); |
| 1250 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10952479 times.
|
10952479 | if (!oIddField) { |
| 1251 | ✗ | return true; | |
| 1252 | } | ||
| 1253 | |||
| 1254 |
1/1✓ Branch 1 taken 10952479 times.
|
10952479 | IddField iddField = *oIddField; |
| 1255 |
1/1✓ Branch 1 taken 10952479 times.
|
10952479 | IddFieldType fieldType = iddField.properties().type; |
| 1256 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 10952479 times.
✗ Branch 4 not taken.
|
10952479 | OS_ASSERT(m_fields.size() > index); |
| 1257 | |||
| 1258 | 10952479 | bool result = true; | |
| 1259 |
6/7✓ Branch 1 taken 10952479 times.
✓ Branch 4 taken 2312851 times.
✓ Branch 5 taken 8639628 times.
✓ Branch 7 taken 2312851 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2312851 times.
✓ Branch 10 taken 8639628 times.
|
13265330 | if ((fieldType == IddFieldType::ObjectListType) && m_sourceData) { |
| 1260 | // automatically excludes unsupported reference lists by going through m_sourceData | ||
| 1261 |
2/2✓ Branch 1 taken 2312851 times.
✓ Branch 4 taken 2312851 times.
|
2312851 | auto it = getConstIteratorAtFieldIndex<SourceData>(m_sourceData.get().pointers, index); |
| 1262 |
3/3✓ Branch 1 taken 2312851 times.
✓ Branch 5 taken 2311504 times.
✓ Branch 6 taken 1347 times.
|
2312851 | if (it != m_sourceData.get().pointers.end()) { |
| 1263 | 2311504 | ForwardPointer ptr = *it; | |
| 1264 |
2/2✓ Branch 1 taken 1095439 times.
✓ Branch 2 taken 1216065 times.
|
2311504 | if (!ptr.targetHandle.isNull()) { |
| 1265 |
3/3✓ Branch 1 taken 1095439 times.
✓ Branch 4 taken 1095439 times.
✓ Branch 7 taken 1095439 times.
|
1095439 | result = m_workspace->canBeTarget(ptr.targetHandle, iddObject().objectLists(index)); |
| 1266 | } | ||
| 1267 | } | ||
| 1268 | } else { | ||
| 1269 |
1/1✓ Branch 1 taken 8639628 times.
|
8639628 | result = IdfObject_Impl::fieldDataIsCorrectType(index); |
| 1270 | } | ||
| 1271 | |||
| 1272 | 10952479 | return result; | |
| 1273 | 10952479 | } | |
| 1274 | |||
| 1275 | 28267 | bool WorkspaceObject_Impl::fieldIsNonnullIfRequired(unsigned index) const { | |
| 1276 | 28267 | bool result = true; | |
| 1277 | |||
| 1278 |
2/2✓ Branch 1 taken 28267 times.
✓ Branch 4 taken 28267 times.
|
28267 | OptionalIddField oIddField = iddObject().getField(index); |
| 1279 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28267 times.
|
28267 | if (!oIddField) { |
| 1280 | ✗ | return result; | |
| 1281 | } | ||
| 1282 | |||
| 1283 |
1/1✓ Branch 1 taken 28267 times.
|
28267 | IddField field = *oIddField; |
| 1284 |
2/2✓ Branch 1 taken 24083 times.
✓ Branch 2 taken 4184 times.
|
56534 | if (m_sourceData) { |
| 1285 |
2/2✓ Branch 1 taken 24083 times.
✓ Branch 4 taken 24083 times.
|
24083 | auto it = getConstIteratorAtFieldIndex<SourceData>(m_sourceData.get().pointers, index); |
| 1286 |
3/3✓ Branch 1 taken 24083 times.
✓ Branch 5 taken 4601 times.
✓ Branch 6 taken 19482 times.
|
24083 | if (it != m_sourceData.get().pointers.end()) { |
| 1287 |
7/7✓ Branch 2 taken 1014 times.
✓ Branch 3 taken 3587 times.
✓ Branch 5 taken 1014 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 1009 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 4596 times.
|
4601 | if (it->targetHandle.isNull() && field.properties().required) { |
| 1288 | 5 | result = false; | |
| 1289 | } | ||
| 1290 | 4601 | return result; | |
| 1291 | } | ||
| 1292 | } | ||
| 1293 | // not managed by WorkspaceObject_Impl, defer to IdfObject_Impl | ||
| 1294 |
1/1✓ Branch 1 taken 23666 times.
|
23666 | result = IdfObject_Impl::fieldIsNonnullIfRequired(index); |
| 1295 | 23666 | return result; | |
| 1296 | 28267 | } | |
| 1297 | |||
| 1298 | } // namespace detail | ||
| 1299 | |||
| 1300 | 6492944 | bool WorkspaceObject::operator<(const WorkspaceObject& right) const { | |
| 1301 | 6492944 | return (getImpl<detail::WorkspaceObject_Impl>()) < (right.getImpl<detail::WorkspaceObject_Impl>()); | |
| 1302 | } | ||
| 1303 | |||
| 1304 | 5830 | std::vector<IdfObject> WorkspaceObject::remove() { | |
| 1305 |
1/1✓ Branch 3 taken 5830 times.
|
5830 | return getImpl<detail::WorkspaceObject_Impl>()->remove(); |
| 1306 | } | ||
| 1307 | |||
| 1308 | // GETTERS | ||
| 1309 | |||
| 1310 | 10750 | Workspace WorkspaceObject::workspace() const { | |
| 1311 |
1/1✓ Branch 3 taken 10750 times.
|
10750 | return getImpl<detail::WorkspaceObject_Impl>()->workspace(); |
| 1312 | } | ||
| 1313 | |||
| 1314 | 3621880 | OptionalWorkspaceObject WorkspaceObject::getTarget(unsigned index) const { | |
| 1315 |
1/1✓ Branch 3 taken 3621880 times.
|
3621880 | return getImpl<WorkspaceObject_Impl>()->getTarget(index); |
| 1316 | } | ||
| 1317 | |||
| 1318 | 31563 | WorkspaceObjectVector WorkspaceObject::targets() const { | |
| 1319 |
1/1✓ Branch 3 taken 31563 times.
|
31563 | return getImpl<WorkspaceObject_Impl>()->targets(); |
| 1320 | } | ||
| 1321 | |||
| 1322 | 7435 | std::vector<unsigned> WorkspaceObject::getSourceIndices(const Handle& targetHandle) const { | |
| 1323 |
1/1✓ Branch 3 taken 7435 times.
|
7435 | return getImpl<WorkspaceObject_Impl>()->getSourceIndices(targetHandle); |
| 1324 | } | ||
| 1325 | |||
| 1326 | 132974 | std::vector<WorkspaceObject> WorkspaceObject::sources() const { | |
| 1327 |
1/1✓ Branch 3 taken 132974 times.
|
132974 | return getImpl<WorkspaceObject_Impl>()->sources(); |
| 1328 | } | ||
| 1329 | |||
| 1330 | 2035697 | std::vector<WorkspaceObject> WorkspaceObject::getSources(IddObjectType objectType) const { | |
| 1331 |
1/1✓ Branch 3 taken 2035697 times.
|
2035697 | return getImpl<WorkspaceObject_Impl>()->getSources(objectType); |
| 1332 | } | ||
| 1333 | |||
| 1334 | // SETTERS | ||
| 1335 | |||
| 1336 | 89084 | bool WorkspaceObject::setPointer(unsigned index, const Handle& targetHandle) { | |
| 1337 |
1/1✓ Branch 3 taken 89084 times.
|
89084 | return getImpl<WorkspaceObject_Impl>()->setPointer(index, targetHandle); |
| 1338 | } | ||
| 1339 | |||
| 1340 | // QUERIES | ||
| 1341 | |||
| 1342 | 7974017 | bool WorkspaceObject::initialized() const { | |
| 1343 |
1/1✓ Branch 3 taken 7974017 times.
|
7974017 | return getImpl<WorkspaceObject_Impl>()->initialized(); |
| 1344 | } | ||
| 1345 | |||
| 1346 | 48 | unsigned WorkspaceObject::numSources() const { | |
| 1347 |
1/1✓ Branch 3 taken 48 times.
|
48 | return getImpl<WorkspaceObject_Impl>()->numSources(); |
| 1348 | } | ||
| 1349 | |||
| 1350 | 5 | bool WorkspaceObject::isSource() const { | |
| 1351 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<WorkspaceObject_Impl>()->isSource(); |
| 1352 | } | ||
| 1353 | |||
| 1354 | 5 | bool WorkspaceObject::canBeSource() const { | |
| 1355 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<WorkspaceObject_Impl>()->canBeSource(); |
| 1356 | } | ||
| 1357 | |||
| 1358 | 40 | bool WorkspaceObject::canBeSource(unsigned index, const StringVector& refLists) const { | |
| 1359 |
1/1✓ Branch 3 taken 40 times.
|
40 | return getImpl<WorkspaceObject_Impl>()->canBeSource(index, refLists); |
| 1360 | } | ||
| 1361 | |||
| 1362 | 11 | bool WorkspaceObject::isTarget() const { | |
| 1363 |
1/1✓ Branch 3 taken 11 times.
|
11 | return getImpl<WorkspaceObject_Impl>()->isTarget(); |
| 1364 | } | ||
| 1365 | |||
| 1366 | ✗ | std::vector<std::string> WorkspaceObject::canBeTarget() const { | |
| 1367 | ✗ | return getImpl<WorkspaceObject_Impl>()->canBeTarget(); | |
| 1368 | } | ||
| 1369 | |||
| 1370 | ✗ | bool WorkspaceObject::objectListFieldsEqual(const WorkspaceObject& other) const { | |
| 1371 | ✗ | return getImpl<WorkspaceObject_Impl>()->objectListFieldsEqual(other); | |
| 1372 | } | ||
| 1373 | |||
| 1374 | 2068 | bool WorkspaceObject::objectListFieldsNonConflicting(const WorkspaceObject& other) const { | |
| 1375 |
1/1✓ Branch 3 taken 2068 times.
|
2068 | return getImpl<WorkspaceObject_Impl>()->objectListFieldsNonConflicting(other); |
| 1376 | } | ||
| 1377 | |||
| 1378 | // SERIALIZATION | ||
| 1379 | |||
| 1380 | 6251 | IdfObject WorkspaceObject::idfObject() { | |
| 1381 |
2/2✓ Branch 3 taken 6251 times.
✓ Branch 6 taken 6251 times.
|
6251 | IdfObject object(getImpl<WorkspaceObject_Impl>()->idfObjectImplPtr()); |
| 1382 | 6251 | return object; | |
| 1383 | } | ||
| 1384 | |||
| 1385 | 174990 | IdfObject WorkspaceObject::idfObject() const { | |
| 1386 |
2/2✓ Branch 3 taken 174990 times.
✓ Branch 6 taken 174990 times.
|
174990 | IdfObject object(getImpl<detail::WorkspaceObject_Impl>()->idfObjectImplPtr()); |
| 1387 | 174990 | return object; | |
| 1388 | } | ||
| 1389 | |||
| 1390 | // PROTECTED | ||
| 1391 | |||
| 1392 |
1/1✓ Branch 3 taken 53706247 times.
|
53706247 | WorkspaceObject::WorkspaceObject(std::shared_ptr<detail::WorkspaceObject_Impl> impl) : IdfObject(std::move(impl)) {} |
| 1393 | |||
| 1394 | 12 | std::ostream& operator<<(std::ostream& os, const WorkspaceObject& workspaceObject) { | |
| 1395 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | os << workspaceObject.idfObject(); |
| 1396 | 12 | return os; | |
| 1397 | } | ||
| 1398 | |||
| 1399 | } // namespace openstudio | ||
| 1400 |