unordered_map heterogeneous access
This commit is contained in:
@@ -304,7 +304,7 @@ void scenes::stream::tracking()
|
|||||||
device_id::RIGHT_GRIP,
|
device_id::RIGHT_GRIP,
|
||||||
device_id::RIGHT_PALM,
|
device_id::RIGHT_PALM,
|
||||||
};
|
};
|
||||||
if (instance.has_extension("XR_EXT_hand_interaction"))
|
if (instance.has_extension(XR_EXT_HAND_INTERACTION_EXTENSION_NAME))
|
||||||
{
|
{
|
||||||
spdlog::info("Adding hand_interaction poses to device list");
|
spdlog::info("Adding hand_interaction poses to device list");
|
||||||
ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE});
|
ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE});
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "utils/handle.h"
|
#include "utils/handle.h"
|
||||||
|
#include "utils/strings.h"
|
||||||
#include "xr/check.h"
|
#include "xr/check.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -49,7 +50,7 @@ class instance : public utils::handle<XrInstance, xrDestroyInstance>
|
|||||||
{
|
{
|
||||||
std::string runtime_version;
|
std::string runtime_version;
|
||||||
std::string runtime_name;
|
std::string runtime_name;
|
||||||
std::unordered_map<std::string, uint32_t> loaded_extensions;
|
std::unordered_map<std::string, uint32_t, utils::string_hash, std::equal_to<>> loaded_extensions;
|
||||||
XrVersion api_version;
|
XrVersion api_version;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -99,12 +100,12 @@ public:
|
|||||||
|
|
||||||
static std::vector<XrExtensionProperties> extensions(const char * layer_name = nullptr);
|
static std::vector<XrExtensionProperties> extensions(const char * layer_name = nullptr);
|
||||||
|
|
||||||
bool has_extension(const std::string & extension_name)
|
bool has_extension(const char * extension_name)
|
||||||
{
|
{
|
||||||
return loaded_extensions.find(extension_name) != loaded_extensions.end();
|
return loaded_extensions.find(extension_name) != loaded_extensions.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t extension_version(const std::string & extension_name)
|
uint32_t extension_version(const char * extension_name)
|
||||||
{
|
{
|
||||||
auto it = loaded_extensions.find(extension_name);
|
auto it = loaded_extensions.find(extension_name);
|
||||||
if (it != loaded_extensions.end())
|
if (it != loaded_extensions.end())
|
||||||
|
|||||||
@@ -20,9 +20,29 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
||||||
|
|
||||||
|
// https://www.cppstories.com/2021/heterogeneous-access-cpp20/
|
||||||
|
struct string_hash
|
||||||
|
{
|
||||||
|
using is_transparent = void;
|
||||||
|
[[nodiscard]] size_t operator()(const char * txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string_view>{}(txt);
|
||||||
|
}
|
||||||
|
[[nodiscard]] size_t operator()(std::string_view txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string_view>{}(txt);
|
||||||
|
}
|
||||||
|
[[nodiscard]] size_t operator()(const std::string & txt) const
|
||||||
|
{
|
||||||
|
return std::hash<std::string>{}(txt);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|||||||
Reference in New Issue
Block a user