| 1 | #include "engine/shared/snapshot.h" |
| 2 | #include "generated/protocolglue.h" |
| 3 | #include <array> |
| 4 | #include <cassert> |
| 5 | #include <cstddef> |
| 6 | #include <cstdint> |
| 7 | #include <iterator> |
| 8 | #include <memory> |
| 9 | #include <new> |
| 10 | #include <stdexcept> |
| 11 | #include <type_traits> |
| 12 | #include <utility> |
| 13 | |
| 14 | namespace rust { |
| 15 | inline namespace cxxbridge1 { |
| 16 | // #include "rust/cxx.h" |
| 17 | |
| 18 | #ifndef CXXBRIDGE1_PANIC |
| 19 | #define CXXBRIDGE1_PANIC |
| 20 | template <typename Exception> |
| 21 | void panic [[noreturn]] (const char *msg); |
| 22 | #endif // CXXBRIDGE1_PANIC |
| 23 | |
| 24 | namespace { |
| 25 | template <typename T> |
| 26 | class impl; |
| 27 | } // namespace |
| 28 | |
| 29 | class Opaque; |
| 30 | |
| 31 | template <typename T> |
| 32 | ::std::size_t size_of(); |
| 33 | template <typename T> |
| 34 | ::std::size_t align_of(); |
| 35 | |
| 36 | #ifndef CXXBRIDGE1_RUST_SLICE |
| 37 | #define CXXBRIDGE1_RUST_SLICE |
| 38 | namespace detail { |
| 39 | template <bool> |
| 40 | struct copy_assignable_if {}; |
| 41 | |
| 42 | template <> |
| 43 | struct copy_assignable_if<false> { |
| 44 | copy_assignable_if() noexcept = default; |
| 45 | copy_assignable_if(const copy_assignable_if &) noexcept = default; |
| 46 | copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete; |
| 47 | copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default; |
| 48 | }; |
| 49 | } // namespace detail |
| 50 | |
| 51 | template <typename T> |
| 52 | class Slice final |
| 53 | : private detail::copy_assignable_if<std::is_const<T>::value> { |
| 54 | public: |
| 55 | using value_type = T; |
| 56 | |
| 57 | Slice() noexcept; |
| 58 | Slice(T *, std::size_t count) noexcept; |
| 59 | |
| 60 | Slice &operator=(const Slice<T> &) &noexcept = default; |
| 61 | Slice &operator=(Slice<T> &&) &noexcept = default; |
| 62 | |
| 63 | T *data() const noexcept; |
| 64 | std::size_t size() const noexcept; |
| 65 | std::size_t length() const noexcept; |
| 66 | bool empty() const noexcept; |
| 67 | |
| 68 | T &operator[](std::size_t n) const noexcept; |
| 69 | T &at(std::size_t n) const; |
| 70 | T &front() const noexcept; |
| 71 | T &back() const noexcept; |
| 72 | |
| 73 | Slice(const Slice<T> &) noexcept = default; |
| 74 | ~Slice() noexcept = default; |
| 75 | |
| 76 | class iterator; |
| 77 | iterator begin() const noexcept; |
| 78 | iterator end() const noexcept; |
| 79 | |
| 80 | void swap(Slice &) noexcept; |
| 81 | |
| 82 | private: |
| 83 | class uninit; |
| 84 | Slice(uninit) noexcept; |
| 85 | friend impl<Slice>; |
| 86 | friend void sliceInit(void *, const void *, std::size_t) noexcept; |
| 87 | friend void *slicePtr(const void *) noexcept; |
| 88 | friend std::size_t sliceLen(const void *) noexcept; |
| 89 | |
| 90 | std::array<std::uintptr_t, 2> repr; |
| 91 | }; |
| 92 | |
| 93 | template <typename T> |
| 94 | class Slice<T>::iterator final { |
| 95 | public: |
| 96 | using iterator_category = std::random_access_iterator_tag; |
| 97 | using value_type = T; |
| 98 | using difference_type = std::ptrdiff_t; |
| 99 | using pointer = typename std::add_pointer<T>::type; |
| 100 | using reference = typename std::add_lvalue_reference<T>::type; |
| 101 | |
| 102 | reference operator*() const noexcept; |
| 103 | pointer operator->() const noexcept; |
| 104 | reference operator[](difference_type) const noexcept; |
| 105 | |
| 106 | iterator &operator++() noexcept; |
| 107 | iterator operator++(int) noexcept; |
| 108 | iterator &operator--() noexcept; |
| 109 | iterator operator--(int) noexcept; |
| 110 | |
| 111 | iterator &operator+=(difference_type) noexcept; |
| 112 | iterator &operator-=(difference_type) noexcept; |
| 113 | iterator operator+(difference_type) const noexcept; |
| 114 | iterator operator-(difference_type) const noexcept; |
| 115 | difference_type operator-(const iterator &) const noexcept; |
| 116 | |
| 117 | bool operator==(const iterator &) const noexcept; |
| 118 | bool operator!=(const iterator &) const noexcept; |
| 119 | bool operator<(const iterator &) const noexcept; |
| 120 | bool operator<=(const iterator &) const noexcept; |
| 121 | bool operator>(const iterator &) const noexcept; |
| 122 | bool operator>=(const iterator &) const noexcept; |
| 123 | |
| 124 | private: |
| 125 | friend class Slice; |
| 126 | void *pos; |
| 127 | std::size_t stride; |
| 128 | }; |
| 129 | |
| 130 | template <typename T> |
| 131 | Slice<T>::Slice() noexcept { |
| 132 | sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0); |
| 133 | } |
| 134 | |
| 135 | template <typename T> |
| 136 | Slice<T>::Slice(T *s, std::size_t count) noexcept { |
| 137 | assert(s != nullptr || count == 0); |
| 138 | sliceInit(this, |
| 139 | s == nullptr && count == 0 |
| 140 | ? reinterpret_cast<void *>(align_of<T>()) |
| 141 | : const_cast<typename std::remove_const<T>::type *>(s), |
| 142 | count); |
| 143 | } |
| 144 | |
| 145 | template <typename T> |
| 146 | T *Slice<T>::data() const noexcept { |
| 147 | return reinterpret_cast<T *>(slicePtr(this)); |
| 148 | } |
| 149 | |
| 150 | template <typename T> |
| 151 | std::size_t Slice<T>::size() const noexcept { |
| 152 | return sliceLen(this); |
| 153 | } |
| 154 | |
| 155 | template <typename T> |
| 156 | std::size_t Slice<T>::length() const noexcept { |
| 157 | return this->size(); |
| 158 | } |
| 159 | |
| 160 | template <typename T> |
| 161 | bool Slice<T>::empty() const noexcept { |
| 162 | return this->size() == 0; |
| 163 | } |
| 164 | |
| 165 | template <typename T> |
| 166 | T &Slice<T>::operator[](std::size_t n) const noexcept { |
| 167 | assert(n < this->size()); |
| 168 | auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n; |
| 169 | return *reinterpret_cast<T *>(ptr); |
| 170 | } |
| 171 | |
| 172 | template <typename T> |
| 173 | T &Slice<T>::at(std::size_t n) const { |
| 174 | if (n >= this->size()) { |
| 175 | panic<std::out_of_range>("rust::Slice index out of range" ); |
| 176 | } |
| 177 | return (*this)[n]; |
| 178 | } |
| 179 | |
| 180 | template <typename T> |
| 181 | T &Slice<T>::front() const noexcept { |
| 182 | assert(!this->empty()); |
| 183 | return (*this)[0]; |
| 184 | } |
| 185 | |
| 186 | template <typename T> |
| 187 | T &Slice<T>::back() const noexcept { |
| 188 | assert(!this->empty()); |
| 189 | return (*this)[this->size() - 1]; |
| 190 | } |
| 191 | |
| 192 | template <typename T> |
| 193 | typename Slice<T>::iterator::reference |
| 194 | Slice<T>::iterator::operator*() const noexcept { |
| 195 | return *static_cast<T *>(this->pos); |
| 196 | } |
| 197 | |
| 198 | template <typename T> |
| 199 | typename Slice<T>::iterator::pointer |
| 200 | Slice<T>::iterator::operator->() const noexcept { |
| 201 | return static_cast<T *>(this->pos); |
| 202 | } |
| 203 | |
| 204 | template <typename T> |
| 205 | typename Slice<T>::iterator::reference Slice<T>::iterator::operator[]( |
| 206 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 207 | auto ptr = static_cast<char *>(this->pos) + this->stride * n; |
| 208 | return *reinterpret_cast<T *>(ptr); |
| 209 | } |
| 210 | |
| 211 | template <typename T> |
| 212 | typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept { |
| 213 | this->pos = static_cast<char *>(this->pos) + this->stride; |
| 214 | return *this; |
| 215 | } |
| 216 | |
| 217 | template <typename T> |
| 218 | typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept { |
| 219 | auto ret = iterator(*this); |
| 220 | this->pos = static_cast<char *>(this->pos) + this->stride; |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | template <typename T> |
| 225 | typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept { |
| 226 | this->pos = static_cast<char *>(this->pos) - this->stride; |
| 227 | return *this; |
| 228 | } |
| 229 | |
| 230 | template <typename T> |
| 231 | typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept { |
| 232 | auto ret = iterator(*this); |
| 233 | this->pos = static_cast<char *>(this->pos) - this->stride; |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | template <typename T> |
| 238 | typename Slice<T>::iterator &Slice<T>::iterator::operator+=( |
| 239 | typename Slice<T>::iterator::difference_type n) noexcept { |
| 240 | this->pos = static_cast<char *>(this->pos) + this->stride * n; |
| 241 | return *this; |
| 242 | } |
| 243 | |
| 244 | template <typename T> |
| 245 | typename Slice<T>::iterator &Slice<T>::iterator::operator-=( |
| 246 | typename Slice<T>::iterator::difference_type n) noexcept { |
| 247 | this->pos = static_cast<char *>(this->pos) - this->stride * n; |
| 248 | return *this; |
| 249 | } |
| 250 | |
| 251 | template <typename T> |
| 252 | typename Slice<T>::iterator Slice<T>::iterator::operator+( |
| 253 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 254 | auto ret = iterator(*this); |
| 255 | ret.pos = static_cast<char *>(this->pos) + this->stride * n; |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | template <typename T> |
| 260 | typename Slice<T>::iterator Slice<T>::iterator::operator-( |
| 261 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 262 | auto ret = iterator(*this); |
| 263 | ret.pos = static_cast<char *>(this->pos) - this->stride * n; |
| 264 | return ret; |
| 265 | } |
| 266 | |
| 267 | template <typename T> |
| 268 | typename Slice<T>::iterator::difference_type |
| 269 | Slice<T>::iterator::operator-(const iterator &other) const noexcept { |
| 270 | auto diff = std::distance(static_cast<char *>(other.pos), |
| 271 | static_cast<char *>(this->pos)); |
| 272 | return diff / this->stride; |
| 273 | } |
| 274 | |
| 275 | template <typename T> |
| 276 | bool Slice<T>::iterator::operator==(const iterator &other) const noexcept { |
| 277 | return this->pos == other.pos; |
| 278 | } |
| 279 | |
| 280 | template <typename T> |
| 281 | bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept { |
| 282 | return this->pos != other.pos; |
| 283 | } |
| 284 | |
| 285 | template <typename T> |
| 286 | bool Slice<T>::iterator::operator<(const iterator &other) const noexcept { |
| 287 | return this->pos < other.pos; |
| 288 | } |
| 289 | |
| 290 | template <typename T> |
| 291 | bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept { |
| 292 | return this->pos <= other.pos; |
| 293 | } |
| 294 | |
| 295 | template <typename T> |
| 296 | bool Slice<T>::iterator::operator>(const iterator &other) const noexcept { |
| 297 | return this->pos > other.pos; |
| 298 | } |
| 299 | |
| 300 | template <typename T> |
| 301 | bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept { |
| 302 | return this->pos >= other.pos; |
| 303 | } |
| 304 | |
| 305 | template <typename T> |
| 306 | typename Slice<T>::iterator Slice<T>::begin() const noexcept { |
| 307 | iterator it; |
| 308 | it.pos = slicePtr(this); |
| 309 | it.stride = size_of<T>(); |
| 310 | return it; |
| 311 | } |
| 312 | |
| 313 | template <typename T> |
| 314 | typename Slice<T>::iterator Slice<T>::end() const noexcept { |
| 315 | iterator it = this->begin(); |
| 316 | it.pos = static_cast<char *>(it.pos) + it.stride * this->size(); |
| 317 | return it; |
| 318 | } |
| 319 | |
| 320 | template <typename T> |
| 321 | void Slice<T>::swap(Slice &rhs) noexcept { |
| 322 | std::swap(*this, rhs); |
| 323 | } |
| 324 | #endif // CXXBRIDGE1_RUST_SLICE |
| 325 | |
| 326 | #ifndef CXXBRIDGE1_IS_COMPLETE |
| 327 | #define CXXBRIDGE1_IS_COMPLETE |
| 328 | namespace detail { |
| 329 | namespace { |
| 330 | template <typename T, typename = std::size_t> |
| 331 | struct is_complete : std::false_type {}; |
| 332 | template <typename T> |
| 333 | struct is_complete<T, decltype(sizeof(T))> : std::true_type {}; |
| 334 | } // namespace |
| 335 | } // namespace detail |
| 336 | #endif // CXXBRIDGE1_IS_COMPLETE |
| 337 | |
| 338 | #ifndef CXXBRIDGE1_LAYOUT |
| 339 | #define CXXBRIDGE1_LAYOUT |
| 340 | class layout { |
| 341 | template <typename T> |
| 342 | friend std::size_t size_of(); |
| 343 | template <typename T> |
| 344 | friend std::size_t align_of(); |
| 345 | template <typename T> |
| 346 | static typename std::enable_if<std::is_base_of<Opaque, T>::value, |
| 347 | std::size_t>::type |
| 348 | do_size_of() { |
| 349 | return T::layout::size(); |
| 350 | } |
| 351 | template <typename T> |
| 352 | static typename std::enable_if<!std::is_base_of<Opaque, T>::value, |
| 353 | std::size_t>::type |
| 354 | do_size_of() { |
| 355 | return sizeof(T); |
| 356 | } |
| 357 | template <typename T> |
| 358 | static |
| 359 | typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type |
| 360 | size_of() { |
| 361 | return do_size_of<T>(); |
| 362 | } |
| 363 | template <typename T> |
| 364 | static typename std::enable_if<std::is_base_of<Opaque, T>::value, |
| 365 | std::size_t>::type |
| 366 | do_align_of() { |
| 367 | return T::layout::align(); |
| 368 | } |
| 369 | template <typename T> |
| 370 | static typename std::enable_if<!std::is_base_of<Opaque, T>::value, |
| 371 | std::size_t>::type |
| 372 | do_align_of() { |
| 373 | return alignof(T); |
| 374 | } |
| 375 | template <typename T> |
| 376 | static |
| 377 | typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type |
| 378 | align_of() { |
| 379 | return do_align_of<T>(); |
| 380 | } |
| 381 | }; |
| 382 | |
| 383 | template <typename T> |
| 384 | std::size_t size_of() { |
| 385 | return layout::size_of<T>(); |
| 386 | } |
| 387 | |
| 388 | template <typename T> |
| 389 | std::size_t align_of() { |
| 390 | return layout::align_of<T>(); |
| 391 | } |
| 392 | #endif // CXXBRIDGE1_LAYOUT |
| 393 | |
| 394 | namespace { |
| 395 | namespace repr { |
| 396 | using Fat = ::std::array<::std::uintptr_t, 2>; |
| 397 | } // namespace repr |
| 398 | |
| 399 | template <typename T> |
| 400 | class impl<Slice<T>> final { |
| 401 | public: |
| 402 | static repr::Fat repr(Slice<T> slice) noexcept { |
| 403 | return slice.repr; |
| 404 | } |
| 405 | }; |
| 406 | |
| 407 | template <bool> struct deleter_if { |
| 408 | template <typename T> void operator()(T *) {} |
| 409 | }; |
| 410 | |
| 411 | template <> struct deleter_if<true> { |
| 412 | template <typename T> void operator()(T *ptr) { ptr->~T(); } |
| 413 | }; |
| 414 | } // namespace |
| 415 | } // namespace cxxbridge1 |
| 416 | } // namespace rust |
| 417 | |
| 418 | using CSnapshot = ::CSnapshot; |
| 419 | using CSnapshotBuffer = ::CSnapshotBuffer; |
| 420 | |
| 421 | extern "C" { |
| 422 | ::CSnapshotBuffer *cxxbridge1$CSnapshotBuffer_New() noexcept { |
| 423 | ::std::unique_ptr<::CSnapshotBuffer> (*CSnapshotBuffer_New$)() = ::CSnapshotBuffer_New; |
| 424 | return CSnapshotBuffer_New$().release(); |
| 425 | } |
| 426 | |
| 427 | ::rust::repr::Fat cxxbridge1$CSnapshot$AsSlice(const ::CSnapshot &self) noexcept { |
| 428 | ::rust::Slice<const ::std::int32_t> (::CSnapshot::*AsSlice$)() const = &::CSnapshot::AsSlice; |
| 429 | return ::rust::impl<::rust::Slice<const ::std::int32_t>>::repr(slice: (self.*AsSlice$)()); |
| 430 | } |
| 431 | |
| 432 | ::rust::repr::Fat cxxbridge1$CSnapshotBuffer$AsMutSlice(::CSnapshotBuffer &self) noexcept { |
| 433 | ::rust::Slice<::std::int32_t> (::CSnapshotBuffer::*AsMutSlice$)() = &::CSnapshotBuffer::AsMutSlice; |
| 434 | return ::rust::impl<::rust::Slice<::std::int32_t>>::repr(slice: (self.*AsMutSlice$)()); |
| 435 | } |
| 436 | |
| 437 | ::std::int32_t cxxbridge1$Obj_SixToSeven(::std::int32_t type_) noexcept { |
| 438 | ::std::int32_t (*Obj_SixToSeven$)(::std::int32_t) = ::Obj_SixToSeven; |
| 439 | return Obj_SixToSeven$(type_); |
| 440 | } |
| 441 | |
| 442 | static_assert(::rust::detail::is_complete<::CSnapshotBuffer>::value, "definition of CSnapshotBuffer is required" ); |
| 443 | static_assert(sizeof(::std::unique_ptr<::CSnapshotBuffer>) == sizeof(void *), "" ); |
| 444 | static_assert(alignof(::std::unique_ptr<::CSnapshotBuffer>) == alignof(void *), "" ); |
| 445 | void cxxbridge1$unique_ptr$CSnapshotBuffer$null(::std::unique_ptr<::CSnapshotBuffer> *ptr) noexcept { |
| 446 | ::new (ptr) ::std::unique_ptr<::CSnapshotBuffer>(); |
| 447 | } |
| 448 | void cxxbridge1$unique_ptr$CSnapshotBuffer$raw(::std::unique_ptr<::CSnapshotBuffer> *ptr, ::CSnapshotBuffer *raw) noexcept { |
| 449 | ::new (ptr) ::std::unique_ptr<::CSnapshotBuffer>(raw); |
| 450 | } |
| 451 | const ::CSnapshotBuffer *cxxbridge1$unique_ptr$CSnapshotBuffer$get(const ::std::unique_ptr<::CSnapshotBuffer>& ptr) noexcept { |
| 452 | return ptr.get(); |
| 453 | } |
| 454 | ::CSnapshotBuffer *cxxbridge1$unique_ptr$CSnapshotBuffer$release(::std::unique_ptr<::CSnapshotBuffer>& ptr) noexcept { |
| 455 | return ptr.release(); |
| 456 | } |
| 457 | void cxxbridge1$unique_ptr$CSnapshotBuffer$drop(::std::unique_ptr<::CSnapshotBuffer> *ptr) noexcept { |
| 458 | ::rust::deleter_if<::rust::detail::is_complete<::CSnapshotBuffer>::value>{}(ptr); |
| 459 | } |
| 460 | } // extern "C" |
| 461 | |