| 168 | } |
| 169 | |
| 170 | Status ResourceMgr::DoCreate(const string& container, TypeIndex type, |
| 171 | const string& name, ResourceBase* resource) { |
| 172 | Container** b = &containers_[container]; |
| 173 | if (*b == nullptr) { |
| 174 | *b = new Container; |
| 175 | } |
| 176 | |
| 177 | // NOTE: Separating out the construction of the map key and value so that the |
| 178 | // key can contain a StringPiece that borrows from the string in the value. |
| 179 | ResourceAndName resource_and_name(resource, name); |
| 180 | StringPiece borrowed_name(*resource_and_name.name); |
| 181 | Container::value_type key_and_value(Key(type.hash_code(), std::string(borrowed_name.data(), borrowed_name.size())), |
| 182 | std::move(resource_and_name)); |
| 183 | |
| 184 | if ((*b)->insert(std::move(key_and_value)).second) { |
| 185 | TF_RETURN_IF_ERROR(InsertDebugTypeName(type.hash_code(), type.name())); |
| 186 | return Status::OK(); |
| 187 | } |
| 188 | return errors::AlreadyExists("Resource ", container, "/", name, "/", |
| 189 | type.name()); |
| 190 | } |
| 191 | |
| 192 | Status ResourceMgr::DoLookup(const string& container, TypeIndex type, |
| 193 | const string& name, |