本文整理汇总了C++中NativeHandle类的典型用法代码示例。如果您正苦于以下问题:C++ NativeHandle类的具体用法?C++ NativeHandle怎么用?C++ NativeHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NativeHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSemaphoreNative
void getSemaphoreNative (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkSemaphore semaphore,
vk::VkExternalSemaphoreHandleTypeFlagBitsKHR externalType,
NativeHandle& nativeHandle)
{
if (externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
|| externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR)
{
const vk::VkSemaphoreGetFdInfoKHR info =
{
vk::VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR,
DE_NULL,
semaphore,
externalType
};
int fd = -1;
VK_CHECK(vkd.getSemaphoreFdKHR(device, &info, &fd));
TCU_CHECK(fd >= 0);
nativeHandle = fd;
}
else if (externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
|| externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR)
{
const vk::VkSemaphoreGetWin32HandleInfoKHR info =
{
vk::VK_STRUCTURE_TYPE_SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR,
DE_NULL,
semaphore,
externalType
};
vk::pt::Win32Handle handle (DE_NULL);
VK_CHECK(vkd.getSemaphoreWin32HandleKHR(device, &info, &handle));
switch (externalType)
{
case vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR:
nativeHandle.setWin32Handle(NativeHandle::WIN32HANDLETYPE_NT, handle);
break;
case vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR:
nativeHandle.setWin32Handle(NativeHandle::WIN32HANDLETYPE_KMT, handle);
break;
default:
DE_FATAL("Unknow external memory handle type");
}
}
else
DE_FATAL("Unknow external semaphore handle type");
}
示例2: importSemaphore
void importSemaphore (const vk::DeviceInterface& vkd,
const vk::VkDevice device,
const vk::VkSemaphore semaphore,
vk::VkExternalSemaphoreHandleTypeFlagBitsKHR externalType,
NativeHandle& handle,
vk::VkSemaphoreImportFlagsKHR flags)
{
if (externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
|| externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR)
{
const vk::VkImportSemaphoreFdInfoKHR importInfo =
{
vk::VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
DE_NULL,
semaphore,
flags,
externalType,
handle.getFd()
};
VK_CHECK(vkd.importSemaphoreFdKHR(device, &importInfo));
handle.disown();
}
else if (externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
|| externalType == vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR)
{
const vk::VkImportSemaphoreWin32HandleInfoKHR importInfo =
{
vk::VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
DE_NULL,
semaphore,
flags,
externalType,
handle.getWin32Handle(),
DE_NULL
};
VK_CHECK(vkd.importSemaphoreWin32HandleKHR(device, &importInfo));
// \note File descriptors and win32 handles behave differently, but this call wil make it seem like they would behave in same way
handle.reset();
}
else
DE_FATAL("Unknown semaphore external handle type");
}
示例3: LoadGameConfigFile
// native GameConfig:LoadGameConfigFile(const file[]);
static cell AMX_NATIVE_CALL LoadGameConfigFile(AMX *amx, cell *params)
{
int length;
const char *filename = get_amxstring(amx, params[1], 0, length);
IGameConfig *config = nullptr;
char error[128];
if (!ConfigManager.LoadGameConfigFile(filename, &config, error, sizeof(error)))
{
LogError(amx, AMX_ERR_NATIVE, "Unable to open %s: %s", filename, error);
return 0;
}
int handle = GameConfigHandle.create();
auto configHandle = GameConfigHandle.lookup(handle);
if (!configHandle)
{
return 0;
}
configHandle->m_config = config;
return handle;
}
示例4: ArrayClone
// native Array:ArrayClone(Array:which);
static cell AMX_NATIVE_CALL ArrayClone(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
return ArrayHandles.clone(vec->clone());
}
示例5: handle
// native bool:INI_ParseFile(INIParser:handle, const file[], &line = 0, &col = 0, any:data = 0);
static cell AMX_NATIVE_CALL INI_ParseFile(AMX *amx, cell *params)
{
ParseInfo *p = TextParsersHandles.lookup(params[1]);
if (!p)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid INI parse handle (%d)", params[1]);
return 0;
}
int length;
const char *file = build_pathname("%s", get_amxstring(amx, params[2], 0, length));
if (*params / sizeof(cell) >= 5)
{
p->data = params[5];
}
unsigned int line, col;
bool result = textparsers->ParseFile_INI(file, p, &line, &col);
*get_amxaddr(amx, params[3]) = line;
*get_amxaddr(amx, params[4]) = col;
return result;
}
示例6: TrieSetString
// native TrieSetString(Trie:handle, const key[], const data[], bool:replace = true);
static cell AMX_NATIVE_CALL TrieSetString(AMX *amx, cell *params)
{
CellTrie *t = TrieHandles.lookup(params[1]);
if (!t)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid map handle provided (%d)", params[1]);
return 0;
}
int len;
const char *key = get_amxstring(amx, params[2], 0, len);
const char *value = get_amxstring(amx, params[3], 1, len);
StringHashMap<Entry>::Insert i = t->map.findForAdd(key);
if (!i.found())
{
if (!t->map.add(i, key))
{
return 0;
}
i->value.setString(value);
return 1;
}
// Old plugin doesn't have 'replace' parameter.
if (*params / sizeof(cell) == 4 && !params[4])
{
return 0;
}
i->value.setString(value);
return 1;
}
示例7: TrieGetCell
// native bool:TrieGetCell(Trie:handle, const key[], &any:value);
static cell AMX_NATIVE_CALL TrieGetCell(AMX *amx, cell *params)
{
CellTrie *t = TrieHandles.lookup(params[1]);
if (!t)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid map handle provided (%d)", params[1]);
return 0;
}
int len;
const char *key = get_amxstring(amx, params[2], 0, len);
StringHashMap<Entry>::Result r = t->map.find(key);
if (!r.found())
{
return 0;
}
cell *ptr = get_amxaddr(amx, params[3]);
if (r->value.isCell())
{
*ptr = r->value.cell_();
return 1;
}
return 0;
}
示例8: ArrayGetStringHandle
// native DoNotUse : ArrayGetStringHandle(Array : which, item);
static cell AMX_NATIVE_CALL ArrayGetStringHandle(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
size_t idx = (size_t)params[2];
if (idx >= vec->size())
{
LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
return 0;
}
cell* ptr = vec->at(idx);
if (ptr == NULL)
{
return 0;
}
return reinterpret_cast<cell>(ptr);
}
示例9: ArraySwap
// native ArraySwap(Array:which, item1, item2);
static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
size_t idx1 = (size_t)params[2];
size_t idx2 = (size_t)params[3];
if (idx1 >= vec->size())
{
LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx1, vec->size());
return 0;
}
if (idx2 >= vec->size())
{
LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx2, vec->size());
return 0;
}
vec->swap(idx1, idx2);
return 1;
}
示例10: strncopy
// native ArraySetString(Array:which, item, const input[]);
static cell AMX_NATIVE_CALL ArraySetString(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
size_t idx = (size_t)params[2];
if (idx >= vec->size())
{
LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
return 0;
}
cell *blk = vec->at(idx);
int len;
char *str = get_amxstring(amx, params[3], 0, len);
return strncopy(blk, str, ke::Min((size_t)len + 1, vec->blocksize()));
}
示例11: ArrayPushArray
// native ArrayPushArray(Array:which, const any:input[], size = -1);
static cell AMX_NATIVE_CALL ArrayPushArray(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
cell *blk = vec->push();
if (!blk)
{
LogError(amx, AMX_ERR_NATIVE, "Failed to grow array");
return 0;
}
cell *addr = get_amxaddr(amx, params[2]);
size_t indexes = vec->blocksize();
if (*params / sizeof(cell) == 3)
{
if (params[3] != -1 && (size_t)params[3] <= vec->blocksize())
{
indexes = params[3];
}
}
memcpy(blk, addr, sizeof(cell) * indexes);
return static_cast<cell>((vec->size() - 1));
}
示例12: ArraySetArray
// native ArraySetArray(Array:which, item, const any:input[], size =-1);
static cell AMX_NATIVE_CALL ArraySetArray(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return 0;
}
size_t idx = (size_t)params[2];
if (idx >= vec->size())
{
LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
return 0;
}
cell *blk = vec->at(idx);
size_t indexes = vec->blocksize();
if (*params / sizeof(cell) == 4)
{
if (params[4] != -1 && (size_t)params[4] <= vec->blocksize())
{
indexes = params[4];
}
}
cell *addr = get_amxaddr(amx, params[3]);
memcpy(blk, addr, sizeof(cell) * indexes);
return indexes;
}
示例13: TrieGetString
// native bool:TrieGetString(Trie:handle, const key[], buff[], len, &size = 0);
static cell AMX_NATIVE_CALL TrieGetString(AMX *amx, cell *params)
{
CellTrie *t = TrieHandles.lookup(params[1]);
if (!t)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid map handle provided (%d)", params[1]);
return 0;
}
if (params[4] < 0)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid buffer size (%d)", params[4]);
return 0;
}
int len;
const char *key = get_amxstring(amx, params[2], 0, len);
cell *pSize = get_amxaddr(amx, params[5]);
StringHashMap<Entry>::Result r = t->map.find(key);
if (!r.found() || !r->value.isString())
{
return 0;
}
*pSize = (cell)set_amxstring_utf8(amx, params[3], r->value.chars(), strlen(r->value.chars()), params[4]);
return 1;
}
示例14: handle
// native SMC_SetParseEnd(SMCParser:handle, const func[]);
static cell AMX_NATIVE_CALL SMC_SetParseEnd(AMX *amx, cell *params)
{
ParseInfo *p = TextParsersHandles.lookup(params[1]);
if (!p)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid SMC parse handle (%d)", params[1]);
return 0;
}
int length = 0;
const char *funcName = nullptr;
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
{
p->parse_end = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
}
if (p->parse_end == -1)
{
LogError(amx, AMX_ERR_NATIVE, "Function is not present (function \"%s\") (plugin \"%s\")", funcName, g_plugins.findPluginFast(amx)->getName());
return 0;
}
return 1;
}
示例15: ArrayFindString
// native ArrayFindString(Array:which, const item[]);
static cell AMX_NATIVE_CALL ArrayFindString(AMX* amx, cell* params)
{
CellArray* vec = ArrayHandles.lookup(params[1]);
if (!vec)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
return -1;
}
cell *b, *a = get_amxaddr(amx, params[2]);
size_t cellcount = vec->blocksize();
size_t a_len = ke::Max(1, amxstring_len(a));
size_t len = a_len > cellcount ? cellcount : a_len;
for (size_t i = 0; i < vec->size(); i++)
{
b = vec->at(i);
if (fastcellcmp(a, b, len))
{
return static_cast<cell>(i);
}
}
return -1;
}