QExplicitlySharedDataPointer Class

template <typename T> class QExplicitlySharedDataPointer

QExplicitlySharedDataPointer 클래스는 명시적으로 공유된 객체에 대한 포인터를 나타냅니다. 더 보기...

Header: #include <QExplicitlySharedDataPointer>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

참고: 이 클래스의 모든 함수는 재인용됩니다.

공용 유형

공용 함수

QExplicitlySharedDataPointer()
QExplicitlySharedDataPointer(T *data)
QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o)
QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o)
QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o)
~QExplicitlySharedDataPointer()
const T *constData() const
T *data() const
void detach()
(since 6.0) T *get() const
(since 6.0) void reset(T *ptr = nullptr)
void swap(QExplicitlySharedDataPointer<T> &other)
T *take()
bool operator bool() const
bool operator!() const
T &operator*() const
T *operator->()
T *operator->() const
QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other)
QExplicitlySharedDataPointer<T> &operator=(T *o)
QExplicitlySharedDataPointer<T> &operator=(const QExplicitlySharedDataPointer<T> &o)

보호된 함수

T *clone()
bool operator!=(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)
bool operator!=(const T *ptr, const QExplicitlySharedDataPointer<T> &rhs)
bool operator==(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)
bool operator==(const T *ptr, const QExplicitlySharedDataPointer<T> &rhs)

상세 설명

QExplicitlySharedDataPointer<T>는 자신만의 명시적으로 공유되는 클래스를 쉽게 작성할 수 있게 해줍니다. QExplicitlySharedDataPointer는 스레드 안전 참조 계수를 구현하여 재진입 클래스에 QExplicitlySharedDataPointers를 추가해도 재진입이 되지 않도록 보장합니다.

한 가지 큰 차이점을 제외하면, QExplicitlySharedDataPointer는 QSharedDataPointer 와 같습니다. 가장 큰 차이점은 QExplicitlySharedDataPointer의 멤버 함수는 공유 데이터 객체를 수정하기 전에 QSharedDataPointer 의 비-const 멤버가 수행하는 쓰기 시 자동 복사 작업(detach())을 수행하지 않는다는 것입니다. detach () 함수를 사용할 수 있지만 detach() 함수를 사용하려면 직접 호출해야 합니다. 즉, 참조 카운트를 수행하고 참조 카운트가 0이 될 때까지 공유 데이터 객체를 삭제하지 않음으로써 매달린 포인터 문제를 피한다는 점을 제외하면 QExplicitlySharedDataPointers는 일반 C++ 포인터처럼 동작합니다.

예제를 통해 QExplicitlySharedDataPointer와 QSharedDataPointer 을 비교하는 것이 도움이 됩니다. Implicit vs Explicit Sharing 에서 설명한 대로 명시적 공유를 사용하도록 수정된 QSharedDataPointerEmployee example 을 고려하십시오.

이 클래스를 사용하지만 detach()를 많이 호출하는 경우 QSharedDataPointer 을 사용해야 할 수도 있습니다.

멤버 함수 문서에서 d 포인터는 항상 공유 데이터 객체에 대한 내부 포인터를 가리킵니다.

QSharedDataQSharedDataPointer참조하세요 .

멤버 유형 문서

QExplicitlySharedDataPointer::Type

공유 데이터 객체의 유형입니다. d 포인터는 이 유형의 객체를 가리킵니다.

멤버 함수 문서

