Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / model-factory.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/modeling/model-factory.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/event/resources/resource-client.h>
22
23 using namespace Dali::Integration;
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 ModelFactory::ModelFactory( ResourceClient& resourceClient )
32 : mResourceClient( resourceClient )
33 {
34 }
35
36 ModelFactory::~ModelFactory()
37 {
38 }
39
40 ResourceTicketPtr ModelFactory::Load( const std::string& filename )
41 {
42   ResourceTicketPtr ticket;
43   ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
44   ResourceTypePath typePath(modelResourceType, filename);
45
46   // Search for a matching resource
47   ResourceTypePathIdIter iter = mResourceTypePathIdMap.end();
48   if ( !mResourceTypePathIdMap.empty() )
49   {
50     iter = mResourceTypePathIdMap.find( typePath );
51   }
52
53   if ( mResourceTypePathIdMap.end() != iter )
54   {
55     // The resource was previously requested
56     unsigned int resourceId = iter->second;
57
58     // The resource may still be alive; share the ticket
59     ticket = mResourceClient.RequestResourceTicket( resourceId );
60
61     // Clean-up the map of resource IDs, if the ticket has been discarded
62     if ( !ticket )
63     {
64       mResourceTypePathIdMap.erase( iter );
65     }
66   }
67
68   // Request a new model resource, if necessary
69   if ( !ticket )
70   {
71     ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
72     ticket = mResourceClient.RequestResource(modelResourceType, filename);
73
74     mResourceTypePathIdMap.insert( ResourceTypePathIdPair( typePath, ticket->GetId() ) );
75   }
76
77   return ticket;
78 }
79
80 } // namespace Internal
81
82 } // namespace Dali