2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/event/modeling/model-factory.h>
21 #include <dali/internal/event/resources/resource-client.h>
23 using namespace Dali::Integration;
31 ModelFactory::ModelFactory( ResourceClient& resourceClient )
32 : mResourceClient( resourceClient )
36 ModelFactory::~ModelFactory()
40 ResourceTicketPtr ModelFactory::Load( const std::string& filename )
42 ResourceTicketPtr ticket;
43 ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
44 ResourceTypePath typePath(modelResourceType, filename);
46 // Search for a matching resource
47 ResourceTypePathIdIter iter = mResourceTypePathIdMap.end();
48 if ( !mResourceTypePathIdMap.empty() )
50 iter = mResourceTypePathIdMap.find( typePath );
53 if ( mResourceTypePathIdMap.end() != iter )
55 // The resource was previously requested
56 unsigned int resourceId = iter->second;
58 // The resource may still be alive; share the ticket
59 ticket = mResourceClient.RequestResourceTicket( resourceId );
61 // Clean-up the map of resource IDs, if the ticket has been discarded
64 mResourceTypePathIdMap.erase( iter );
68 // Request a new model resource, if necessary
71 ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
72 ticket = mResourceClient.RequestResource(modelResourceType, filename);
74 mResourceTypePathIdMap.insert( ResourceTypePathIdPair( typePath, ticket->GetId() ) );
80 } // namespace Internal