| 51 | } |
| 52 | |
| 53 | unsigned ResourceObject_Impl::nonResourceObjectUseCount(bool excludeChildren) const { |
| 54 | |
| 55 | unsigned result = 0; |
| 56 | |
| 57 | ModelObjectVector children; |
| 58 | if (excludeChildren) { |
| 59 | children = this->children(); |
| 60 | } |
| 61 | |
| 62 | WorkspaceObjectVector sources = this->sources(); |
| 63 | for (const WorkspaceObject& source : sources) { |
| 64 | OptionalResourceObject oro = source.optionalCast<ResourceObject>(); |
| 65 | if (oro) { |
| 66 | // another ResourceObject, pass the request through |
| 67 | result += oro->nonResourceObjectUseCount(excludeChildren); |
| 68 | } else { |
| 69 | |
| 70 | if (excludeChildren) { |
| 71 | // check if this is a child |
| 72 | auto it = std::find_if(children.cbegin(), children.cend(), |
| 73 | [h = source.handle()](const ModelObject& mo) { return handleEquals<ModelObject, Handle>(mo, h); }); |
| 74 | if (it == children.end()) { |
| 75 | // non-ResourceObject and non-Child--count the use |
| 76 | ++result; |
| 77 | } |
| 78 | } else { |
| 79 | // non-ResourceObject--count the use |
| 80 | ++result; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | } // namespace detail |
| 89 | |