|
| 1 | +/* |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +// Copyright 2013-2025 Daniel Parker |
| 17 | +// Distributed under the Boost license, Version 1.0. |
| 18 | +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 19 | + |
| 20 | +// See https://github.com/danielaparker/jsoncons for latest version |
| 21 | + |
| 22 | +#ifndef JSONCONS_ALLOCATOR_SET_HPP |
| 23 | +#define JSONCONS_ALLOCATOR_SET_HPP |
| 24 | + |
| 25 | +#include <memory> |
| 26 | + |
| 27 | +#include "velox/external/jsoncons/tag_type.hpp" |
| 28 | + |
| 29 | +namespace facebook::velox::jsoncons { |
| 30 | + |
| 31 | +template <typename Allocator,typename TempAllocator > |
| 32 | +class allocator_set |
| 33 | +{ |
| 34 | + Allocator result_alloc_; |
| 35 | + TempAllocator temp_alloc_; |
| 36 | +public: |
| 37 | + using allocator_type = Allocator; |
| 38 | + using temp_allocator_type = TempAllocator; |
| 39 | + |
| 40 | + allocator_set(const Allocator& alloc=Allocator(), |
| 41 | + const TempAllocator& temp_alloc=TempAllocator()) |
| 42 | + : result_alloc_(alloc), temp_alloc_(temp_alloc) |
| 43 | + { |
| 44 | + } |
| 45 | + |
| 46 | + allocator_set(const allocator_set&) = default; |
| 47 | + allocator_set(allocator_set&&) = default; |
| 48 | + allocator_set& operator=(const allocator_set&) = delete; |
| 49 | + allocator_set& operator=(allocator_set&&) = delete; |
| 50 | + ~allocator_set() = default; |
| 51 | + |
| 52 | + Allocator get_allocator() const {return result_alloc_;} |
| 53 | + TempAllocator get_temp_allocator() const {return temp_alloc_;} |
| 54 | +}; |
| 55 | + |
| 56 | +inline |
| 57 | +allocator_set<std::allocator<char>,std::allocator<char>> combine_allocators() |
| 58 | +{ |
| 59 | + return allocator_set<std::allocator<char>,std::allocator<char>>(std::allocator<char>(), std::allocator<char>()); |
| 60 | +} |
| 61 | + |
| 62 | +template <typename Allocator> |
| 63 | +allocator_set<Allocator,std::allocator<char>> combine_allocators(const Allocator& alloc) |
| 64 | +{ |
| 65 | + return allocator_set<Allocator,std::allocator<char>>(alloc, std::allocator<char>()); |
| 66 | +} |
| 67 | + |
| 68 | +template <typename Allocator,typename TempAllocator > |
| 69 | +allocator_set<Allocator,TempAllocator> combine_allocators(const Allocator& alloc, const TempAllocator& temp_alloc) |
| 70 | +{ |
| 71 | + return allocator_set<Allocator,TempAllocator>(alloc, temp_alloc); |
| 72 | +} |
| 73 | + |
| 74 | +template <typename TempAllocator > |
| 75 | +allocator_set<std::allocator<char>,TempAllocator> temp_allocator_only(const TempAllocator& temp_alloc) |
| 76 | +{ |
| 77 | + return allocator_set<std::allocator<char>,TempAllocator>(std::allocator<char>(), temp_alloc); |
| 78 | +} |
| 79 | + |
| 80 | +} // namespace facebook::velox::jsoncons |
| 81 | + |
| 82 | +#endif // JSONCONS_ALLOCATOR_SET_HPP |
0 commit comments