Lagrange
Loading...
Searching...
No Matches
get_unique_attribute_name.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/Logger.h>
15#include <lagrange/SurfaceMesh.h>
16#include <lagrange/utils/Error.h>
17
18#include <string_view>
19
20namespace lagrange::internal {
21
36template <typename Scalar, typename Index>
37std::string get_unique_attribute_name(const SurfaceMesh<Scalar, Index>& mesh, std::string_view name)
38{
39 if (!mesh.has_attribute(name)) {
40 return std::string(name);
41 } else {
42 std::string new_name;
43 for (int cnt = 0; cnt < 1000; ++cnt) {
44 new_name = fmt::format("{}.{}", name, cnt);
45 if (!mesh.has_attribute(new_name)) {
46 logger().warn("Attribute '{}' already exists. Using '{}' instead.", name, new_name);
47 return new_name;
48 }
49 }
50 throw Error(fmt::format("Could not assign a unique attribute name for: {}", name));
51 }
52}
53
54} // namespace lagrange::internal
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:40
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
std::string get_unique_attribute_name(const SurfaceMesh< Scalar, Index > &mesh, std::string_view name)
Returns a unique attribute name by appending a suffix if necessary.
Definition get_unique_attribute_name.h:37
@ Error
Throw an error if collision is detected.
Definition MappingPolicy.h:24