feat: initial DX12 foundation framework
This commit is contained in:
86
Engine/Utilities/Utilities.h
Normal file
86
Engine/Utilities/Utilities.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file Utilities.h
|
||||
* @brief 公共容器与工具模块聚合入口。
|
||||
* @details
|
||||
* 通过编译开关统一切换 STL 与自定义容器实现,并集中导出:
|
||||
* - vector/deque 等基础容器别名;
|
||||
* - erase_unordered 辅助函数;
|
||||
* - FreeList 等常用数据结构头文件。
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
||||
/**
|
||||
* @brief 是否使用 STL vector 作为基础容器。
|
||||
*/
|
||||
#define USE_STL_VECTOR 0
|
||||
/**
|
||||
* @brief 是否启用 STL deque 别名。
|
||||
*/
|
||||
#define USE_STL_DRQUE 1
|
||||
|
||||
#if USE_STL_VECTOR
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
namespace XEngine::utl {
|
||||
template<typename T>
|
||||
using vector = std::vector<T>;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 通过交换尾元素方式无序删除。
|
||||
* @tparam T 容器类型。
|
||||
* @param v 目标容器。
|
||||
* @param index 删除下标。
|
||||
*/
|
||||
template<typename T>
|
||||
void erase_unordered(T& v, size_t index)
|
||||
{
|
||||
if (v.size() > 1)
|
||||
{
|
||||
std::iter_swap(v.begin() + index, v.end() - 1);
|
||||
v.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
v.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#include "Vector.h"
|
||||
|
||||
namespace XEngine::utl {
|
||||
/**
|
||||
* @brief 调用自定义容器的无序删除接口。
|
||||
* @tparam T 容器类型。
|
||||
* @param v 目标容器。
|
||||
* @param index 删除下标。
|
||||
*/
|
||||
template<typename T>
|
||||
void erase_unordered(T& v, size_t index)
|
||||
{
|
||||
v.erase_unordered(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_STL_DRQUE
|
||||
#include <deque>
|
||||
namespace XEngine::utl {
|
||||
template<typename T>
|
||||
using deque = std::deque<T>;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
namespace XEngine::utl {
|
||||
}
|
||||
|
||||
#include "FreeList.h"
|
||||
Reference in New Issue
Block a user