日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Key_handle的学习

發布時間:2023/12/13 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Key_handle的学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼

一切盡在不言中

#pragma once#include "common/common.h" #include "sdf/sdf.h"#include <memory>namespace sdf {namespace algorithm {class KeyHandle {public:using erased_internal_data_t = char; //使用erased_internal_data_t等效于char,此處用法相當于typedefKeyHandle() = default;//構造函數,使用默認參數virtual ~KeyHandle() = default;//析構函數,使用默認參數KeyHandle(const KeyHandle &) = delete;//賦值構造函數//參考鏈接 https://blog.csdn.net/TanJiaLiang_/article/details/86691437?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.compare&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.compareKeyHandle &operator=(const KeyHandle &) = delete;//復制賦值//https://zh.cppreference.com/w/cpp/language/operators/*** @brief construct an empty key handle //摘要** @tparam T internal type //參數* @return unique_ptr to KeyHandle which contains empty internal data*/template <typename T> static std::unique_ptr<KeyHandle> make() {//template <typename T> 模板類//static std::unique_ptr https://mp.csdn.net/console/editor/html/109365196auto key_handle = std::make_unique<KeyHandle>();//std::make_unique https://zh.cppreference.com/w/cpp/memory/unique_ptr/make_unique// erase internal typekey_handle->data.reset(reinterpret_cast<char *>(new T()),internal_data_deleter<T>);//reinterpret_cast https://blog.csdn.net/iflyme/article/details/83378697//data.reset data屬于std::shared_ptr<erased_internal_data_t>類型 https://zh.cppreference.com/w/cpp/memory/shared_ptr/resetkey_handle->data_length = sizeof(T);return key_handle;}/*** @brief cast to internal type for accessing raw key data** @tparam T internal type* @return pointer to internal data*/template <typename T> T *cast() { return reinterpret_cast<T *>(data.get()); }/*** @brief cast to internal type for accessing raw key data** @tparam T internal type* @return const pointer to internal data*/template <typename T> const T *cast() const {return reinterpret_cast<const T *>(data.get());}/*** @brief convert to native handle representation for public c style apis** @return sdf_handle_t type pointer to this*/sdf_handle_t native_handle() const {return reinterpret_cast<sdf_handle_t>(const_cast<KeyHandle *>(this));}/*** @brief convert to native 64-bits representation for grpc conversions** @return uint64_t type number equals to address of this*/uint64_t native_handle_64ull() const {return reinterpret_cast<uint64_t>(this);}/*** @brief access key handle via native handle** @param native_handle public c style handle* @return pointer to KeyHandle*/static KeyHandle *from_native_handle(sdf_handle_t native_handle) {return reinterpret_cast<KeyHandle *>(native_handle);}/*** @brief access key handle via native 64-bits representation** @param native_handle_64ull native 64-bits representation* @return pointer to KeyHandle*/static KeyHandle *from_native_handle_64ull(uint64_t native_handle_64ull) {return reinterpret_cast<KeyHandle *>(native_handle_64ull);}private:template <typename T>static void internal_data_deleter(const erased_internal_data_t *ptr) {delete reinterpret_cast<const T *>(ptr);}protected:std::shared_ptr<erased_internal_data_t> data; ///< internal datasize_t data_length = 0; ///< length of internal data};} // namespace algorithm } // namespace sdf

?

總結

以上是生活随笔為你收集整理的Key_handle的学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。