1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: Handle.h 4 5 Copyright (C)2009-2012 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: 47231 $ 14 *---------------------------------------------------------------------------*/ 15 16 17 #ifndef NN_HANDLE_H_ 18 #define NN_HANDLE_H_ 19 20 #include <nn/types.h> 21 #include <nn/Result.h> 22 23 24 //------------------------------------------------------------------- 25 // for C / C++ 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif // ifdef __cplusplus 30 31 typedef struct nnHandle 32 { 33 bit32 value; 34 } 35 nnHandle; 36 37 extern const nnHandle NN_INVALID_HANDLE_VALUE; 38 39 #ifdef __cplusplus 40 } 41 #endif // ifdef __cplusplus 42 43 44 45 //------------------------------------------------------------------- 46 // for C++ 47 48 #ifdef __cplusplus 49 50 namespace nn 51 { 52 53 class Handle 54 { 55 public: Handle()56 Handle() : m_Handle(0) 57 { 58 } 59 Handle(nnHandle handle)60 Handle(nnHandle handle) : m_Handle(handle.value) 61 { 62 } 63 Handle(bit32 handle)64 explicit Handle(bit32 handle) 65 { 66 m_Handle = handle; 67 } 68 IsValid()69 bool IsValid() const 70 { 71 return m_Handle != 0; 72 } 73 74 #if ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT) || ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK) GetPrintableBits()75 bit32 GetPrintableBits() const 76 { 77 return m_Handle; 78 } 79 #endif 80 81 bool operator ==(const Handle& rhs) const { return this->m_Handle == rhs.m_Handle; } 82 bool operator !=(const Handle& rhs) const { return this->m_Handle != rhs.m_Handle; } nnHandle()83 operator nnHandle() const { nnHandle handle = {this->m_Handle}; return handle; } 84 85 private: 86 bit32 m_Handle; 87 }; 88 89 namespace 90 { 91 const nnHandle PSEUDO_HANDLE_CURRENT_THREAD = {0xFFFF8000}; 92 const nnHandle PSEUDO_HANDLE_CURRENT_PROCESS = {0xFFFF8001}; 93 const nnHandle INVALID_HANDLE_VALUE = {0}; 94 } 95 96 } 97 #endif // ifdef __cplusplus 98 99 100 101 #endif /* NN_HANDLE_H_ */ 102