Project

General

Profile

SO3Engine
SO3UserObjectBindings.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
26
27namespace SO3
28{
29
30SAny SUserObjectBindings::msEmptyAny;
31
33{
34 mAttributes = NULL;
35}
36
41
43{
44 // Allocate attributes on demand.
45 if (mAttributes == NULL)
46 mAttributes = new SUserObjectBindings::Attributes;
47
48 mAttributes->mKeylessAny = anything;
49}
50
52{
53 // Allocate attributes on demand.
54 if (mAttributes == NULL)
55 mAttributes = new SUserObjectBindings::Attributes;
56
57 return mAttributes->mKeylessAny;
58}
59
60void SUserObjectBindings::SetUserAny(const std::string& key, const SAny& anything)
61{
62 // Allocate attributes on demand.
63 if (mAttributes == NULL)
64 mAttributes = new SUserObjectBindings::Attributes;
65
66 if (mAttributes->mpUserObjectsMap == NULL)
67 mAttributes->mpUserObjectsMap = new UserObjectsMap;
68
69 (*mAttributes->mpUserObjectsMap)[key] = anything;
70}
71
72const SAny& SUserObjectBindings::GetUserAny(const std::string& key) const
73{
74 // Allocate attributes on demand.
75 if (mAttributes == NULL)
76 mAttributes = new SUserObjectBindings::Attributes;
77
78 // Case map doesn't exists.
79 if (mAttributes->mpUserObjectsMap == NULL)
80 return msEmptyAny;
81
82 UserObjectsMapConstIterator it = mAttributes->mpUserObjectsMap->find(key);
83 if (it != mAttributes->mpUserObjectsMap->end())
84 return it->second;
85
86 return msEmptyAny;
87}
88
89void SUserObjectBindings::EraseUserAny(const std::string& key)
90{
91 // Case attributes and map allocated.
92 if(mAttributes != NULL && mAttributes->mpUserObjectsMap != NULL)
93 {
94 UserObjectsMapIterator it = mAttributes->mpUserObjectsMap->find(key);
95 if (it != mAttributes->mpUserObjectsMap->end())
96 mAttributes->mpUserObjectsMap->erase(it);
97 }
98}
99
101{
102 if (mAttributes != NULL)
103 {
104 SAFE_DELETE(mAttributes);
105 }
106}
107
108}
SAny mKeylessAny
Will hold key less associated user object for fast access.
UserObjectsMap * mpUserObjectsMap
Will hold a map between user keys to user objects.
void EraseUserAny(const std::string &key)
std::unordered_map< std::string, SAny > UserObjectsMap
UserObjectsMap::const_iterator UserObjectsMapConstIterator
UserObjectsMap::iterator UserObjectsMapIterator
void SetUserAny(const SAny &anything)