| 407 | }; |
| 408 | |
| 409 | class RefPtr { |
| 410 | std::shared_ptr<void*> m_ref; |
| 411 | size_t m_offset; |
| 412 | bool m_mutable; |
| 413 | |
| 414 | public: |
| 415 | RefPtr() { |
| 416 | m_ref = std::make_shared<void*>((void*)nullptr); |
| 417 | m_offset = 0; |
| 418 | m_mutable = true; |
| 419 | } |
| 420 | |
| 421 | RefPtr(void* ref_ptr, const size_t offset = 0) { |
| 422 | m_ref = std::make_shared<void*>(ref_ptr); |
| 423 | m_offset = offset; |
| 424 | m_mutable = true; |
| 425 | } |
| 426 | |
| 427 | explicit RefPtr( |
| 428 | std::shared_ptr<void*> ref_ptr, const size_t offset = 0, |
| 429 | bool is_mutable = true) { |
| 430 | m_ref = ref_ptr; |
| 431 | m_offset = offset; |
| 432 | m_mutable = is_mutable; |
| 433 | } |
| 434 | |
| 435 | void* get_ptr() const { |
| 436 | return static_cast<void*>( |
| 437 | (*m_ref != NULL) ? static_cast<dt_byte*>(*m_ref) + m_offset : nullptr); |
| 438 | } |
| 439 | |
| 440 | bool is_mutable() const { return m_mutable; } |
| 441 | |
| 442 | void reset(const void* ptr, size_t offset = 0); |
| 443 | |
| 444 | RefPtr& operator+=(size_t offset) { |
| 445 | m_offset += offset; |
| 446 | return *this; |
| 447 | } |
| 448 | |
| 449 | bool operator==(const RefPtr& other) const { |
| 450 | return *m_ref == *other.m_ref && m_offset == other.m_offset; |
| 451 | } |
| 452 | |
| 453 | template <typename T> |
| 454 | T* ptr() const { |
| 455 | return static_cast<T*>(get_ptr()); |
| 456 | } |
| 457 | }; |
| 458 | |
| 459 | /** |
| 460 | * \brief A simple encapsulation class for n-dimensional tensor. |
no outgoing calls
no test coverage detected