File indexing completed on 2025-02-21 09:30:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
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
0090
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