| 150 | } |
| 151 | |
| 152 | boost::optional<std::string> WorkspaceObject_Impl::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const { |
| 153 | if (canBeSource(index) && (index < numFields())) { |
| 154 | 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 | OptionalWorkspaceObject oTarget = getTarget(index); |
| 161 | if (!oTarget) { |
| 162 | // implicitly or explicitly a null pointer |
| 163 | if (returnDefault) { |
| 164 | // get default from idd and return if exists |
| 165 | OptionalIddField iddField = iddObject().getField(index); |
| 166 | OS_ASSERT(iddField); |
| 167 | if (iddField->properties().stringDefault) { |
| 168 | return iddField->properties().stringDefault; |
| 169 | } |
| 170 | } |
| 171 | if (returnUninitializedEmpty) { |
| 172 | return boost::none; |
| 173 | } |
| 174 | return std::string(); |
| 175 | } else { |
| 176 | // return target's name |
| 177 | if (auto s = oTarget->name()) { |
| 178 | return s.get(); |
| 179 | } else { |
| 180 | // Fall back to handle if it doesn't have a name |
| 181 | return openstudio::toString(oTarget->handle()); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // regular field, let IdfObject_Impl take care of it |
| 187 | return IdfObject_Impl::getString(index, returnDefault, returnUninitializedEmpty); |
| 188 | } |
| 189 | |
| 190 | boost::optional<std::string> WorkspaceObject_Impl::getField(unsigned index, bool returnDefault) const { |
| 191 | boost::optional<std::string> result; |