1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: Handle.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 13429 $ 14 *---------------------------------------------------------------------------*/ 15 16 /*! 17 @file 18 @brief Handle クラスの宣言 19 :include nn/Handle.h 20 */ 21 22 #ifndef NN_HANDLE_H_ 23 #define NN_HANDLE_H_ 24 25 #include <nn/types.h> 26 #include <nn/Result.h> 27 28 29 //------------------------------------------------------------------- 30 // for C / C++ 31 32 /*! 33 @addtogroup nn_root nn 34 35 @{ 36 */ 37 38 /*! 39 @defgroup nn_Handle_c Handle (C) 40 41 @brief nn::HandleのC インタフェースモジュールです。 42 43 @{ 44 */ 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif // ifdef __cplusplus 49 50 /*! 51 @brief オブジェクトのハンドルを示す構造体です。C の API で使用します。 52 */ 53 typedef struct nnHandle 54 { 55 bit32 value; 56 } 57 nnHandle; 58 59 extern const nnHandle NN_INVALID_HANDLE_VALUE; 60 61 #ifdef __cplusplus 62 } 63 #endif // ifdef __cplusplus 64 65 /*! 66 @} 67 */ 68 /*! 69 @} 70 */ 71 72 73 //------------------------------------------------------------------- 74 // for C++ 75 76 #ifdef __cplusplus 77 78 namespace nn { 79 /*! 80 @brief オブジェクトのハンドルを示すクラスです。 81 */ 82 class Handle{ 83 public: Handle()84 Handle() : m_Handle(0) 85 { 86 } 87 Handle(nnHandle handle)88 Handle(nnHandle handle) : m_Handle(handle.value) 89 { 90 } 91 Handle(bit32 handle)92 explicit Handle(bit32 handle) 93 { 94 m_Handle = handle; 95 } 96 97 /*! 98 @brief ハンドルが有効かどうかを調べます。 99 100 @return ハンドルの値が有効なら true を、無効なら false を返します。 101 */ IsValid()102 bool IsValid() const 103 { 104 return m_Handle != 0; 105 } 106 107 /*! 108 @brief ハンドルの値を取得します。デバッグ用です。 109 110 @return ハンドルの値。 111 */ 112 #if ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT) || ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK) GetPrintableBits()113 bit32 GetPrintableBits() const 114 { 115 return m_Handle; 116 } 117 #endif 118 119 bool operator ==(const Handle& rhs) const { return this->m_Handle == rhs.m_Handle; } 120 bool operator !=(const Handle& rhs) const { return this->m_Handle != rhs.m_Handle; } nnHandle()121 operator nnHandle() const { nnHandle handle = {this->m_Handle}; return handle; } 122 123 private: 124 bit32 m_Handle; 125 }; 126 127 namespace 128 { 129 const nnHandle PSEUDO_HANDLE_CURRENT_THREAD = {0xFFFF8000}; //!< カレントスレッドを示す擬似ハンドル 130 const nnHandle PSEUDO_HANDLE_CURRENT_PROCESS = {0xFFFF8001}; //!< カレントプロセスを示す擬似ハンドル 131 const nnHandle INVALID_HANDLE_VALUE = {0}; 132 } 133 134 } 135 #endif // ifdef __cplusplus 136 137 138 139 #endif /* NN_HANDLE_H_ */ 140