Blender V5.3
makesrna_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <sstream>
10#include <utility>
11
12#include "makesrna_utils.hh"
13
14#include "BLI_string.hh"
15#include "BLI_string_ref.hh"
16
17namespace blender {
18
23
25{
26 StringRef namespace_name;
27 StringRef struct_name;
28 int namespace_length = full_name.find_last_of("::");
29 if (namespace_length != StringRef::not_found) {
30 namespace_name = full_name.substr(0, namespace_length - 1);
31 struct_name = full_name.substr(namespace_length + 1);
32 }
33 else {
34 struct_name = full_name;
35 }
36 return {namespace_name, struct_name};
37}
38
39void rna_write_struct_forward_declarations(std::ostringstream &stream, Vector<StringRef> structs)
40{
41 std::stable_sort(structs.begin(), structs.end(), [](const StringRef a, const StringRef b) {
42 /* Keep structs within namespaces last. */
43 const StructSplitName a_name_split = rna_split_namespace_struct_name(a);
44 const StructSplitName b_name_split = rna_split_namespace_struct_name(b);
45 return (a_name_split.namespace_name < b_name_split.namespace_name) ||
46 (a_name_split.namespace_name == b_name_split.namespace_name &&
47 BLI_strcasecmp(a_name_split.struct_name.data(), b_name_split.struct_name.data()) < 0);
48 });
49
50 /* For grouping structs within namespaces. */
51 StringRef last_namespace = "";
52 for (const StringRef full_name : structs) {
53 const StructSplitName name_split = rna_split_namespace_struct_name(full_name);
54 if (name_split.namespace_name != last_namespace && !last_namespace.is_empty()) {
55 stream << "}; // namespace " << std::string_view(last_namespace) << '\n';
56 }
57 if (name_split.namespace_name != last_namespace && !name_split.namespace_name.is_empty()) {
58 stream << "namespace " << std::string_view(name_split.namespace_name) << " {\n";
59 }
60 stream << "struct " << std::string_view(name_split.struct_name) << ";\n";
61 last_namespace = name_split.namespace_name;
62 }
63 if (!last_namespace.is_empty()) {
64 stream << "}; // namespace " << std::string_view(last_namespace) << '\n';
65 }
66}
67
68} // namespace blender
static constexpr int64_t not_found
constexpr bool is_empty() const
BMesh Iterators.
void rna_write_struct_forward_declarations(std::ostringstream &stream, Vector< StringRef > structs)
static StructSplitName rna_split_namespace_struct_name(StringRef full_name)