OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
uid.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Capgemini Engineering Research and Development.
2//
3// This file is part of OCCT-Light software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Affero General Public License version 3 as published
7// by the Free Software Foundation, with an option to use any later version.
8// Consult the file LICENSE_AGPL_30.txt included in OCCT-Light distribution
9// for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of a commercial
12// license or contractual agreement.
13//
14// SPDX-License-Identifier: AGPL-3.0-or-later
15
21#ifndef OCCTL_HPP_UID_HPP
22#define OCCTL_HPP_UID_HPP
23
24#include <occtl-hpp/core.hpp>
25
26#include <occtl/occtl_topo.h>
27
28#include <array>
29#include <cstdint>
30
31namespace occtl
32{
33
38class UID
39{
40public:
42 explicit UID(const ::occtl_uid_t theUid) noexcept
43 : myUid(theUid)
44 {
45 }
46
48 static UID invalid() noexcept { return UID(OCCTL_UID_INVALID); }
49
51 ::occtl_uid_t get() const noexcept { return myUid; }
52
53 bool is_valid() const noexcept
54 {
55 return myUid.bits != 0;
56 }
57
58 bool operator==(const UID& theOther) const noexcept
59 {
60 return myUid.bits == theOther.myUid.bits;
61 }
62
63 bool operator!=(const UID& theOther) const noexcept
64 {
65 return myUid.bits != theOther.myUid.bits;
66 }
67
68private:
69 ::occtl_uid_t myUid;
70};
71
76class RefUID
77{
78public:
80 explicit RefUID(const ::occtl_ref_uid_t theUid) noexcept
81 : myUid(theUid)
82 {
83 }
84
86 static RefUID invalid() noexcept { return RefUID(OCCTL_REF_UID_INVALID); }
87
89 ::occtl_ref_uid_t get() const noexcept { return myUid; }
90
93 static RefUID from_bytes(const std::array<std::uint8_t, OCCTL_REF_UID_WIRE_SIZE>& theBytes)
94 {
95 ::occtl_ref_uid_t aUid = OCCTL_REF_UID_INVALID;
96 check(::occtl_ref_uid_from_bytes(theBytes.data(), &aUid));
97 return RefUID(aUid);
98 }
99
101 std::array<std::uint8_t, OCCTL_REF_UID_WIRE_SIZE> to_bytes() const
102 {
103 std::array<std::uint8_t, OCCTL_REF_UID_WIRE_SIZE> aBytes{};
104 check(::occtl_ref_uid_to_bytes(myUid, aBytes.data()));
105 return aBytes;
106 }
107
108 bool is_valid() const noexcept
109 {
110 return myUid.bits != 0;
111 }
112
113 bool operator==(const RefUID& theOther) const noexcept
114 {
115 return myUid.bits == theOther.myUid.bits;
116 }
117
118 bool operator!=(const RefUID& theOther) const noexcept
119 {
120 return myUid.bits != theOther.myUid.bits;
121 }
122
123private:
124 ::occtl_ref_uid_t myUid;
125};
126
132{
133public:
135 explicit RepUID(const ::occtl_rep_uid_t theUid) noexcept
136 : myUid(theUid)
137 {
138 }
139
141 static RepUID invalid() noexcept { return RepUID(OCCTL_REP_UID_INVALID); }
142
144 ::occtl_rep_uid_t get() const noexcept { return myUid; }
145
148 static RepUID from_bytes(const std::array<std::uint8_t, OCCTL_REP_UID_WIRE_SIZE>& theBytes)
149 {
150 ::occtl_rep_uid_t aUid = OCCTL_REP_UID_INVALID;
151 check(::occtl_rep_uid_from_bytes(theBytes.data(), &aUid));
152 return RepUID(aUid);
153 }
154
156 std::array<std::uint8_t, OCCTL_REP_UID_WIRE_SIZE> to_bytes() const
157 {
158 std::array<std::uint8_t, OCCTL_REP_UID_WIRE_SIZE> aBytes{};
159 check(::occtl_rep_uid_to_bytes(myUid, aBytes.data()));
160 return aBytes;
161 }
162
163 bool is_valid() const noexcept
164 {
165 return myUid.bits != 0;
166 }
167
168 bool operator==(const RepUID& theOther) const noexcept
169 {
170 return myUid.bits == theOther.myUid.bits;
171 }
172
173 bool operator!=(const RepUID& theOther) const noexcept
174 {
175 return myUid.bits != theOther.myUid.bits;
176 }
177
178private:
179 ::occtl_rep_uid_t myUid;
180};
181
182} // namespace occtl
183
184#endif // OCCTL_HPP_UID_HPP
Persistent identity surviving reference removal and graph compaction.
Definition uid.hpp:77
bool is_valid() const noexcept
True when the UID is not the all-zero sentinel.
Definition uid.hpp:108
static RefUID from_bytes(const std::array< std::uint8_t, OCCTL_REF_UID_WIRE_SIZE > &theBytes)
Decodes a RefUID from the fixed-width C wire format.
Definition uid.hpp:93
bool operator!=(const RefUID &theOther) const noexcept
Bitwise inequality.
Definition uid.hpp:118
static RefUID invalid() noexcept
Returns the invalid sentinel (all-zero bits).
Definition uid.hpp:86
std::array< std::uint8_t, OCCTL_REF_UID_WIRE_SIZE > to_bytes() const
Encodes this RefUID into the fixed-width C wire format.
Definition uid.hpp:101
bool operator==(const RefUID &theOther) const noexcept
Bitwise equality.
Definition uid.hpp:113
RefUID(const ::occtl_ref_uid_t theUid) noexcept
Wraps an existing C value type (zero-cost).
Definition uid.hpp:80
::occtl_ref_uid_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition uid.hpp:89
Persistent identity surviving representation removal and graph compaction.
Definition uid.hpp:132
::occtl_rep_uid_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition uid.hpp:144
static RepUID from_bytes(const std::array< std::uint8_t, OCCTL_REP_UID_WIRE_SIZE > &theBytes)
Decodes a RepUID from the fixed-width C wire format.
Definition uid.hpp:148
std::array< std::uint8_t, OCCTL_REP_UID_WIRE_SIZE > to_bytes() const
Encodes this RepUID into the fixed-width C wire format.
Definition uid.hpp:156
bool is_valid() const noexcept
True when the UID is not the all-zero sentinel.
Definition uid.hpp:163
bool operator==(const RepUID &theOther) const noexcept
Bitwise equality.
Definition uid.hpp:168
static RepUID invalid() noexcept
Returns the invalid sentinel (all-zero bits).
Definition uid.hpp:141
RepUID(const ::occtl_rep_uid_t theUid) noexcept
Wraps an existing C value type (zero-cost).
Definition uid.hpp:135
bool operator!=(const RepUID &theOther) const noexcept
Bitwise inequality.
Definition uid.hpp:173
Persistent identity surviving node removal and graph compaction. Mirrors occtl_uid_t.
Definition uid.hpp:39
UID(const ::occtl_uid_t theUid) noexcept
Wraps an existing C value type (zero-cost).
Definition uid.hpp:42
static UID invalid() noexcept
Returns the invalid sentinel (all-zero bits).
Definition uid.hpp:48
bool operator==(const UID &theOther) const noexcept
Bitwise equality.
Definition uid.hpp:58
::occtl_uid_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition uid.hpp:51
bool is_valid() const noexcept
True when the UID is not the all-zero sentinel.
Definition uid.hpp:53
bool operator!=(const UID &theOther) const noexcept
Bitwise inequality.
Definition uid.hpp:63
C++ veneer for the core module.
void check(const ::occtl_status_t theStatus)
Throw on non-OK; otherwise a no-op.
Definition core.hpp:85
#define OCCTL_UID_INVALID
Definition occtl_core.h:286
OCCT-Light: topology module public API.
occtl_status_t occtl_rep_uid_to_bytes(occtl_rep_uid_t rep_uid, uint8_t *out_bytes)
occtl_status_t occtl_ref_uid_from_bytes(const uint8_t *in_bytes, occtl_ref_uid_t *out_ref_uid)
occtl_status_t occtl_rep_uid_from_bytes(const uint8_t *in_bytes, occtl_rep_uid_t *out_rep_uid)
occtl_status_t occtl_ref_uid_to_bytes(occtl_ref_uid_t ref_uid, uint8_t *out_bytes)
Definition occtl_topo_types.h:76
uint64_t bits
Definition occtl_topo_types.h:77
Definition occtl_topo_types.h:91
uint64_t bits
Definition occtl_topo_types.h:92
Definition occtl_core.h:272