change:基本定义更改用于同时支持wstring和string。

This commit is contained in:
taynpg 2024-11-15 13:16:04 +08:00
parent 13132f5212
commit b8ec3c55cb
7 changed files with 93 additions and 11 deletions

58
.vscode/settings.json vendored
View File

@ -19,9 +19,9 @@
"args": [ "args": [
] ]
}, },
// "cmake.configureSettings": { "cmake.configureSettings": {
// "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
// }, },
"cmake.options.statusBarVisibility": "visible", "cmake.options.statusBarVisibility": "visible",
"cmake.generator": "Ninja", "cmake.generator": "Ninja",
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json", "C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
@ -31,5 +31,57 @@
"ja": true, "ja": true,
"zh-hant": true, "zh-hant": true,
"zh-hans": true "zh-hans": true
},
"files.associations": {
"xstring": "cpp",
"algorithm": "cpp",
"chrono": "cpp",
"cmath": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
} }
} }

View File

@ -11,11 +11,14 @@ endif()
message(STATUS "System: ${CMAKE_SYSTEM_NAME}") message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}") message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")
set(SRC_FILES # find_package(GTest CONFIG REQUIRED)
include/of_path.h src/of_path.cpp
include/of_str.h src/of_str.cpp
)
set(SRC_FILES
src/of_path.cpp src/of_str.cpp
)
include_directories(include) include_directories(include)
add_subdirectory(test)
add_library(Ofen STATIC ${SRC_FILES}) add_library(Ofen STATIC ${SRC_FILES})
target_include_directories(Ofen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(Ofen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

14
include/of_def.hpp Normal file
View File

@ -0,0 +1,14 @@
#ifndef OFEN_DEFINE
#define OFEN_DEFINE
#include <string>
#ifdef UNICODE_OFSTR
using ofString = std::wstring;
#define ofT(text) L##text
#else
using ofString = std::string;
#define ofT(text) text
#endif
#endif

View File

@ -1,7 +1,7 @@
#ifndef OFEN_PATH_HEADER #ifndef OFEN_PATH_HEADER
#define OFEN_PATH_HEADER #define OFEN_PATH_HEADER
#include <string> #include "of_def.hpp"
namespace ofen { namespace ofen {
class COfPath class COfPath
@ -11,7 +11,7 @@ public:
~COfPath(); ~COfPath();
public: public:
static bool is_same_path(const std::string& pa, const std::string& pb); static bool is_same_path(const ofString& pa, const ofString& pb);
}; };
}; // namespace ofen }; // namespace ofen
#endif #endif

View File

@ -1,7 +1,7 @@
#ifndef OFEN_STRING_HEADER #ifndef OFEN_STRING_HEADER
#define OFEN_STRING_HEADER #define OFEN_STRING_HEADER
#include <string> #include "of_def.hpp"
namespace ofen { namespace ofen {
class COfStr class COfStr

View File

@ -11,7 +11,7 @@ COfPath::~COfPath()
{ {
} }
bool COfPath::is_same_path(const std::string& pa, const std::string& pb) bool COfPath::is_same_path(const ofString& pa, const ofString& pb)
{ {
return false; return false;
} }

13
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.16)
project(ofen LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (MSVC)
add_compile_options(/source-charset:utf-8)
endif()
add_executable(ofTest main.cpp)
target_link_libraries(ofTest PRIVATE Ofen)