Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:30:08

0001 /*
0002 Open Asset Import Library (assimp)
0003 ----------------------------------------------------------------------
0004 
0005 Copyright (c) 2006-2024, assimp team
0006 
0007 All rights reserved.
0008 
0009 Redistribution and use of this software in source and binary forms,
0010 with or without modification, are permitted provided that the
0011 following conditions are met:
0012 
0013 * Redistributions of source code must retain the above
0014   copyright notice, this list of conditions and the
0015   following disclaimer.
0016 
0017 * Redistributions in binary form must reproduce the above
0018   copyright notice, this list of conditions and the
0019   following disclaimer in the documentation and/or other
0020   materials provided with the distribution.
0021 
0022 * Neither the name of the assimp team, nor the names of its
0023   contributors may be used to endorse or promote products
0024   derived from this software without specific prior
0025   written permission of the assimp team.
0026 
0027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0028 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0029 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0030 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0031 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0032 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0033 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0034 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0035 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038 
0039 ----------------------------------------------------------------------
0040 */
0041 
0042 #pragma once
0043 #ifndef AI_GENERIC_PROPERTY_H_INCLUDED
0044 #define AI_GENERIC_PROPERTY_H_INCLUDED
0045 
0046 #ifdef __GNUC__
0047 #    pragma GCC system_header
0048 #endif
0049 
0050 #include <assimp/Hash.h>
0051 #include <assimp/ai_assert.h>
0052 #include <assimp/Importer.hpp>
0053 
0054 #include <map>
0055 
0056 // ------------------------------------------------------------------------------------------------
0057 template <class T>
0058 inline bool SetGenericProperty(std::map<unsigned int, T> &list,
0059         const char *szName, const T &value) {
0060     ai_assert(nullptr != szName);
0061     const uint32_t hash = SuperFastHash(szName);
0062 
0063     typename std::map<unsigned int, T>::iterator it = list.find(hash);
0064     if (it == list.end()) {
0065         list.insert(std::pair<unsigned int, T>(hash, value));
0066         return false;
0067     }
0068     (*it).second = value;
0069 
0070     return true;
0071 }
0072 
0073 // ------------------------------------------------------------------------------------------------
0074 template <class T>
0075 inline const T &GetGenericProperty(const std::map<unsigned int, T> &list,
0076         const char *szName, const T &errorReturn) {
0077     ai_assert(nullptr != szName);
0078     const uint32_t hash = SuperFastHash(szName);
0079 
0080     typename std::map<unsigned int, T>::const_iterator it = list.find(hash);
0081     if (it == list.end()) {
0082         return errorReturn;
0083     }
0084 
0085     return (*it).second;
0086 }
0087 
0088 // ------------------------------------------------------------------------------------------------
0089 // Special version for pointer types - they will be deleted when replaced with another value
0090 // passing nullptr removes the whole property
0091 template <class T>
0092 inline void SetGenericPropertyPtr(std::map<unsigned int, T *> &list,
0093         const char *szName, T *value, bool *bWasExisting = nullptr) {
0094     ai_assert(nullptr != szName);
0095     const uint32_t hash = SuperFastHash(szName);
0096 
0097     typename std::map<unsigned int, T *>::iterator it = list.find(hash);
0098     if (it == list.end()) {
0099         if (bWasExisting) {
0100             *bWasExisting = false;
0101         }
0102 
0103         list.insert(std::pair<unsigned int, T *>(hash, value));
0104         return;
0105     }
0106     if ((*it).second != value) {
0107         delete (*it).second;
0108         (*it).second = value;
0109     }
0110     if (!value) {
0111         list.erase(it);
0112     }
0113     if (bWasExisting) {
0114         *bWasExisting = true;
0115     }
0116 }
0117 
0118 // ------------------------------------------------------------------------------------------------
0119 template <class T>
0120 inline bool HasGenericProperty(const std::map<unsigned int, T> &list,
0121         const char *szName) {
0122     ai_assert(nullptr != szName);
0123     const uint32_t hash = SuperFastHash(szName);
0124 
0125     typename std::map<unsigned int, T>::const_iterator it = list.find(hash);
0126     if (it == list.end()) {
0127         return false;
0128     }
0129 
0130     return true;
0131 }
0132 
0133 #endif // !! AI_GENERIC_PROPERTY_H_INCLUDED