[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer()

nullptrd 포인터로 초기화한 QExplicitlySharedDataPointer를 구축합니다.

[explicit noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(T *data)

d 포인터가 data 로 설정된 QExplicitlySharedDataPointer를 생성하고 data 의 참조 수를 증가시킵니다.

[noexcept] template <typename X> QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o)

이 복사 생성자는 o 가 명시적으로 공유되는 데이터 포인터의 다른 유형이지만 호환되는 공유 데이터 객체를 가진 포인터가 될 수 있다는 점에서 다릅니다.

기본적으로 od 포인터 ( X * 유형)는 암시적으로 T * 유형으로 변환되며, 이 변환의 결과는 이것의 d 포인터로 설정되고 공유 데이터 객체의 참조 횟수가 증가합니다.

그러나 QExplicitlySharedDataPointer 헤더를 포함하기 전에 QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST 매크로가 정의된 경우 od 포인터는 static_cast 를 거쳐 T * 유형으로 변환됩니다. 그러면 형변환의 결과가 이것의 d 포인터로 설정되고 공유 데이터 객체의 참조 횟수가 증가합니다.

경고: 이러한 static_cast 에 의존하는 것은 이와 같은 코드가 컴파일될 수 있으므로 잠재적으로 위험할 수 있습니다:

    QExplicitlySharedDataPointer<Base> base(new Base);
    QExplicitlySharedDataPointer<Derived> derived(base); // !!! DANGER !!!

Qt 5.4부터는 기본적으로 형변환이 비활성화되어 있습니다. QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST 매크로를 정의하여 다시 활성화할 수 있으므로 (이 기능에 의존하는) 이전 코드가 수정 없이 컴파일되도록 허용할 수 있습니다.

참고: QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST 매크로의 사용은 더 이상 사용되지 않습니다. 이 매크로는 향후 버전의 Qt에서 제거될 예정입니다.

[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o)

이 표준 복사 생성자는 이것의 d 포인터를 od 포인터로 설정하고 공유 데이터 객체의 참조 수를 증가시킵니다.

[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o)

Move는 QExplicitlySharedDataPointer 인스턴스를 생성하여 o 가 가리키던 것과 동일한 객체를 가리키도록 합니다.

QExplicitlySharedDataPointer::~QExplicitlySharedDataPointer()

공유 데이터 객체의 참조 개수를 감소시킵니다. 참조 카운트가 0이 되면 공유 데이터 개체가 삭제됩니다. 그러면 공유 데이터 개체가 소멸됩니다.

[protected] T *QExplicitlySharedDataPointer::clone()

현재 데이터의 심층 복사본을 생성하고 반환합니다. 이 함수는 참조 카운트가 1보다 클 때 detach()에 의해 호출되어 새 복사본을 만듭니다. 이 함수는 new 연산자를 사용하고 T 유형의 복사본 생성자를 호출합니다.

사용 방법에 대한 설명은 QSharedDataPointer<T>::clone()을 참조하세요.

[noexcept] const T *QExplicitlySharedDataPointer::constData() const

공유 데이터 객체에 대한 상수 포인터를 반환합니다.

data()도 참조하세요 .

[noexcept] T *QExplicitlySharedDataPointer::data() const

공유 데이터 객체에 대한 포인터를 반환합니다.

void QExplicitlySharedDataPointer::detach()

공유 데이터 객체의 참조 수가 1보다 크면 이 함수는 공유 데이터 객체의 딥 복사본을 생성하고 복사본의 d 포인터를 복사본으로 설정합니다.

QExplicitlySharedDataPointerQSharedDataPointer 의 멤버가 수행하는 쓰기 작업 자동 복사를 수행하지 않으므로 이 클래스의 멤버 함수 어디에서도 detach()가 자동으로 호출되지 않습니다. 코드의 모든 곳에서 detach()를 호출하는 경우 QSharedDataPointer 대신 를 사용하는 것이 좋습니다.

[noexcept, since 6.0] T *QExplicitlySharedDataPointer::get() const

data()와 동일합니다. 이 함수는 STL 호환성을 위해 제공됩니다.

이 함수는 Qt 6.0에 도입되었습니다.

[noexcept, since 6.0] void QExplicitlySharedDataPointer::reset(T *ptr = nullptr)

포인터를 ptr 로 설정하고 ptrnullptr 이 아닌 경우 ptr 의 참조 카운트를 증가시킵니다. 이전 공유 데이터 객체의 참조 카운트가 감소하고 참조 카운트가 0에 도달하면 객체가 삭제됩니다.

이 함수는 Qt 6.0에 도입되었습니다.

[noexcept] void QExplicitlySharedDataPointer::swap(QExplicitlySharedDataPointer<T> &other)

이 명시적으로 공유된 데이터 포인터를 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.

[noexcept] T *QExplicitlySharedDataPointer::take()

공유 객체에 대한 포인터를 반환하고 이를 nullptr 으로 재설정합니다(즉, 이 함수는 함수의 d 포인터를 nullptr 으로 설정합니다).

참고: 반환된 객체의 참조 카운트는 감소하지 않습니다. 이 함수는 QAdoptSharedDataTag 태그 객체를 받는 생성자와 함께 사용하여 원자 연산 개입 없이 공유 데이터 객체를 전송할 수 있습니다.

[noexcept] bool QExplicitlySharedDataPointer::operator bool() const

이것의 d 포인터가 널이 아닌 경우 true 을 반환합니다.

[noexcept] bool QExplicitlySharedDataPointer::operator!() const

포인터가 nullptr 인 경우 true 을 반환합니다.

T &QExplicitlySharedDataPointer::operator*() const

공유 데이터 개체의 멤버에 대한 액세스를 제공합니다.

[noexcept] T *QExplicitlySharedDataPointer::operator->()

공유 데이터 개체의 멤버에 대한 액세스를 제공합니다.

[noexcept] T *QExplicitlySharedDataPointer::operator->() const

공유 데이터 객체의 멤버에 대한 const 액세스를 제공합니다.

[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(QExplicitlySharedDataPointer<T> &&other)

이동-이 other 인스턴스를 QExplicitlySharedDataPointer 인스턴스에 할당합니다.

[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(T *o)

이것의 d 포인터를 o 로 설정하고 o 의 참조 카운트를 증가시킵니다. 이것의 이전 공유 데이터 객체의 참조 카운트는 감소합니다. 이전 공유 데이터 객체의 참조 카운트가 0이 되면 이전 공유 데이터 객체가 삭제됩니다.

[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(const QExplicitlySharedDataPointer<T> &o)

이것의 d 포인터를 od 포인터로 설정하고 공유 데이터 객체의 참조 횟수를 증가시킵니다. 이것의 이전 공유 데이터 객체의 참조 카운트는 감소합니다. 이전 공유 데이터 객체의 참조 카운트가 0이 되면 이전 공유 데이터 객체가 삭제됩니다.

관련 비회원

[noexcept] bool operator!=(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)

lhsrhs 에 동일한 d 포인터가 없는 경우 true 를 반환합니다.

[noexcept] bool operator!=(const T *ptr, const QExplicitlySharedDataPointer<T> &rhs)

rhsd 포인터가 ptr아닌 경우 true 를 반환합니다.

[noexcept] bool operator==(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)

lhsrhs 에 동일한 d 포인터가 있는 경우 true 를 반환합니다.

[noexcept] bool operator==(const T *ptr, const QExplicitlySharedDataPointer<T> &rhs)

rhsd 포인터가 ptr 인 경우 true 를 반환합니다.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.