/**************************************************************************** Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd. http://www.cocos.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #pragma once #include #include #include #include #include "cocos/base/std/container/unordered_map.h" #include "cocos/renderer/pipeline/custom/details/Pmr.h" #include "cocos/renderer/pipeline/custom/details/Utility.h" // for std::less<> the transparent comparator // see https://stackoverflow.com/questions/20317413/what-are-transparent-comparators namespace cc { // map template using PmrMap = std::map< Key, Value, std::less, boost::container::pmr::polymorphic_allocator>>; template using PmrMultiMap = std::multimap< Key, Value, std::less, boost::container::pmr::polymorphic_allocator>>; template using TransparentMap = std::map>; template using TransparentMultiMap = std::multimap>; template using PmrTransparentMap = std::map< Key, Value, std::less<>, boost::container::pmr::polymorphic_allocator>>; template using PmrTransparentMultiMap = std::multimap< Key, Value, std::less<>, boost::container::pmr::polymorphic_allocator>>; // flat_map template using FlatMap = boost::container::flat_map>; template using FlatMultiMap = boost::container::flat_multimap>; template using PmrFlatMap = boost::container::pmr::flat_map>; template using PmrFlatMultiMap = boost::container::pmr::flat_multimap>; // unordered_map template using PmrUnorderedMap = ccstd::pmr::unordered_map; template using PmrUnorderedMultiMap = ccstd::pmr::unordered_multimap; // transparent string unordered_map template using UnorderedStringMap = std::unordered_map< Key, Value, TransparentStringHash, std::equal_to<>>; template using UnorderedStringMultiMap = std::unordered_multimap< Key, Value, TransparentStringHash, std::equal_to<>>; template using PmrUnorderedStringMap = std::unordered_map< Key, Value, TransparentStringHash, std::equal_to<>, boost::container::pmr::polymorphic_allocator>>; template using PmrUnorderedStringMultiMap = std::unordered_multimap< Key, Value, TransparentStringHash, std::equal_to<>, boost::container::pmr::polymorphic_allocator>>; template inline typename std::map, Allocator>::mapped_type& at(std::map, Allocator>& m, const KeyLike& key) { auto iter = m.find(key); if (iter == m.end()) { throw std::out_of_range("at(std::map) out of range"); } return iter->second; } template inline typename std::map, Allocator>::mapped_type const& at(const std::map, Allocator>& m, const KeyLike& key) { auto iter = m.find(key); if (iter == m.end()) { throw std::out_of_range("at(std::map) out of range"); } return iter->second; } template inline typename boost::container::flat_map, Allocator>::mapped_type& at(boost::container::flat_map, Allocator>& m, const KeyLike& key) { auto iter = m.find(key); if (iter == m.end()) { throw std::out_of_range("at(boost::container::flat_map) out of range"); } return iter->second; } template inline typename boost::container::flat_map, Allocator>::mapped_type const& at(const boost::container::flat_map, Allocator>& m, const KeyLike& key) { auto iter = m.find(key); if (iter == m.end()) { throw std::out_of_range("at(boost::container::flat_map) out of range"); } return iter->second; } } // namespace cc namespace ccstd { template struct hash> { hash_t operator()(const boost::container::flat_map& val) const noexcept { hash_t seed = 0; for (const auto& pair : val) { hash_combine(seed, pair); } return seed; } }; } // namespace ccstd