1
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29
30 // Interface header.
31 #include "itemregistry.h"
32
33 // appleseed.renderer headers.
34 #include "renderer/api/entity.h"
35
36 // Standard headers.
37 #include <cassert>
38 #include <utility>
39
40 // Qt headers.
41 #include <QMutexLocker>
42
43 using namespace foundation;
44 using namespace renderer;
45 using namespace std;
46
47 namespace appleseed {
48 namespace studio {
49
insert(const UniqueID uid,ItemBase * item)50 void ItemRegistry::insert(
51 const UniqueID uid,
52 ItemBase* item)
53 {
54 QMutexLocker locker(&m_mutex);
55
56 #ifndef NDEBUG
57 const pair<RegistryType::iterator, bool> result =
58 #endif
59 m_registry.insert(make_pair(uid, item));
60
61 assert(result.second);
62 }
63
insert(const Entity & entity,ItemBase * item)64 void ItemRegistry::insert(
65 const Entity& entity,
66 ItemBase* item)
67 {
68 insert(entity.get_uid(), item);
69 }
70
remove(const UniqueID uid)71 void ItemRegistry::remove(const UniqueID uid)
72 {
73 QMutexLocker locker(&m_mutex);
74
75 #ifndef NDEBUG
76 const RegistryType::size_type result =
77 #endif
78 m_registry.erase(uid);
79
80 assert(result == 1);
81 }
82
remove(const Entity & entity)83 void ItemRegistry::remove(const Entity& entity)
84 {
85 remove(entity.get_uid());
86 }
87
get_item(const UniqueID uid) const88 ItemBase* ItemRegistry::get_item(const UniqueID uid) const
89 {
90 QMutexLocker locker(&m_mutex);
91
92 const RegistryType::const_iterator i = m_registry.find(uid);
93
94 return i == m_registry.end() ? nullptr : i->second;
95 }
96
get_item(const Entity & entity) const97 ItemBase* ItemRegistry::get_item(const Entity& entity) const
98 {
99 return get_item(entity.get_uid());
100 }
101
102 } // namespace studio
103 } // namespace appleseed
104