00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OpenSpace3D 00004 For the latest info, see http://www.openspace3d.com 00005 00006 Copyright (c) 2010 I-maginer 00007 00008 This program is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU Lesser General Public License as published by the Free Software 00010 Foundation; either version 2 of the License, or (at your option) any later 00011 version. 00012 00013 This program is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License along with 00018 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00019 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00020 http://www.gnu.org/copyleft/lesser.txt 00021 00022 You may alternatively use this source under the terms of a specific version of 00023 the OpenSpace3D Unrestricted License provided you have obtained such a license from 00024 I-maginer. 00025 ----------------------------------------------------------------------------- 00026 */ 00027 00028 #include "SO3UserObjectBindings.h" 00029 00030 namespace SO3 00031 { 00032 00033 SAny SUserObjectBindings::msEmptyAny; 00034 00035 SUserObjectBindings::SUserObjectBindings() 00036 { 00037 mAttributes = NULL; 00038 } 00039 00040 SUserObjectBindings::~SUserObjectBindings() 00041 { 00042 Clear(); 00043 } 00044 00045 void SUserObjectBindings::SetUserAny(const SAny& anything) 00046 { 00047 // Allocate attributes on demand. 00048 if (mAttributes == NULL) 00049 mAttributes = new SUserObjectBindings::Attributes; 00050 00051 mAttributes->mKeylessAny = anything; 00052 } 00053 00054 const SAny& SUserObjectBindings::GetUserAny() const 00055 { 00056 // Allocate attributes on demand. 00057 if (mAttributes == NULL) 00058 mAttributes = new SUserObjectBindings::Attributes; 00059 00060 return mAttributes->mKeylessAny; 00061 } 00062 00063 void SUserObjectBindings::SetUserAny(const std::string& key, const SAny& anything) 00064 { 00065 // Allocate attributes on demand. 00066 if (mAttributes == NULL) 00067 mAttributes = new SUserObjectBindings::Attributes; 00068 00069 if (mAttributes->mpUserObjectsMap == NULL) 00070 mAttributes->mpUserObjectsMap = new UserObjectsMap; 00071 00072 (*mAttributes->mpUserObjectsMap)[key] = anything; 00073 } 00074 00075 const SAny& SUserObjectBindings::GetUserAny(const std::string& key) const 00076 { 00077 // Allocate attributes on demand. 00078 if (mAttributes == NULL) 00079 mAttributes = new SUserObjectBindings::Attributes; 00080 00081 // Case map doesn't exists. 00082 if (mAttributes->mpUserObjectsMap == NULL) 00083 return msEmptyAny; 00084 00085 UserObjectsMapConstIterator it = mAttributes->mpUserObjectsMap->find(key); 00086 if (it != mAttributes->mpUserObjectsMap->end()) 00087 return it->second; 00088 00089 return msEmptyAny; 00090 } 00091 00092 void SUserObjectBindings::EraseUserAny(const std::string& key) 00093 { 00094 // Case attributes and map allocated. 00095 if(mAttributes != NULL && mAttributes->mpUserObjectsMap != NULL) 00096 { 00097 UserObjectsMapIterator it = mAttributes->mpUserObjectsMap->find(key); 00098 if (it != mAttributes->mpUserObjectsMap->end()) 00099 mAttributes->mpUserObjectsMap->erase(it); 00100 } 00101 } 00102 00103 void SUserObjectBindings::Clear() const 00104 { 00105 if (mAttributes != NULL) 00106 { 00107 SAFE_DELETE(mAttributes); 00108 } 00109 } 00110 00111 }
1.6.3