From 2b71bf8135047b73e035724534450e8740ff0fc4 Mon Sep 17 00:00:00 2001
From: hyzboy
Date: Mon, 19 Aug 2019 19:19:58 +0800
Subject: [PATCH] first commit
---
CMakeLists.txt | 14 +
cmake/CMCoreCheck.cmake | 11 +
cmake/compiler.cmake | 47 +
cmake/output_path.cmake | 33 +
cmake/system_bit.cmake | 31 +
cmake/version.cmake | 25 +
inc/hgl/CodePage.h | 243 ++
inc/hgl/CompOperator.h | 16 +
inc/hgl/Endian.h | 275 +++
inc/hgl/LogInfo.h | 63 +
inc/hgl/Logger.h | 133 ++
inc/hgl/Macro.h | 120 +
inc/hgl/Time.h | 23 +
inc/hgl/TypeFunc.h | 655 ++++++
inc/hgl/filesystem/AssetManage.h | 9 +
inc/hgl/filesystem/EnumFile.h | 75 +
inc/hgl/filesystem/EnumVolume.h | 99 +
inc/hgl/filesystem/FileSystem.h | 229 ++
inc/hgl/io/DataInputStream.h | 231 ++
inc/hgl/io/DataOutputStream.h | 226 ++
inc/hgl/io/EndianDataInputStream.h | 100 +
inc/hgl/io/EndianDataOutputStream.h | 103 +
inc/hgl/io/FileAccess.h | 83 +
inc/hgl/io/FileInputStream.h | 78 +
inc/hgl/io/FileOutputStream.h | 93 +
inc/hgl/io/IOType.h | 34 +
inc/hgl/io/InputStream.h | 39 +
inc/hgl/io/JavaInputStream.h | 71 +
inc/hgl/io/JavaOutputStream.h | 62 +
inc/hgl/io/MemoryInputStream.h | 162 ++
inc/hgl/io/MemoryOutputStream.h | 235 ++
inc/hgl/io/OutputStream.h | 36 +
inc/hgl/io/RandomAccessFile.h | 47 +
inc/hgl/io/SeekAccess.h | 36 +
inc/hgl/io/TextOutputStream.h | 176 ++
inc/hgl/math/FastTriangle.h | 23 +
inc/hgl/math/Math.h | 8 +
inc/hgl/math/Matrix.h | 156 ++
inc/hgl/math/Vector.h | 346 +++
inc/hgl/platform/Exit.h | 10 +
inc/hgl/platform/ExternalModule.h | 36 +
inc/hgl/platform/FuncLoad.h | 31 +
inc/hgl/platform/Platform.h | 334 +++
inc/hgl/platform/SystemInfo.h | 69 +
inc/hgl/platform/compiler/DataTypeGNU.h | 21 +
inc/hgl/platform/compiler/DataTypeTiny.h | 29 +
inc/hgl/platform/compiler/DataTypeWin.h | 17 +
inc/hgl/platform/compiler/EventFunc.h | 250 +++
inc/hgl/platform/compiler/GNU.h | 85 +
inc/hgl/platform/compiler/Intel.h | 43 +
inc/hgl/platform/compiler/LLVM.h | 25 +
inc/hgl/platform/compiler/Microsoft.h | 61 +
inc/hgl/platform/compiler/Property.h | 97 +
inc/hgl/platform/os/Android.h | 86 +
inc/hgl/platform/os/BSD.h | 83 +
inc/hgl/platform/os/Linux.h | 75 +
inc/hgl/platform/os/MSWindows.h | 80 +
inc/hgl/platform/os/MacOS.h | 78 +
inc/hgl/platform/os/PosixThread.h | 15 +
inc/hgl/proc/Fifo.h | 29 +
inc/hgl/proc/FifoInputStream.h | 35 +
inc/hgl/proc/Pipe.h | 24 +
inc/hgl/proc/Proc.h | 41 +
inc/hgl/proc/ProcMutex.h | 37 +
inc/hgl/thread/ASyncEvent.h | 123 +
inc/hgl/thread/Atomic.h | 61 +
inc/hgl/thread/CondVar.h | 32 +
inc/hgl/thread/DataPost.h | 156 ++
inc/hgl/thread/Loader.h | 74 +
inc/hgl/thread/RWLock.h | 187 ++
inc/hgl/thread/RingBuffer.cpp | 58 +
inc/hgl/thread/RingBuffer.h | 345 +++
inc/hgl/thread/RingBufferRead.cpp | 210 ++
inc/hgl/thread/RingBufferWrite.cpp | 181 ++
inc/hgl/thread/SemLock.h | 233 ++
inc/hgl/thread/Semaphore.h | 33 +
inc/hgl/thread/SwapColl.h | 156 ++
inc/hgl/thread/SwapData.h | 240 ++
inc/hgl/thread/Thread.h | 230 ++
inc/hgl/thread/ThreadMutex.h | 163 ++
inc/hgl/thread/Workflow.h | 371 ++++
inc/hgl/thread/atomic/AtomicGNU.h | 48 +
inc/hgl/thread/atomic/AtomicOSX.h | 50 +
inc/hgl/thread/atomic/AtomicWin.h | 91 +
inc/hgl/type/BaseString.h | 1207 ++++++++++
inc/hgl/type/Color.h | 244 ++
inc/hgl/type/Color3f.h | 91 +
inc/hgl/type/Color4f.h | 100 +
inc/hgl/type/DataType.h | 12 +
inc/hgl/type/DateTime.h | 178 ++
inc/hgl/type/EnumClass.h | 13 +
inc/hgl/type/LRUCache.cpp | 354 +++
inc/hgl/type/LRUCache.h | 78 +
inc/hgl/type/List.cpp | 492 ++++
inc/hgl/type/List.h | 195 ++
inc/hgl/type/Map.cpp | 582 +++++
inc/hgl/type/Map.h | 340 +++
inc/hgl/type/MemBlock.h | 203 ++
inc/hgl/type/ObjectList.cpp | 249 +++
inc/hgl/type/Pair.h | 82 +
inc/hgl/type/Pool.cpp | 144 ++
inc/hgl/type/Pool.h | 267 +++
inc/hgl/type/Queue.cpp | 239 ++
inc/hgl/type/Queue.h | 75 +
inc/hgl/type/RectScope.cpp | 80 +
inc/hgl/type/RectScope.h | 141 ++
inc/hgl/type/ResManage.cpp | 160 ++
inc/hgl/type/ResManage.h | 88 +
inc/hgl/type/ResPoolManage.h | 34 +
inc/hgl/type/Set.cpp | 365 +++
inc/hgl/type/Set.h | 77 +
inc/hgl/type/Smart.h | 537 +++++
inc/hgl/type/Stack.cpp | 261 +++
inc/hgl/type/Stack.h | 59 +
inc/hgl/type/StdString.h | 35 +
inc/hgl/type/StrChar.h | 2593 ++++++++++++++++++++++
inc/hgl/type/StringInstance.h | 500 +++++
inc/hgl/type/StringList.h | 712 ++++++
inc/hgl/type/Vertex2.cpp | 147 ++
inc/hgl/type/Vertex2.h | 113 +
inc/hgl/type/_Object.h | 36 +
src/CMakeLists.txt | 64 +
src/DataType/Color.cpp | 228 ++
src/DataType/Color3f.cpp | 75 +
src/DataType/Color4f.cpp | 70 +
src/DataType/Endian.cpp | 15 +
src/DataType/StringList.cpp | 182 ++
src/FileSystem/EnumFile.cpp | 42 +
src/FileSystem/FileSystem.cpp | 315 +++
src/IO/DataInputStream.cpp | 248 +++
src/IO/DataOutputStream.cpp | 185 ++
src/IO/FileAccess.cpp | 174 ++
src/IO/FileInputStream.cpp | 65 +
src/IO/FileOutputStream.cpp | 60 +
src/IO/IOType.cpp | 37 +
src/IO/RandomAccessFile.cpp | 60 +
src/IO/TextOutputStream.cpp | 47 +
src/Other/CodePage.cpp | 267 +++
src/Other/DateTime.cpp | 348 +++
src/Other/ExpendString.cpp | 120 +
src/Other/ThreadFunc.cpp | 44 +
src/Other/TimeCount.cpp | 57 +
src/Other/TimeVal.cpp | 14 +
src/PlugIn/ExternalModule.cpp | 93 +
src/SystemInfo.cpp | 136 ++
145 files changed, 23208 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 cmake/CMCoreCheck.cmake
create mode 100644 cmake/compiler.cmake
create mode 100644 cmake/output_path.cmake
create mode 100644 cmake/system_bit.cmake
create mode 100644 cmake/version.cmake
create mode 100644 inc/hgl/CodePage.h
create mode 100644 inc/hgl/CompOperator.h
create mode 100644 inc/hgl/Endian.h
create mode 100644 inc/hgl/LogInfo.h
create mode 100644 inc/hgl/Logger.h
create mode 100644 inc/hgl/Macro.h
create mode 100644 inc/hgl/Time.h
create mode 100644 inc/hgl/TypeFunc.h
create mode 100644 inc/hgl/filesystem/AssetManage.h
create mode 100644 inc/hgl/filesystem/EnumFile.h
create mode 100644 inc/hgl/filesystem/EnumVolume.h
create mode 100644 inc/hgl/filesystem/FileSystem.h
create mode 100644 inc/hgl/io/DataInputStream.h
create mode 100644 inc/hgl/io/DataOutputStream.h
create mode 100644 inc/hgl/io/EndianDataInputStream.h
create mode 100644 inc/hgl/io/EndianDataOutputStream.h
create mode 100644 inc/hgl/io/FileAccess.h
create mode 100644 inc/hgl/io/FileInputStream.h
create mode 100644 inc/hgl/io/FileOutputStream.h
create mode 100644 inc/hgl/io/IOType.h
create mode 100644 inc/hgl/io/InputStream.h
create mode 100644 inc/hgl/io/JavaInputStream.h
create mode 100644 inc/hgl/io/JavaOutputStream.h
create mode 100644 inc/hgl/io/MemoryInputStream.h
create mode 100644 inc/hgl/io/MemoryOutputStream.h
create mode 100644 inc/hgl/io/OutputStream.h
create mode 100644 inc/hgl/io/RandomAccessFile.h
create mode 100644 inc/hgl/io/SeekAccess.h
create mode 100644 inc/hgl/io/TextOutputStream.h
create mode 100644 inc/hgl/math/FastTriangle.h
create mode 100644 inc/hgl/math/Math.h
create mode 100644 inc/hgl/math/Matrix.h
create mode 100644 inc/hgl/math/Vector.h
create mode 100644 inc/hgl/platform/Exit.h
create mode 100644 inc/hgl/platform/ExternalModule.h
create mode 100644 inc/hgl/platform/FuncLoad.h
create mode 100644 inc/hgl/platform/Platform.h
create mode 100644 inc/hgl/platform/SystemInfo.h
create mode 100644 inc/hgl/platform/compiler/DataTypeGNU.h
create mode 100644 inc/hgl/platform/compiler/DataTypeTiny.h
create mode 100644 inc/hgl/platform/compiler/DataTypeWin.h
create mode 100644 inc/hgl/platform/compiler/EventFunc.h
create mode 100644 inc/hgl/platform/compiler/GNU.h
create mode 100644 inc/hgl/platform/compiler/Intel.h
create mode 100644 inc/hgl/platform/compiler/LLVM.h
create mode 100644 inc/hgl/platform/compiler/Microsoft.h
create mode 100644 inc/hgl/platform/compiler/Property.h
create mode 100644 inc/hgl/platform/os/Android.h
create mode 100644 inc/hgl/platform/os/BSD.h
create mode 100644 inc/hgl/platform/os/Linux.h
create mode 100644 inc/hgl/platform/os/MSWindows.h
create mode 100644 inc/hgl/platform/os/MacOS.h
create mode 100644 inc/hgl/platform/os/PosixThread.h
create mode 100644 inc/hgl/proc/Fifo.h
create mode 100644 inc/hgl/proc/FifoInputStream.h
create mode 100644 inc/hgl/proc/Pipe.h
create mode 100644 inc/hgl/proc/Proc.h
create mode 100644 inc/hgl/proc/ProcMutex.h
create mode 100644 inc/hgl/thread/ASyncEvent.h
create mode 100644 inc/hgl/thread/Atomic.h
create mode 100644 inc/hgl/thread/CondVar.h
create mode 100644 inc/hgl/thread/DataPost.h
create mode 100644 inc/hgl/thread/Loader.h
create mode 100644 inc/hgl/thread/RWLock.h
create mode 100644 inc/hgl/thread/RingBuffer.cpp
create mode 100644 inc/hgl/thread/RingBuffer.h
create mode 100644 inc/hgl/thread/RingBufferRead.cpp
create mode 100644 inc/hgl/thread/RingBufferWrite.cpp
create mode 100644 inc/hgl/thread/SemLock.h
create mode 100644 inc/hgl/thread/Semaphore.h
create mode 100644 inc/hgl/thread/SwapColl.h
create mode 100644 inc/hgl/thread/SwapData.h
create mode 100644 inc/hgl/thread/Thread.h
create mode 100644 inc/hgl/thread/ThreadMutex.h
create mode 100644 inc/hgl/thread/Workflow.h
create mode 100644 inc/hgl/thread/atomic/AtomicGNU.h
create mode 100644 inc/hgl/thread/atomic/AtomicOSX.h
create mode 100644 inc/hgl/thread/atomic/AtomicWin.h
create mode 100644 inc/hgl/type/BaseString.h
create mode 100644 inc/hgl/type/Color.h
create mode 100644 inc/hgl/type/Color3f.h
create mode 100644 inc/hgl/type/Color4f.h
create mode 100644 inc/hgl/type/DataType.h
create mode 100644 inc/hgl/type/DateTime.h
create mode 100644 inc/hgl/type/EnumClass.h
create mode 100644 inc/hgl/type/LRUCache.cpp
create mode 100644 inc/hgl/type/LRUCache.h
create mode 100644 inc/hgl/type/List.cpp
create mode 100644 inc/hgl/type/List.h
create mode 100644 inc/hgl/type/Map.cpp
create mode 100644 inc/hgl/type/Map.h
create mode 100644 inc/hgl/type/MemBlock.h
create mode 100644 inc/hgl/type/ObjectList.cpp
create mode 100644 inc/hgl/type/Pair.h
create mode 100644 inc/hgl/type/Pool.cpp
create mode 100644 inc/hgl/type/Pool.h
create mode 100644 inc/hgl/type/Queue.cpp
create mode 100644 inc/hgl/type/Queue.h
create mode 100644 inc/hgl/type/RectScope.cpp
create mode 100644 inc/hgl/type/RectScope.h
create mode 100644 inc/hgl/type/ResManage.cpp
create mode 100644 inc/hgl/type/ResManage.h
create mode 100644 inc/hgl/type/ResPoolManage.h
create mode 100644 inc/hgl/type/Set.cpp
create mode 100644 inc/hgl/type/Set.h
create mode 100644 inc/hgl/type/Smart.h
create mode 100644 inc/hgl/type/Stack.cpp
create mode 100644 inc/hgl/type/Stack.h
create mode 100644 inc/hgl/type/StdString.h
create mode 100644 inc/hgl/type/StrChar.h
create mode 100644 inc/hgl/type/StringInstance.h
create mode 100644 inc/hgl/type/StringList.h
create mode 100644 inc/hgl/type/Vertex2.cpp
create mode 100644 inc/hgl/type/Vertex2.h
create mode 100644 inc/hgl/type/_Object.h
create mode 100644 src/CMakeLists.txt
create mode 100644 src/DataType/Color.cpp
create mode 100644 src/DataType/Color3f.cpp
create mode 100644 src/DataType/Color4f.cpp
create mode 100644 src/DataType/Endian.cpp
create mode 100644 src/DataType/StringList.cpp
create mode 100644 src/FileSystem/EnumFile.cpp
create mode 100644 src/FileSystem/FileSystem.cpp
create mode 100644 src/IO/DataInputStream.cpp
create mode 100644 src/IO/DataOutputStream.cpp
create mode 100644 src/IO/FileAccess.cpp
create mode 100644 src/IO/FileInputStream.cpp
create mode 100644 src/IO/FileOutputStream.cpp
create mode 100644 src/IO/IOType.cpp
create mode 100644 src/IO/RandomAccessFile.cpp
create mode 100644 src/IO/TextOutputStream.cpp
create mode 100644 src/Other/CodePage.cpp
create mode 100644 src/Other/DateTime.cpp
create mode 100644 src/Other/ExpendString.cpp
create mode 100644 src/Other/ThreadFunc.cpp
create mode 100644 src/Other/TimeCount.cpp
create mode 100644 src/Other/TimeVal.cpp
create mode 100644 src/PlugIn/ExternalModule.cpp
create mode 100644 src/SystemInfo.cpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..ccef777
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.0)
+
+project(CMCore)
+
+set(CMCORE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+set(CMCORE_ROOT_INCLUDE_PATH ${CMCORE_ROOT_PATH}/inc)
+set(CMCORE_ROOT_SOURCE_PATH ${CMCORE_ROOT_PATH}/src)
+
+set(CMAKE_MODULE_PATH ${CMCORE_ROOT_PATH}/cmake)
+
+include(CMCoreCheck)
+
+include_directories(${CMCORE_ROOT_INCLUDE_PATH})
+add_subdirectory(${CMCORE_ROOT_SOURCE_PATH})
diff --git a/cmake/CMCoreCheck.cmake b/cmake/CMCoreCheck.cmake
new file mode 100644
index 0000000..f098c2c
--- /dev/null
+++ b/cmake/CMCoreCheck.cmake
@@ -0,0 +1,11 @@
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
+include(system_bit)
+include(version)
+include(compiler)
+include(output_path)
+
+check_system_bits()
+check_system_version()
+set_compiler_param()
+set_output_directory()
diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
new file mode 100644
index 0000000..d7f5bca
--- /dev/null
+++ b/cmake/compiler.cmake
@@ -0,0 +1,47 @@
+macro(set_compiler_param)
+
+ IF(WIN32)
+
+ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd")
+ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
+
+ SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
+ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
+
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14")
+
+ add_compile_options(/arch:AVX2)
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+
+ ELSE()
+ IF(NOT ANDROID)
+ IF(APPLE)
+ SET(USE_CLANG ON)
+ ELSE()
+ OPTION(USE_CLANG OFF)
+ ENDIF()
+
+ if(USE_CLANG)
+ SET(CMAKE_C_COMPILER clang)
+ SET(CMAKE_CXX_COMPILER clang++)
+ endif()
+ ENDIF()
+
+ add_compile_options(-mavx)
+
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
+
+ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3")
+ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb3")
+
+ SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast")
+ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")
+ ENDIF()
+
+ MESSAGE("C Compiler: " ${CMAKE_C_COMPILER})
+ MESSAGE("C++ Compiler: " ${CMAKE_CXX_COMPILER})
+ MESSAGE("C Flag: " ${CMAKE_C_FLAGS})
+ MESSAGE("C++ Flag: " ${CMAKE_CXX_FLAGS})
+
+endmacro()
diff --git a/cmake/output_path.cmake b/cmake/output_path.cmake
new file mode 100644
index 0000000..b435b2f
--- /dev/null
+++ b/cmake/output_path.cmake
@@ -0,0 +1,33 @@
+macro(set_output_directory)
+
+ IF(ANDROID)
+ SET(OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/out/android/${ANDROID_ABI})
+ ELSEIF(IOS)
+ SET(OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/out/iOS/${IOS_PLATFORM})
+ ELSE()
+ IF(WIN32)
+ SET(USE_GUI ON)
+ ENDIF()
+
+ SET(OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/out/${CMAKE_SYSTEM_NAME}_${HGL_BITS})
+ ENDIF()
+
+ MESSAGE("SYSTEM NAME: " ${CMAKE_SYSTEM_NAME})
+ MESSAGE("OUTPUT DIRECTORY: " ${OUTPUT_DIRECTORY})
+
+ SET(OUTPUT_DIRECTORY_DEBUG ${OUTPUT_DIRECTORY}_Debug)
+ SET(OUTPUT_DIRECTORY_RELEASE ${OUTPUT_DIRECTORY}_Release)
+
+ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
+ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
+ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
+
+ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_DIRECTORY_DEBUG})
+ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_DIRECTORY_DEBUG})
+ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_DIRECTORY_DEBUG})
+
+ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_DIRECTORY_RELEASE})
+ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_DIRECTORY_RELEASE})
+ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_DIRECTORY_RELEASE})
+
+endmacro()
diff --git a/cmake/system_bit.cmake b/cmake/system_bit.cmake
new file mode 100644
index 0000000..cf0d8b3
--- /dev/null
+++ b/cmake/system_bit.cmake
@@ -0,0 +1,31 @@
+macro(check_system_bits)
+
+ IF(APPLE)
+ SET(HGL_BITS 64)
+ ELSE()
+ IF(ANDROID)
+ if(ANDROID_ABI MATCHES ".*64.*")
+ SET(HGL_BITS 64)
+ else()
+ SET(HGL_BITS 32)
+ endif()
+ ELSE()
+ IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ SET(HGL_BITS 64)
+ ELSE()
+ SET(HGL_BITS 32)
+ ENDIF()
+ endif()
+ endif()
+
+ IF(HGL_BITS EQUAL 32)
+ add_definitions(-DHGL_32_BITS)
+ add_definitions(-DHGL_POINTER_UINT=uint32)
+ ELSE()
+ add_definitions(-DHGL_64_BITS)
+ add_definitions(-DHGL_POINTER_UINT=uint64)
+ ENDIF()
+
+ Message("System is ${HGL_BITS} Bit")
+
+endmacro()
diff --git a/cmake/version.cmake b/cmake/version.cmake
new file mode 100644
index 0000000..090f70d
--- /dev/null
+++ b/cmake/version.cmake
@@ -0,0 +1,25 @@
+macro(check_system_version)
+
+ message("Host system: " ${CMAKE_HOST_SYSTEM})
+ message("Host system name: " ${CMAKE_HOST_SYSTEM_NAME})
+ message("Host system version: " ${CMAKE_HOST_SYSTEM_VERSION})
+
+ message("Compile features: " ${CMAKE_CXX_COMPILE_FEATURES})
+ message("Compile Flags: " ${CMAKE_C_FLAGS})
+ message("C++ Compile Flags: " ${CMAKE_CXX_FLAGS})
+ message("Build type: " ${CMAKE_BUILD_TYPE})
+
+ add_definitions(-DHGL_HOST_SYSTEM="${CMAKE_HOST_SYSTEM}")
+
+ add_definitions(-DHGL_COMPILE_C_FLAGS="${CMAKE_C_FLAGS}")
+ add_definitions(-DHGL_COMPILE_CXX_FLAGS="${CMAKE_CXX_FLAGS}")
+
+ add_definitions(-DCMAKE_VERSION="${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
+
+ MESSAGE("C Compile Features: " ${CMAKE_C_COMPILE_FEATURES})
+ MESSAGE("C++ Compile Features: " ${CMAKE_CXX_COMPILE_FEATURES})
+
+ # add_definitions(-DHGL_COMPILE_C_FEATURES="${CMAKE_C_COMPILE_FEATURES}")
+ # add_definitions(-DHGL_COMPILE_CXX_FEATURES="${CMAKE_CXX_COMPILE_FEATURES}")
+
+endmacro()
diff --git a/inc/hgl/CodePage.h b/inc/hgl/CodePage.h
new file mode 100644
index 0000000..d647f1c
--- /dev/null
+++ b/inc/hgl/CodePage.h
@@ -0,0 +1,243 @@
+#ifndef HGL_CODE_PAGE_INCLUDE
+#define HGL_CODE_PAGE_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ struct CodePageAndCharSet
+ {
+ CharCodePage codepage;
+ CharSetName charset;
+ };
+
+ constexpr struct CodePageAndCharSet CodePage2CharSet[]=
+ {
+ {ccpNone, "us-ascii" },
+
+ {ccpGBK, "gbk" },
+ {ccpBig5, "big5" },
+ {ccpGB2312, "gb2312" },
+ {ccpGB18030, "gb18030" },
+
+ {ccpShiftJIS, "shift-jis" },
+ {ccpJISX, "iso-2022-jp" },
+
+ {ccpKorean, "ks_c_5601-1987"},
+
+ {ccpMacJanpan, "x-mac-japanese" },
+ {ccpMacTraditionalChinese, "x-mac-chinesetrad" },
+ {ccpMacSimplifiedChinese, "x-mac-chinesesimp" },
+
+ {ccpUTF7, "utf-7" },
+ {ccpUTF8, "utf-8" },
+
+ {ccpUTF16LE, "utf-16le" },
+ {ccpUTF16BE, "utf-16be" },
+ {ccpUTF32LE, "utf-32le" },
+ {ccpUTF32BE, "utf-32be" },
+ };//const struct
+
+ constexpr int CharSetCount=sizeof(CodePage2CharSet)/sizeof(CodePageAndCharSet);
+
+ inline const char *FindCharSet(CharCodePage ccp)
+ {
+ for(int i=0;i(str)+1,len);
+ }
+
+ inline u16char *u8_to_u16(const char *str)
+ {
+ int len;
+ return u8_to_u16(str,hgl::strlen(str)+1,len);
+ }
+
+ inline UTF16String to_u16(const char *u8_str,int length)
+ {
+ int wlen;
+ u16char *ws=u8_to_u16(u8_str,length,wlen);
+
+ return UTF16String(ws,wlen,true);
+ }
+
+ inline UTF16String to_u16(const UTF8String &u8str)
+ {
+ return to_u16(u8str.c_str(),u8str.Length());
+ }
+
+ inline UTF16String to_u16(const char *str)
+ {
+ int wlen;
+
+ u16char *ws=u8_to_u16(str,strlen(str),wlen);
+
+ return UTF16String(ws,wlen,true);
+ }
+
+ inline UTF8String to_u8(const u16char *wide_str,int length)
+ {
+ int ulen;
+
+ char *us=u16_to_u8(wide_str,length,ulen);
+
+ return UTF8String(us,ulen,true);
+ }
+
+ inline UTF8String to_u8(const UTF16String &ws)
+ {
+ return to_u8(ws.c_str(),ws.Length());
+ }
+
+#if HGL_OS == HGL_OS_Windows
+ inline OSString ToOSString(const char *str){return to_u16(str);}
+ inline OSString ToOSString(const UTF8String &str){return to_u16(str.c_str(), (int)(str.Length()));}
+
+ inline UTF8String ToUTF8String(const os_char *str){return to_u8(str,strlen(str));}
+ inline UTF8String ToUTF8String(const OSString &str){return to_u8(str);}
+#else
+ inline OSString ToOSString(const char *str){return OSString(str);}
+ inline OSString ToOSString(const UTF8String &str){return str;}
+
+ inline UTF8String ToUTF8String(const os_char *str){return UTF8String(str);}
+ inline UTF8String ToUTF8String(const OSString &str){return str;}
+#endif//
+
+ const BOMFileHeader *ParseBOM(const void *input);
+
+ bool BOM2CharSet(CharSet *cs,const BOMFileHeader *bom);
+}//namespace hgl
+#endif//HGL_CODE_PAGE_INCLUDE
diff --git a/inc/hgl/CompOperator.h b/inc/hgl/CompOperator.h
new file mode 100644
index 0000000..474581a
--- /dev/null
+++ b/inc/hgl/CompOperator.h
@@ -0,0 +1,16 @@
+#ifndef HGL_COMP_OPERATOR_INCLUDE
+#define HGL_COMP_OPERATOR_INCLUDE
+
+namespace hgl
+{
+ #define CompOperator(name,compfunc) const bool operator > (name i)const {return compfunc(i)>0;} \
+ const bool operator < (name i)const {return compfunc(i)<0;} \
+ const bool operator >=(name i)const {return compfunc(i)>=0;}\
+ const bool operator <=(name i)const {return compfunc(i)<=0;}\
+ const bool operator ==(name i)const {return compfunc(i)==0;}\
+ const bool operator !=(name i)const {return compfunc(i)!=0;}
+
+ #define CompOperatorMemcmp(name) int _Comp(name data)const{return memcmp(this,&data,sizeof(name));} \
+ CompOperator(name,_Comp)
+}//namespace hgl
+#endif//HGL_COMP_OPERATOR_INCLUDE
diff --git a/inc/hgl/Endian.h b/inc/hgl/Endian.h
new file mode 100644
index 0000000..3461e31
--- /dev/null
+++ b/inc/hgl/Endian.h
@@ -0,0 +1,275 @@
+#ifndef HGL_ENDIAN_INCLUDE
+#define HGL_ENDIAN_INCLUDE
+
+#include // 平台定义
+namespace hgl
+{
+ namespace endian
+ {
+ /**
+ * Windows代码页枚举
+ * 全部Windows所支持代码页请参见 http://msdn.microsoft.com/en-us/library/dd317756
+ */
+ enum CharCodePage ///代码页枚举
+ {
+ ccpNone=0, ///<起始定义,无意义
+
+ //中文
+ ccpGBK =936, ///<中国GBK标准中文
+ ccpBig5 =950, ///<中国台湾Big5标准繁体中文
+ ccpGB2312 =20936, ///<中国GB2312标准简体中文
+ ccpGB18030 =54936, ///<中国GB18030-2000标准中文
+
+ //日文
+ ccpShiftJIS =932, ///<日文ShiftJIS
+ ccpJISX =50222, ///<日文JIS X/ISO 2022
+
+ //韩文
+ ccpKorean =949, ///<韩文
+
+ //苹果编码
+ ccpMacJanpan =10001, ///<日文
+ ccpMacTraditionalChinese =10002, ///<繁体中文
+ ccpMacSimplifiedChinese =10008, ///<简体中文
+
+ //unicode
+ ccpUTF7 =65000, /// const CharSetName &GetCurCharSet(); ///<取得当前程序编码字符集
+
+ constexpr CharSetName utf8_charset="utf8";
+ constexpr CharSetName utf16le_charset="utf-16le";
+ constexpr CharSetName utf16be_charset="utf-16be";
+ constexpr CharSetName utf32le_charset="utf-32le";
+ constexpr CharSetName utf32be_charset="utf-32be";
+
+ template<> inline const CharSetName &GetCurCharSet<2,HGL_LITTLE_ENDIAN >(){return utf16le_charset;}
+ template<> inline const CharSetName &GetCurCharSet<2,HGL_BIG_ENDIAN >(){return utf16be_charset;}
+ template<> inline const CharSetName &GetCurCharSet<4,HGL_LITTLE_ENDIAN >(){return utf32le_charset;}
+ template<> inline const CharSetName &GetCurCharSet<4,HGL_BIG_ENDIAN >(){return utf32be_charset;}
+
+ template inline const CharSetName &GetCharSet()
+ {
+ return GetCurCharSet();
+ }
+
+ /**
+ * 字节序文件头数据结构
+ */
+ struct BOMFileHeader
+ {
+ int size; ///<字节序文件头长度
+ unsigned char data[4]; ///<字节序数据
+
+ ByteOrderMask bom; ///<字节序枚举
+ const CharSetName *char_set;///<字符集名称
+ CharCodePage code_page; ///<代码页
+ };
+
+ /**
+ * 字节序文件头定义
+ */
+ constexpr BOMFileHeader BOMData[bomEnd]=
+ {
+ {0,{} ,bomNone, nullptr ,ccpNone },
+ {3,{0xEF,0xBB,0xBF} ,bomUTF8, &utf8_charset ,ccpUTF8 },
+ {2,{0xFF,0xFE} ,bomUTF16LE,&utf16le_charset ,ccpUTF16LE },
+ {2,{0xFE,0xFF} ,bomUTF16BE,&utf16be_charset ,ccpUTF16BE },
+ {4,{0xFF,0xFE,0x00,0x00},bomUTF32LE,&utf32le_charset ,ccpUTF32LE },
+ {4,{0x00,0x00,0xFE,0xFF},bomUTF32BE,&utf32be_charset ,ccpUTF32BE }
+ };
+
+ template
+ inline T EndianSwap(const T value)
+ {
+ union
+ {
+ T v;
+ uint8 bytes[sizeof(T)];
+ }a,b;
+
+ a.v=value;
+
+ for(uint i=0;i inline int8 EndianSwap< int8>(const int8 value){return value;}
+ template<> inline uint8 EndianSwap(const uint8 value){return value;}
+
+ template<> inline uint16 EndianSwap(const uint16 value)
+ {
+ return ((value&0xFF)<<8)
+ |((value&0xFF00)>>8);
+ }
+
+ template<> inline uint32 EndianSwap(const uint32 value)
+ {
+ return ((value&0xFF)<<24)
+ |((value&0xFF00)<<8)
+ |((value&0xFF0000)>>8)
+ |((value&0xFF000000)>>24);
+ }
+
+ template<> inline uint64 EndianSwap(const uint64 value)
+ {
+ return ((value&0xFF)<<56)
+ |((value&0xFF00)<<40)
+ |((value&0xFF0000)<<24)
+ |((value&0xFF000000)<<8)
+ |((value&0xFF00000000)>>8)
+ |((value&0xFF0000000000)>>24)
+ |((value&0xFF000000000000)>>40)
+ |((value&0xFF00000000000000)>>56);
+ }
+
+ template<> inline u16char EndianSwap(const u16char value){return EndianSwap(uint16(value));}
+
+ template
+ inline void EndianSwap(T *value,const int64 count)
+ {
+ for(int64 i=0;i
+ inline void EndianSwap(T *dst,const T *src,const int64 count)
+ {
+ for(uint i=0;i
+ inline void EndianSwap(D *dst,const S *src,const int64 count)
+ {
+ for(uint i=0;i T ToBigEndian(T value){return value;}
+
+ template inline void ToBigEndian(T *value,const int64 count){}
+ template inline void ToBigEndian(D *dst,const S *src,const int64 count){hgl_cpy(dst,src,count);}
+
+ template T ToLittleEndian(T value){return EndianSwap(value);}
+
+ template inline void ToLittleEndian(T *value,const int64 count){EndianSwap(value,count);}
+ template inline void ToLittleEndian(D *dst,const S *src,const int64 count){EndianSwap(dst,src,count);}
+
+ #else
+
+ constexpr uint HGL_BOM_UTF16LE =0xfeff;
+ constexpr uint HGL_BOM_UTF16BE =0xfffe;
+ constexpr uint HGL_BOM_UTF32LE =0x0000feff;
+ constexpr uint HGL_BOM_UTF32BE =0xfffe0000;
+
+ #define LittleToCurrentEndian ToLittleEndian
+ #define BigToCurrentEndian EndianSwap
+
+ template T ToBigEndian(T value){return EndianSwap(value);}
+
+ template inline void ToBigEndian(T *value,const int64 count){EndianSwap(value,count);}
+ template inline void ToBigEndian(D *dst,const S *src,const int64 count){EndianSwap(dst,src,count);}
+
+ template T ToLittleEndian(T value){return value;}
+
+ template inline void ToLittleEndian(T *,const int64){}
+ template inline void ToLittleEndian(D *dst,const S *src,const int64 count){hgl_cpy(dst,src,count);}
+
+ #endif//HGL_BIG_ENDIAN
+
+ template struct UTF16CharConvert;
+
+ template<> struct UTF16CharConvert
+ {
+ #if HGL_ENDIAN == HGL_BIG_ENDIAN
+ static void convert(u16char *str,const int length)
+ {
+ EndianSwap(str,length);
+ }
+ #else
+ static void convert(const u16char *,const int){}
+ #endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+
+ static void convert(u16char *out_str,const u16char *in_str,const int length)
+ {
+ #if HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ memcpy(out_str,in_str,length*sizeof(u16char));
+ #else
+ EndianSwap(in_str,length);
+ #endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ }
+ };//template<> struct UTF16CharConvert
+
+ template<> struct UTF16CharConvert
+ {
+ static void convert(u16char *str,const int length)
+ {
+ #if HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ EndianSwap(str,length);
+ #endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ }
+
+ static void convert(u16char *out_str,const u16char *in_str,const int length)
+ {
+ #if HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ memcpy(out_str,in_str,length*sizeof(u16char));
+ #else
+ EndianSwap(in_str,length);
+ #endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ }
+ };//template<> struct UTF16ToWideChar
+ }//namespace endian
+
+ using namespace endian;
+}//namespace hgl
+#endif//HGL_ENDIAN_INCLUDE
diff --git a/inc/hgl/LogInfo.h b/inc/hgl/LogInfo.h
new file mode 100644
index 0000000..71ac103
--- /dev/null
+++ b/inc/hgl/LogInfo.h
@@ -0,0 +1,63 @@
+#ifndef HGL_LOGINFO_INCLUDE
+#define HGL_LOGINFO_INCLUDE
+
+#include
+#include
+
+#if (HGL_COMPILER == HGL_COMPILER_GNU)||(HGL_COMPILER == HGL_COMPILER_LLVM)
+ #define __HGL_FUNC__ __PRETTY_FUNCTION__
+#elif HGL_COMPILER == HGL_COMPILER_Microsoft
+ #define __HGL_FUNC__ __FUNCSIG__
+#else
+ #define __HGL_FUNC__ __FUNCTION__
+#endif//
+
+namespace hgl
+{
+ namespace logger
+ {
+ enum LogLevel
+ {
+ llError=0, //错误,肯定出对话框
+ llProblem, //问题,默认出对话框
+ llHint, //提示,不重要,debug状态默认出对话框
+ llLog //记录一下
+ };//enum LogLevel
+
+ inline void Log(LogLevel ll,const UTF16String &str)
+ {
+ std::wcout<>LogFrom(\"")+to_u16(filename)+U16_TEXT("\", ")+UTF16String(line)+U16_TEXT(" line,func:\"")+to_u16(funcname)+U16_TEXT("\")"));
+ }
+
+ inline void DebugLog(LogLevel ll,const UTF8String &str,const char *filename,int line,const char *funcname)
+ {
+ Log(ll,str+U8_TEXT(">>LogFrom(\"")+UTF8String(filename)+U8_TEXT("\", ")+UTF8String(line)+U8_TEXT(" line,func:\"")+UTF8String(funcname)+U8_TEXT("\")"));
+ }
+
+ #define LOG_INFO(str) {Log(llLog, str);}
+ #define LOG_HINT(str) {Log(llHint, str);}
+ #define LOG_PROBLEM(str) {Log(llProblem, str);}
+ #define LOG_ERROR(str) {Log(llError, str);}
+
+ #define RETURN_FALSE {DebugLog(llLog,OS_TEXT("return(false)" ),__FILE__,__LINE__,__HGL_FUNC__);return(false);}
+ #define RETURN_ERROR(v) {DebugLog(llLog,OS_TEXT("return error(")+OSString(v)+OS_TEXT(")"),__FILE__,__LINE__,__HGL_FUNC__);return(v);}
+ #define RETURN_ERROR_NULL {DebugLog(llLog,OS_TEXT("return error(nullptr)" ),__FILE__,__LINE__,__HGL_FUNC__);return(nullptr);}
+
+ #define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}
+
+ #define IF_FALSE_RETURN(str) if(!str)RETURN_FALSE;
+ }//namespace logger
+
+ using namespace logger;
+}//namespace hgl
+#endif//HGL_LOGINFO_INCLUDE
diff --git a/inc/hgl/Logger.h b/inc/hgl/Logger.h
new file mode 100644
index 0000000..aa1283d
--- /dev/null
+++ b/inc/hgl/Logger.h
@@ -0,0 +1,133 @@
+#ifndef HGL_LOGGER_INCLUDE
+#define HGL_LOGGER_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace logger
+ {
+ enum LogLevel
+ {
+ llError=0, //错误,肯定出对话框
+ llProblem, //问题,默认出对话框
+ llHint, //提示,不重要,debug状态默认出对话框
+ llLog //记录一下
+ };//enum LogLevel
+
+ /**
+ * 日志输出基类
+ */
+ class Logger
+ {
+ protected:
+
+ LogLevel min_level; ///<最小输出级别
+ UTF16String project_code;
+
+ public:
+
+ Logger(LogLevel l){min_level=l;}
+ virtual ~Logger()=default;
+
+ const LogLevel GetLevel()const{return min_level;} ///<取得最小输出级别
+
+ virtual void Close()=0; ///<关闭日志
+
+ virtual void Write(const u16char *,int)=0; ///<输出一行u16char日志
+ virtual void Write(const char *,int)=0; ///<输出一行char(utf8)日志
+ };//class Logger
+ }//namespace logger
+
+ namespace logger
+ {
+ /**
+ * 日志级别枚举
+ */
+ enum LOG_LEVEL
+ {
+ LL_START=0, ///<日志级别起始定义
+
+ LL_HOTPOT, ///<性能记录热点
+ LL_CODE, ///<代码日志(引擎内部记录)
+ LL_USER, ///<用户日志(开发人员的日志)
+ LL_RUN, ///<运行日志(实际使用时的日志)
+
+ LL_END ///<日志级别结束定义
+ };
+
+ /**
+ * 影响级别
+ */
+ enum AFFECTOR_LEVEL
+ {
+ AL_START=0,
+
+ AL_USER, ///<用户级(无关仅要,正常程序逻辑报错)
+ AL_FUNC, ///<函数级(当前函数报错)
+ AL_MODULE, ///<模块级
+ AL_FULL, ///<整体级(很严重,只能退出)
+
+ AL_MUST_FIXED, ///<必须修正的代码问题
+
+ AL_END
+ };
+
+ /**
+ * 日志输出基类
+ */
+ class LoggerBase
+ {
+ protected:
+
+ LOG_LEVEL log_level;
+ AFFECTOR_LEVEL err_level;
+
+ protected:
+
+ uint32 source_file; ///<源代所在文件ID
+ uint32 source_line; ///<源代码所在行
+ uint32 function; ///<函数ID
+ HGL_POINTER_UINT object_address; ///<对象地址
+ HGL_POINTER_UINT thread_id; ///<线程ID
+
+ public:
+ };//class AdvLogger
+
+ /**
+ * 线程日志
+ */
+ class ThreadLogger
+ {
+
+ public:
+
+
+ };//class ThreadLogger
+
+ /**
+ * 对象日志
+ */
+ class ObjectLogger
+ {
+ };
+
+ /**
+ * 时间追踪日志
+ * 针对同一数据记录每一次时间下的数值的日志输出模块
+ */
+ class TimeLogger
+ {
+ };
+
+ /**
+ * 图形日志
+ * 用于记录碰撞信息,寻路信息,路线跟踪等等
+ */
+ class GraphicsLogger
+ {
+ };//
+ }//namespace logger
+
+ using namespace logger;
+}//namespace hgl
+#endif//HGL_LOGGER_INCLUDE
diff --git a/inc/hgl/Macro.h b/inc/hgl/Macro.h
new file mode 100644
index 0000000..ce84daa
--- /dev/null
+++ b/inc/hgl/Macro.h
@@ -0,0 +1,120 @@
+#ifndef HGL_MACRO_INCLUDE
+#define HGL_MACRO_INCLUDE
+
+namespace hgl
+{
+ #define RETURN_OBJECT_OF_ARRAY(array,index,max_count) return (index<0||index>=max_count)?nullptr:array[index];
+
+ #define NEW_NULL_ARRAY(name,type,count) { \
+ name=new type[count]; \
+ \
+ memset(name,0,sizeof(type)*count); \
+ }
+
+ #define SAFE_CLEAR(name) { \
+ if(name) \
+ { \
+ delete name; \
+ name=nullptr; \
+ } \
+ }
+
+ #define SAFE_CLEAR_ARRAY(name) { \
+ if(name) \
+ { \
+ delete[] name; \
+ name=nullptr; \
+ } \
+ }
+
+ #define SAFE_CLEAR_OBJECT_ARRAY(name,num) { \
+ if(name&&num>=0) \
+ { \
+ int safe_clear_object_array_number=num; \
+ \
+ while(safe_clear_object_array_number--) \
+ if(name[safe_clear_object_array_number]) \
+ delete name[safe_clear_object_array_number]; \
+ \
+ delete[] name; \
+ name=nullptr; \
+ } \
+ }
+
+ #define FREE_OBJECT_ARRAY(name,num) { \
+ if(name&&num>=0) \
+ { \
+ int free_object_array_number=num; \
+ \
+ while(free_object_array_number--) \
+ if(name[free_object_array_number]) \
+ delete name[free_object_array_number]; \
+ \
+ hgl_free(name); \
+ name=nullptr; \
+ } \
+ }
+
+ #define SAFE_FREE_OBJECT_ARRAY(name,num) { \
+ if(name) \
+ FREE_OBJECT_ARRAY(name,num); \
+ }
+
+ #define SAFE_FREE(name) { \
+ if(name) \
+ hgl_free(name); \
+ }
+
+ #define SAFE_RECREATE(name,code) { \
+ if(name) \
+ delete name; \
+ \
+ name=code; \
+ }
+
+ #define ARRAY_CALL(name,num,code) { \
+ int array_call_number=num; \
+ \
+ while(array_call_number--) \
+ name[array_call_number]->code; \
+ }
+
+ #define LOAD_FUNC(type,func) type func(void *buf,int buf_size) \
+ { \
+ if(!buf||buf_size<=0)return 0; \
+ \
+ MemoryInputStream ms(buf,buf_size); \
+ \
+ return(func(&ms)); \
+ } \
+ \
+ type func(const UTF16String &filename) \
+ { \
+ FileInputStream fs; \
+ \
+ if(fs.Open(filename)) \
+ return(func(&fs)); \
+ else \
+ return 0; \
+ }
+
+ #define SAVE_FUNC(type,func) bool func(type data,void *buf,int buf_size) \
+ { \
+ if(!buf||buf_size<=0)return(false); \
+ \
+ MemoryOutputStream ms(buf,buf_size); \
+ \
+ return(func(data,&ms)); \
+ } \
+ \
+ bool func(type data,const UTF16String &filename) \
+ { \
+ FileOutputStream fs; \
+ \
+ if(fs.CreateTrunc(filename)) \
+ return(func(data,&fs)); \
+ else \
+ return(false); \
+ }
+}//namespace hgl
+#endif//HGL_MACRO_INCLUDE
diff --git a/inc/hgl/Time.h b/inc/hgl/Time.h
new file mode 100644
index 0000000..b5d3e05
--- /dev/null
+++ b/inc/hgl/Time.h
@@ -0,0 +1,23 @@
+#ifndef HGL_TIME_INCLUDE
+#define HGL_TIME_INCLUDE
+
+#include
+
+namespace hgl //时间
+{
+ int GetTimeZone(); ///<返回时区的时差(单位:秒)
+
+ uint64 GetMilliStartTime(); ///<取得毫秒程序启动时间(单位:1/1000秒)
+ uint64 GetMicroStartTime(); ///<取得微秒程序启动时间(单位:1/1000000秒)
+ double GetDoubleStartTime(); ///<取得秒程序启动时间(单位:秒)
+
+ uint64 GetTime(); ///<取得当前时间(单位:1/1000秒)
+ uint64 GetMicroTime(); ///<取得当前时间(单位:1/1000000秒)
+ double GetDoubleTime(); ///<取得当前时间(单位:秒)
+
+ double GetLocalDoubleTime(); ///<取得本地当前时间(单位:秒)
+
+ void WaitTime(double); ///<等待一定时间(单位:秒)
+}//namespace hgl
+
+#endif//HGL_TIME_INCLUDE
diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h
new file mode 100644
index 0000000..aa12ea3
--- /dev/null
+++ b/inc/hgl/TypeFunc.h
@@ -0,0 +1,655 @@
+#ifndef HGL_TYPE_FUNC_INCLUDE
+#define HGL_TYPE_FUNC_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ #define HGL_CONVER_TO_MEM_ALIGN(x) ((((x)+HGL_MEM_ALIGN-1)/HGL_MEM_ALIGN)*HGL_MEM_ALIGN) //内存对齐转换宏
+
+ #ifndef NULL
+ #define NULL 0
+ #endif//
+
+ template
+ inline T *zero_new(const int count)
+ {
+ T *result=new T[count];
+
+ if(!result)
+ return(nullptr);
+
+ memset(result,0,count*sizeof(T));
+ return result;
+ }
+
+ template
+ inline T *zero_malloc(const int count)
+ {
+ T *result=hgl_malloc(count*sizeof(T));
+
+ if(!result)
+ return(nullptr);
+
+ memset(result,0,count*sizeof(T));
+ return result;
+ }
+
+ template
+ inline void hgl_call_construct(T *obj) //呼叫构造函数
+ {
+ new (static_cast(obj)) T();
+ }
+
+ #define HGL_BIT(n) (1<<(n))
+ #define HGL_64BIT(n) (1L<<(n))
+
+ template
+ inline bool hgl_is_one(const T value,int off)
+ {
+ return value&(1<
+ inline bool hgl_is_zero(const T value,int off)
+ {
+ return !(value&(1<
+ inline void hgl_set_one(T &value,int off)
+ {
+ value|=(1<
+ inline void hgl_set_zero(T &value,int off)
+ {
+ value&=~T(1<
+ inline void hgl_set_bit(T &value,int off,bool b)
+ {
+ if(b)
+ hgl_set_one(value,off);
+ else
+ hgl_set_zero(value,off);
+ }
+
+ template
+ inline int hgl_bit_count(const T value)
+ {
+ int count=0;
+ T bit=1;
+
+ for(int i=0;i
+ inline int hgl_bit_count(const T value,int size)
+ {
+ int count=0;
+ T bit=1;
+
+ for(int i=0;i T HGL_INTEGER_MAX();
+ template T HGL_INTEGER_MIN();
+
+ template<> inline uint8 HGL_INTEGER_MAX() { return HGL_U8_MAX; }
+ template<> inline uint16 HGL_INTEGER_MAX() { return HGL_U16_MAX; }
+ template<> inline uint32 HGL_INTEGER_MAX() { return HGL_U32_MAX; }
+ template<> inline uint64 HGL_INTEGER_MAX() { return HGL_U64_MAX; }
+
+ template<> inline int8 HGL_INTEGER_MAX() { return HGL_S8_MAX; }
+ template<> inline int16 HGL_INTEGER_MAX() { return HGL_S16_MAX; }
+ template<> inline int32 HGL_INTEGER_MAX() { return HGL_S32_MAX; }
+ template<> inline int64 HGL_INTEGER_MAX() { return HGL_S64_MAX; }
+
+ template<> inline int8 HGL_INTEGER_MIN() { return HGL_S8_MIN; }
+ template<> inline int16 HGL_INTEGER_MIN() { return HGL_S16_MIN; }
+ template<> inline int32 HGL_INTEGER_MIN() { return HGL_S32_MIN; }
+ template<> inline int64 HGL_INTEGER_MIN() { return HGL_S64_MIN; }
+
+ /**
+ * 星期每天枚举
+ */
+ enum WeekDay
+ {
+ weekNone=-1,
+
+ weekSunday, ///<星期天
+ weekMonday, ///<星期一
+ weekTuesday, ///<星期二
+ weekWednesday, ///<星期三
+ weekThursday, ///<星期四
+ weekFriday, ///<星期五
+ weekSaturday, ///<星期六
+
+ weekEnd
+ };
+
+ /**
+ * 月份枚举
+ */
+ enum Month
+ {
+ monthNone=0,
+
+ monthJanuary, ///<一月
+ monthFebruary, ///<二月
+ monthMarch, ///<三月
+ monthApril, ///<四月
+ monthMay, ///<五月
+ monthJune, ///<六月
+ monthJuly, ///<七月
+ monthAugust, ///<八月
+ monthSeptember, ///<九月
+ monthOctober, ///<十月
+ monthNovember, ///<十一月
+ monthDecember, ///<十二月
+
+ monthEnd
+ };
+
+ constexpr uint HGL_TIME_ONE_SECOND =1;
+ constexpr uint HGL_TIME_HALF_MINUTE =30;
+ constexpr uint HGL_TIME_ONE_MINUTE =60;
+ constexpr uint HGL_TIME_HALF_HOUR =30*HGL_TIME_ONE_MINUTE;
+ constexpr uint HGL_TIME_ONE_HOUR =60*HGL_TIME_ONE_MINUTE;
+ constexpr uint HGL_TIME_HALF_DAY =12*HGL_TIME_ONE_HOUR;
+ constexpr uint HGL_TIME_ONE_DAY =24*HGL_TIME_ONE_HOUR;
+ constexpr uint HGL_TIME_ONE_WEEK =7*HGL_TIME_ONE_DAY;
+ constexpr uint HGL_TIME_ONE_YEAR =365*HGL_TIME_ONE_DAY;
+
+ constexpr uint HGL_HOUR_HALF_DAY =12;
+ constexpr uint HGL_HOUR_ONE_DAY =24;
+
+ constexpr uint HGL_DAY_ONE_WEEK =7;
+ constexpr uint HGL_DAY_ONE_YEAR =365;
+
+ constexpr uint HGL_MONTH_ONE_YEAR =12;
+
+ constexpr uint HGL_MILLI_SEC_PRE_SEC =1000; //毫秒
+ constexpr uint HGL_MICRO_SEC_PER_SEC =1000*1000; //微秒
+ constexpr uint HGL_NANO_SEC_PER_SEC =1000*1000*1000; //纳秒
+
+ constexpr char LowerHexChar[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; ///<小写16进制字符
+ constexpr char UpperHexChar[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; ///<大写16进制字符
+
+ constexpr double HGL_E =2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274; //欧拉数(自然对数的底数)
+ constexpr double HGL_LOG2E =1.44269504088896340736;
+ constexpr double HGL_LOG10E =0.434294481903251827651;
+ constexpr double HGL_LN2 =0.693147180559945309417;
+ constexpr double HGL_LN10 =2.30258509299404568402;
+ constexpr double HGL_PI =3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068;
+ constexpr double HGL_PI_2 =1.57079632679489661923;
+ constexpr double HGL_PI_4 =0.785398163397448309616;
+ constexpr double HGL_PI_3_4 =2.356194490192344928938;
+ constexpr double HGL_1_PI =0.318309886183790671538;
+ constexpr double HGL_2_PI =0.636619772367581343076;
+ constexpr double HGL_2_SQRTPI =1.12837916709551257390;
+ constexpr double HGL_SQRT2 =1.41421356237309504880168872420969807;
+ constexpr double HGL_SQRT1_2 =0.707106781186547524401;
+
+ constexpr double HGL_COS_ANG_0 =1;
+ constexpr double HGL_COS_ANG_45 =0.707106781187;
+ constexpr double HGL_COS_ANG_90 =0;
+ constexpr double HGL_COS_ANG_135=-0.707106781187;
+ constexpr double HGL_COS_ANG_180=-1;
+ constexpr double HGL_COS_ANG_225=-0.707106781187;
+ constexpr double HGL_COS_ANG_270=0;
+ constexpr double HGL_COS_ANG_315=0.707106781187;
+
+ #define HGL_DEF_ANG2RAD(ang) constexpr double HGL_RAD_##ang=double(ang)*(HGL_PI/180.0f);
+
+ HGL_DEF_ANG2RAD(0)
+ HGL_DEF_ANG2RAD(45)
+ HGL_DEF_ANG2RAD(90)
+ HGL_DEF_ANG2RAD(135)
+ HGL_DEF_ANG2RAD(180)
+ HGL_DEF_ANG2RAD(225)
+ HGL_DEF_ANG2RAD(270)
+ HGL_DEF_ANG2RAD(315)
+
+ #undef HGL_DEF_ANG2RAD
+
+ constexpr double HGL_GOLDEN_RATIO =0.61803398874989484820458683436563811772030917980576;//黄金比例
+ constexpr double HGL_SILVER_RATIO =2.4142135623730950488; //白银比例
+
+ constexpr double HGL_SPEED_OF_SOUND =331.3f; //音速(米/秒)
+ constexpr double HGL_SPEED_OF_LIGHT =299792458; //光速(米/秒)
+
+ constexpr double HGL_ABSOLUTE_ZERO =-273.15f; //绝对零度
+
+ constexpr double HGL_UNIVERSAL_GRAVITATION =6.67384e-11; //万有引力常数
+
+ constexpr double HGL_EARTH_GRAVITATIONAL_ACCELERATION =9.80665; //地球上的重力加速度(牛顿)
+ constexpr double HGL_EARTH_MASS =5.9722e+24; //地球质量
+ constexpr double HGL_EARTH_RADIUS =6371000; //地球半径(米)
+
+ /**
+ * 物体万有引力计算
+ * @param m1 星球质量
+ * @param m2 物体质量
+ * @param length 到星球中心的距离
+ */
+ template
+ inline T UniversalGravitation(const T m1,const T m2,const T length)
+ {
+ return HGL_UNIVERSAL_GRAVITATION*((m1*m2)/(length*length));
+ }
+
+ /**
+ * 星球重力加速度计算
+ * 理论上: (地球质量*万有引力常数)/(地球半径的平方)=地球上的重力加速度
+ * @param m 星球质量
+ * @param raidus 星球半径
+ * @return 星球的重力加速度(牛顿)
+ */
+ template
+ inline T UniversalGravitation(const T m,const T radius)
+ {
+ return (HGL_UNIVERSAL_GRAVITATION*m)/(radius*radius);
+ }
+
+ /**
+ * 向心力计算
+ * @param m 质量
+ * @param v 速度
+ * @param r 距离
+ */
+ template
+ inline T CentripetalForce(const T m,const T v,const T r)
+ {
+ return (m*v*v)/r;
+ }
+
+ /**
+ * 加速度计算
+ * @param power 推力
+ * @param weight 质量
+ */
+ template
+ inline T AddSpeed(const T &power,const T &weight)
+ {
+ return power/weight;
+ }
+
+ /**
+ * 物体运动质量计算(物体运动越快,质量越大)
+ * @param m0 静止质量
+ * @param v 运动速度
+ */
+ template
+ inline T RunWeight(const T &m0,const T &v)
+ {
+ return m0/sqrt(1-(v*v)/(HGL_SPEED_OF_LIGHT*HGL_SPEED_OF_LIGHT));
+ }
+
+ inline float half_to_float(const uint16 &h)
+ {
+ return ((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13);
+ }
+
+ inline uint16 float_to_half(const float &f)
+ {
+ const uint32 x = *((uint32 *)&f);
+
+ return ((x>>16)&0x8000)|((((x&0x7f800000)-0x38000000)>>13)&0x7c00)|((x>>13)&0x03ff);
+ }
+
+ /**
+ * 正圆面积计算
+ * @param radius 半径
+ */
+ inline double CircleArea(const double radius)
+ {
+ return(radius*radius*HGL_PI);
+ }
+
+ /**
+ * 椭圆面积计算
+ * @param l_radius 长半径
+ * @param s_radius 短半径
+ */
+ inline double ElipseArea(const double l_radius,const double s_radius)
+ {
+ return(l_radius*s_radius*HGL_PI);
+ }
+
+ /**
+ * 球体积计算
+ * @param radius 球半径
+ */
+ inline double SphereVolume(const double radius)
+ {
+ return(radius*radius*radius*(HGL_PI*4.0f))/3.0f;
+ }
+
+ /**
+ * 椭球体积计算
+ * @param x_radius x半径
+ * @param y_radius y半径
+ * @param z_radius z半径
+ */
+ inline double EllipsoidVolume(const double x_radius,const double y_radius,const double z_radius)
+ {
+ return(x_radius*y_radius*z_radius*(HGL_PI*4.0f))/3.0f;
+ }
+
+ /**
+ * 取适合正巧大于当前数的2次幂值
+ */
+ template
+ inline T power_to_2(T value)
+ {
+ T result=1;
+
+ while(result inline void hgl_swap(T &x,T &y)
+ {
+ T t;
+
+ memcpy(&t,&x,sizeof(T));
+ memcpy(&x,&y,sizeof(T));
+ memcpy(&y,&t,sizeof(T));
+ }
+
+ template T hgl_clamp(const T &cur,const T &min_value,const T &max_value)
+ {
+ if(curmax_value)return max_value;
+
+ return cur;
+ }
+
+ template inline T hgl_abs(const T &v){return (v>=0?v:-v);}
+
+ template inline T hgl_min(const T &a,const T &b){return (a>b?b:a);}
+ template inline T hgl_max(const T &a,const T &b){return (a>b?a:b);}
+
+ template inline T hgl_min(const T *data,int count,T min_value)
+ {
+ T value=min_value;
+
+ for(int i=0;i inline T hgl_max(const T *data,int count,T max_value)
+ {
+ T value=max_value;
+
+ for(int i=0;ivalue)
+ value=*data;
+
+ ++data;
+ }
+
+ return(value);
+ }
+
+ /**
+ * 角度转弧度
+ */
+ inline double hgl_ang2rad(const double ang)
+ {
+ return ang*(HGL_PI/180.0f);
+ }
+
+ /**
+ * 弧度转角度
+ */
+ inline double hgl_rad2ang(const double rad)
+ {
+ return rad*(180.0f/HGL_PI);
+ }
+
+ /**
+ * 浮点数截取小数点后指定位度
+ * @param value 要截取的浮点数
+ * @param num 要截取的位数
+ */
+ template
+ inline T hgl_clip_float(const T value,const int num)
+ {
+ if(num<=0)
+ return int64(value);
+
+ if(value==0)return(0);
+
+ double per=pow(10,num);
+
+ return double(floor(value*per))/per;
+ }
+
+ /**
+ * 等值类型复制
+ */
+ template
+ inline void hgl_cpy(T &dst,const T &src)
+ {
+ memcpy(&dst,&src,sizeof(T));
+ }
+
+ /**
+ * 不同类型数据块复制
+ */
+ template
+ inline void hgl_cpy(D *dst,const S *src,const size_t count)
+ {
+ for(size_t i=0;i
+ inline void hgl_typecpy(T *dst,const T *src,const size_t count)
+ {
+ memcpy(dst,src,count*sizeof(T));
+ }
+
+ /**
+ * 同类型数据块移动
+ */
+ template
+ inline void hgl_typemove(T *dst,const T *src,const size_t count)
+ {
+ memmove(dst,src,count*sizeof(T));
+ }
+
+ /**
+ * 指定类型数据块赋值
+ */
+ template
+ inline void hgl_set(T *data,const T value,const size_t count)
+ {
+ for(size_t i=0;i
+ inline void hgl_zero(T *data,const size_t count)
+ {
+ memset(data,0,count*sizeof(T));
+ }
+
+ /**
+ * 分配指定类型数据块并清0
+ */
+ template
+ inline T *hgl_zero_new(const size_t count)
+ {
+ if(count<=0)return(nullptr);
+
+ T *data=new T[count];
+ memset(data,0,count*sizeof(T));
+ return data;
+ }
+
+ template
+ inline T *hgl_copy_new(const size_t count,const T *src)
+ {
+ if(count<=0)return(nullptr);
+
+ T *data=new T[count];
+ memcpy(data,src,count*sizeof(T));
+ return data;
+ }
+
+ /**
+ * 指定类型数据清0
+ */
+ template
+ inline void hgl_zero(T &data)
+ {
+ memset(&data,0,sizeof(T));
+ }
+}//namespace hgl
+
+/**
+* 比较处理模板基类
+*/
+template class Comparator ///比较处理模板基类
+{
+public:
+
+ /**
+ * 比较函数,需被特例化或派生实现
+ */
+ virtual int compare(const T &a,const T &b)const
+ {
+ return 0; // 如 return(a-b); ,但这个函数正确情况下不应该会被调用
+ }
+
+ /**
+ * 交换函数
+ */
+ virtual void exchange(T &a,T &b)
+ {
+ T t;
+
+ memcpy(&t,&a,sizeof(T));
+ memcpy(&a,&b,sizeof(T));
+ memcpy(&b,&t,sizeof(T));
+ }
+
+ /**
+ * 复制数据
+ */
+ virtual void cpy(T *t,T *s)
+ {
+ memcpy(t,s,sizeof(T));
+ }
+};//class Comparator
+
+//针对原生类型的特例化版本,做适当加速
+#define COMPARATOR_ORIGIN_TYPE(type) template<> class Comparator \
+ { \
+ public: \
+ int compare(const type &a,const type &b)const{return a-b;} \
+ void exchange(type &a,type &b){type t;t=a;a=b;b=t;} \
+ void cpy(type *t,type *s){*t=*s;} \
+ };
+
+ COMPARATOR_ORIGIN_TYPE(hgl::int8)
+ COMPARATOR_ORIGIN_TYPE(hgl::int16)
+ COMPARATOR_ORIGIN_TYPE(hgl::int32)
+ COMPARATOR_ORIGIN_TYPE(hgl::int64)
+
+ COMPARATOR_ORIGIN_TYPE(hgl::uint8)
+ COMPARATOR_ORIGIN_TYPE(hgl::uint16)
+ COMPARATOR_ORIGIN_TYPE(hgl::uint32)
+ COMPARATOR_ORIGIN_TYPE(hgl::uint64)
+
+ COMPARATOR_ORIGIN_TYPE(float)
+ COMPARATOR_ORIGIN_TYPE(double)
+
+ COMPARATOR_ORIGIN_TYPE(char)
+ COMPARATOR_ORIGIN_TYPE(wchar_t)
+
+#if HGL_OS != HGL_OS_Windows
+ COMPARATOR_ORIGIN_TYPE(u16char)
+#endif//HGL_OS != HGL_OS_Windows
+
+ COMPARATOR_ORIGIN_TYPE(char32_t)
+#undef COMPARATOR_ORIGIN_TYPE
+#endif//HGL_TYPE_FUNC_INCLUDE
diff --git a/inc/hgl/filesystem/AssetManage.h b/inc/hgl/filesystem/AssetManage.h
new file mode 100644
index 0000000..fa6f626
--- /dev/null
+++ b/inc/hgl/filesystem/AssetManage.h
@@ -0,0 +1,9 @@
+#ifndef HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE
+#define HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE
+
+#include
+namespace hgl
+{
+
+}//namespace hgl
+#endif//HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE
diff --git a/inc/hgl/filesystem/EnumFile.h b/inc/hgl/filesystem/EnumFile.h
new file mode 100644
index 0000000..5108996
--- /dev/null
+++ b/inc/hgl/filesystem/EnumFile.h
@@ -0,0 +1,75 @@
+#include
+
+namespace hgl
+{
+ namespace filesystem
+ {
+ struct EnumFileConfig
+ {
+ OSString folder_name; ///<要枚举的目录名称
+
+#if HGL_OS == HGL_OS_Windows ///<通配符过滤是Windows平台独有
+ OSString find_name; ///<要枚举的文件名称
+#endif//HGL_OS == HGL_OS_Windows
+
+ bool proc_folder; ///<是否处理目录
+ bool proc_file; ///<是否处理文件
+ bool sub_folder; ///<是否查找子目录
+
+ public:
+
+ EnumFileConfig(const OSString &fn)
+ {
+ folder_name=fn;
+
+#if HGL_OS == HGL_OS_Windows
+ find_name=OS_TEXT("*.*");
+#endif//HGL_OS == HGL_OS_Windows
+
+ proc_folder=true;
+ proc_file=true;
+ sub_folder=false;
+ }
+
+ EnumFileConfig(const EnumFileConfig *efc,const OSString &sub_folder_name)
+ {
+ folder_name =sub_folder_name;
+
+#if HGL_OS == HGL_OS_Windows
+ find_name =efc->find_name;
+#endif//HGL_OS == HGL_OS_Windows
+
+ proc_folder =efc->proc_folder;
+ proc_file =efc->proc_file;
+ sub_folder =efc->sub_folder;
+ }
+
+ virtual ~EnumFileConfig()=default;
+ };//struct EnumFileConfig
+
+ /**
+ * 枚举文件系统内的文件
+ */
+ class EnumFile
+ {
+ protected:
+
+ virtual void ProcFolder(struct EnumFileConfig *parent_efc,struct EnumFileConfig *cur_efc,FileInfo &fi){}
+ virtual void ProcFile(struct EnumFileConfig *,FileInfo &fi){}
+
+ virtual EnumFileConfig *CreateSubConfig(struct EnumFileConfig *up_efc,const FileInfo &fi)
+ {
+ const OSString full_sub_folder_name=MergeFilename(up_efc->folder_name,fi.name);
+
+ return(new EnumFileConfig(up_efc,full_sub_folder_name));
+ }
+
+ public:
+
+ EnumFile()=default;
+ virtual ~EnumFile()=default;
+
+ virtual int Enum(EnumFileConfig *);
+ };//class EnumFile
+ }//namespace filesystem
+}//namespace hgl
diff --git a/inc/hgl/filesystem/EnumVolume.h b/inc/hgl/filesystem/EnumVolume.h
new file mode 100644
index 0000000..47e7a10
--- /dev/null
+++ b/inc/hgl/filesystem/EnumVolume.h
@@ -0,0 +1,99 @@
+#pragma once
+
+#include
+
+namespace hgl
+{
+ namespace filesystem
+ {
+ /**
+ * 卷信息数据结构
+ */
+ struct VolumeInfo
+ {
+ enum DriverType
+ {
+ dtNone=0, ///<未知类型
+
+ dtRemovable, ///<可移动设备
+ dtFixed, ///<固定设备
+ dtRemote, ///<远程设备
+ dtCDROM, ///<光盘驱动器
+ dtRamDisk, ///<内存虚拟设备
+
+ dtEnd ///<结束定义
+ };
+
+ u16char name[HGL_MAX_PATH]; ///<卷名称
+
+ u16char path[HGL_MAX_PATH]; ///<卷所对应的路径名(注意:不是所有卷都有对应路径)
+
+ DriverType driver_type; ///<驱动器类型(注意:不是所有的卷都对应驱动器)
+
+ uint32 serial; ///<卷序列号
+
+ u16char volume_label[HGL_MAX_PATH]; ///<卷标名称
+
+ u16char file_system[HGL_MAX_PATH]; ///<文件系统名称
+
+ uint32 filename_max_length; ///<文件名最大长度
+
+ bool unicode; ///<文件名支持UNICODE
+
+ uint64 available_space; ///<有效容量
+ uint64 total_space; ///<总空量
+ uint64 free_space; ///<自由容量
+ };//struct VolumeInfo
+
+#if HGL_OS == HGL_OS_Windows
+
+ /**
+ * 卷检测配置
+ */
+ struct VolumeCheckConfig
+ {
+ bool removable =false;
+ bool fixed =false;
+ bool remote =false;
+ bool cdrom =false;
+ bool ram_disk =false;
+ bool unknow =false;
+
+ public:
+
+ /**
+ * 设置为全部检测
+ */
+ void SetFullCheck()
+ {
+ memset(this,0xff,sizeof(VolumeCheckConfig));
+ }
+
+ /**
+ * 是否无效配置
+ */
+ bool isErrorConfig()const
+ {
+ if(removable)return(false);
+ if(fixed)return(false);
+ if(remote)return(false);
+ if(cdrom)return(false);
+ if(ram_disk)return(false);
+ if(unknow)return(false);
+
+ return(true);
+ }
+ };
+
+ /**
+ * 枚举当前计算机所有卷
+ * @param vi_list 储存卷信息的列表
+ * @param check_removable 检测可移除设备
+ * @param check_remote 检测远程驱动器
+ * @param check_cd 检测光盘
+ * @return 查找到的卷数量,-1表示失败
+ */
+ int EnumVolume(List &vi_list,const VolumeCheckConfig &);
+#endif//HGL_OS == HGL_OS_Windows
+ }//namespace filesystem
+}//namespace hgl
\ No newline at end of file
diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h
new file mode 100644
index 0000000..c3b831e
--- /dev/null
+++ b/inc/hgl/filesystem/FileSystem.h
@@ -0,0 +1,229 @@
+#ifndef HGL_FILE_SYSTEM_INCLUDE
+#define HGL_FILE_SYSTEM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class InputStream;
+ }//namespace io
+
+ namespace filesystem
+ {
+ template
+ inline BaseString MergeFilename(const BaseString &pathname,const BaseString &filename,const T directory_separator_char,const T *directory_separator_str)
+ {
+ BaseString fullname;
+
+ if(pathname.GetEndChar()==directory_separator_char) //结尾有分隔符
+ {
+ if(filename.GetBeginChar()==directory_separator_char) //开头有分隔符
+ {
+ fullname.Set(pathname.c_str(),pathname.Length()-1); //少取一个字符
+ }
+ else
+ {
+ fullname=pathname;
+ }
+ }
+ else //结尾没有分隔符
+ {
+ fullname=pathname;
+
+ if(filename.GetBeginChar()!=directory_separator_char) //开头没有分隔符
+ {
+ fullname.Strcat(directory_separator_str); //添加分隔符
+ }
+ }
+
+ fullname.Strcat(filename);
+ return fullname;
+ }
+
+ /**
+ * 截取完整路径中的文件名
+ * @param fullname 完整路径文件名
+ */
+ template
+ inline BaseString ClipFilename(const BaseString &fullname)
+ {
+ if(fullname.Length()<=1)
+ return(BaseString());
+
+ const T spear_char[] = { '/','\\' };
+
+ const int pos=fullname.FindRightChar(spear_char);
+
+ if(pos==-1)
+ return BaseString(fullname);
+
+ return fullname.SubString(pos+1);
+ }
+
+ /**
+ * 截取一个文件名中的主名称(不能带路径)
+ * @param filename 文件名
+ * @param split_char 扩展名分隔符,一般为'.'
+ */
+ template
+ inline BaseString ClipFileMainname(const BaseString &filename,const T split_char='.')
+ {
+ if(filename.Length()<=1)
+ return(BaseString());
+
+ const int pos=filename.FindRightChar(split_char);
+
+ if(pos==-1)
+ return BaseString(filename);
+
+ return filename.SubString(0,pos);
+ }
+
+ /**
+ * 截取完整文件名中的扩展名
+ * @param fullname 完整文件名
+ * @param include_dot 是否包括点
+ */
+ template
+ inline BaseString ClipFileExtName(const BaseString &fullname,bool include_dot=true)
+ {
+ int end=fullname.FindChar(T('?')); //url的文件名,以?为结束
+
+ if(end==-1)
+ end=fullname.Length();
+
+ int pos=fullname.FindRightChar(fullname.Length()-end,T('.'));
+
+ if(pos==-1)
+ return BaseString();
+
+ return include_dot? fullname.SubString(pos, end- pos ):
+ fullname.SubString(pos+1, end-(pos+1));
+ }
+
+ /**
+ * 截取路径最后一个名字
+ */
+ template
+ inline BaseString ClipLastPathname(const BaseString &fullname)
+ {
+ if(fullname.Length()<=1)
+ return(BaseString());
+
+ const T gap_char[2]={'\\','/'};
+
+ T *p=nullptr;
+
+ T *s=fullname.c_str();
+ T *e=fullname.c_str()+fullname.Length()-1;
+
+ while(e>s)
+ {
+ if(!p)
+ {
+ if(*e==gap_char[0]||*e==gap_char[1])
+ {
+ --e;
+ continue;
+ }
+
+ p=e;
+ --e;
+ }
+ else
+ {
+ if(*e==gap_char[0]||*e==gap_char[1])
+ {
+ return BaseString(e+1,p-e);
+ }
+
+ --e;
+ }
+ }
+
+ return(BaseString());
+ }
+
+ inline UTF8String MergeFilename(const UTF8String &pathname,const UTF8String &filename) ///<组合路径名与文件名
+ {return MergeFilename(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);}
+
+ inline WideString MergeFilename(const WideString &pathname,const WideString &filename) ///<组合路径名与文件名
+ {return MergeFilename(pathname,filename,L'\\',L"\\");}
+
+ bool FileCopy(const OSString &,const OSString &); ///<文件复制
+ bool FileDelete(const OSString &); ///<文件删除
+ bool FileMove(const OSString &,const OSString &); ///<文件移动
+ bool FileRename(const OSString &,const OSString &); ///<文件改名
+ bool FileExist(const OSString &); ///<文件确认是否存在
+ bool FileComp(const OSString &,const OSString &); ///<文件比较
+
+ bool FileCanRead(const OSString &); ///<检测文件是否可读
+ bool FileCanWrite(const OSString &); ///<检测文件是否可写
+ bool FileCanExec(const OSString &); ///<检测文件是否可执行
+
+ int64 LoadFileToMemory(const OSString &,void **); ///<加载一个文件到内存
+ int64 SaveMemoryToFile(const OSString &,const void *,const int64 &); ///<保存一块内存成文件
+ int64 SaveMemoryToFile(const OSString &,void **,const int64 *,const int &); ///<保存多块内存成一个文件
+
+ void *LoadFileToMemory(const OSString &,int64,void *buf,int64); ///<加载一个文件的一部分到内存
+ bool SaveMemoryToFile(const OSString &,int64,const void *,int64); ///<保存一块内存到一个文件
+
+ bool IsDirectory(const os_char *);
+ inline bool IsDirectory(const OSString &str){return IsDirectory(str.c_str());} ///<判断这个名称是否是目录
+
+#if HGL_OS != HGL_OS_Windows
+ bool IsLink(const os_char *); ///<判断这个名称是否是链接
+#endif//
+
+ bool MakePath(const OSString &); ///<创建一个路径
+ bool DeletePath(const OSString &); ///<删除一个路径
+ void DeleteTree(const OSString &); ///<删除一个路径(包含所有文件)
+
+ bool GetCurrentPath(OSString &); ///<取得当前路径
+ bool GetCurrentProgram(OSString &); ///<取得当前程序全路径名称
+ bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
+ void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]); ///<取得当前用户应用程序数据存放路径
+
+ //使用int64而不是__int64是因为不是所有编译器都支持__int64的写法,必须使用DataType.H中引入的定义
+
+ /**
+ * 文件信息数据结构
+ */
+ struct FileInfo ///文件信息
+ {
+ os_char name[HGL_MAX_PATH]; ///<文件名(不包含路径)
+ os_char fullname[HGL_MAX_PATH]; ///<完整名称(包含路径)
+
+ uint64 size; ///<文件长度
+
+ union
+ {
+ uint32 attrib; ///<文件属性
+
+ struct
+ {
+ bool is_file:1; ///<是文件
+ bool is_directory:1; ///<是目录
+
+ bool is_hiddle:1; ///<是否隐藏文件
+
+#if HGL_OS != HGL_OS_Windows
+ bool is_link:1; ///<是否是链接
+#endif//HGL_OS != HGL_OS_Windows
+
+ bool can_read:1; ///<可以读
+ bool can_write:1; ///<可以写
+ };
+ };
+
+ uint64 mtime; ///<最后修改日期(这个值在win/unix下不通用)
+ };//struct FileInfo
+
+ bool GetFileInfo(const os_char *filename,struct FileInfo &); ///<取得文件信息
+
+ int GetFileInfoList(List &, const OSString &folder_name, bool proc_folder, bool proc_file, bool sub_folder);
+ }//namespace filesystem
+}//namespace hgl
+#endif//HGL_FILE_SYSTEM_INCLUDE
diff --git a/inc/hgl/io/DataInputStream.h b/inc/hgl/io/DataInputStream.h
new file mode 100644
index 0000000..2708438
--- /dev/null
+++ b/inc/hgl/io/DataInputStream.h
@@ -0,0 +1,231 @@
+#ifndef HGL_IO_DATA_INPUT_STREAM_INCLUDE
+#define HGL_IO_DATA_INPUT_STREAM_INCLUDE
+
+#include
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class InputStream;
+
+ /**
+ * 格式数据输入流基类
+ */
+ class DataInputStream ///格式数据输入流基类
+ {
+ protected:
+
+ InputStream *in;
+
+ public:
+
+ DataInputStream(InputStream *is)
+ {
+ in=is;
+ }
+
+ virtual ~DataInputStream()
+ {
+ }
+
+ virtual void Use(InputStream *is)
+ {
+ in=is;
+ }
+
+ virtual int64 Read(void *buf,int64 size)
+ {
+ if(!buf||size<0)return(-1);
+
+ return(in?in->Read(buf,size):-1);
+ }
+
+ virtual int64 Peek(void *buf,int64 size)
+ {
+ if(!buf||size<0)return(-1);
+
+ return(in?in->Peek(buf,size):-1);
+ }
+
+ virtual int64 ReadFully(void *buf,int64 size)
+ {
+ if(!buf||size<0)return(-1);
+
+ return(in?in->ReadFully(buf,size):-1);
+ }
+
+ virtual int64 Seek(int64 offset,SeekOrigin so=SeekOrigin::Begin)
+ {
+ return(in?in->Seek(offset,so):-1);
+ }
+
+ virtual int64 Skip(int64 size) ///<跳过指定字节不访问
+ {
+ return(in?in->Skip(size):-1);
+ }
+
+ virtual bool CanRestart ()const{return in?in->CanRestart():false;} ///<是否可以复位
+ virtual bool CanSeek ()const{return in?in->CanSeek ():false;} ///<是否可以定位
+ virtual bool CanSize ()const{return in?in->CanSize ():false;} ///<是否可以取得尺寸
+ virtual bool CanPeek ()const{return in?in->CanPeek ():false;} ///<是否可以预览数据
+
+ virtual bool Restart ()const{return in?in->Restart ():false;} ///<复位访问指针
+ virtual int64 Tell ()const{return in?in->Tell ():-1;} ///<返回当前访问位置
+ virtual int64 GetSize ()const{return in?in->GetSize ():-1;} ///<取得流长度
+ virtual int64 Available ()const{return in?in->Available ():-1;} ///<剩下的可以不受阻塞读取的字节数
+
+ template bool ReadNumber(T &value);
+
+ #define STREAM_READ(type,name) virtual bool Read##name(type &value) \
+ { \
+ return Read(value); \
+ } \
+ \
+ virtual int64 Read##name(type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ return ReadArrays(data,count); \
+ }
+
+ STREAM_READ(char, Char );
+ STREAM_READ(bool, Bool );
+ STREAM_READ(int8, Int8 );
+ STREAM_READ(uint8, Uint8 );
+
+ #undef STREAM_READ
+
+ #define STREAM_READ(type,name) virtual bool Read##name(type &)=0; \
+ virtual int64 Read##name(type *,const int64)=0;
+
+ STREAM_READ(int16, Int16 );
+ STREAM_READ(int32, Int32 );
+ STREAM_READ(int64, Int64 );
+
+ STREAM_READ(uint16, Uint16 );
+ STREAM_READ(uint32, Uint32 );
+ STREAM_READ(uint64, Uint64 );
+
+ STREAM_READ(u16char, UTF16Char);
+ STREAM_READ(float, Float );
+ STREAM_READ(double, Double );
+
+ #undef STREAM_READ
+
+ bool Read(Vector2f &vec){return ReadFloat((float *)&vec,2)==2;}
+ bool Read(Vector3f &vec){return ReadFloat((float *)&vec,3)==3;}
+ bool Read(Vector4f &vec){return ReadFloat((float *)&vec,4)==4;}
+
+ /**
+ * 自适应类型数据读取
+ * 请在多平台混用的情况下不要使用此函数,以免造成不同平台数据实质结构不一致的情况
+ */
+ template bool Read(T &data)
+ {
+ return(ReadFully(&data,sizeof(T))==sizeof(T));
+ }
+
+ /**
+ * 自适应类型数据阵列读取
+ * 请在多平台混用的情况下不要使用此函数,以免造成不同平台数据实质结构不一致的情况
+ * @param data 数据存放区
+ * @param count 数据个数
+ * @return 实质读入的数据个数
+ * @return <0 出错
+ */
+ template int64 ReadArrays(T *data,int64 count)
+ {
+ if(count<=0)return(count);
+ if(!data)return(-1);
+
+ return ReadFully(data,count*sizeof(T))/sizeof(T);
+ }
+
+ /**
+ * 自定义类型数据阵列读取
+ * 请在多平台混用的情况下不要使用此函数,以免造成不同平台数据实质结构不一致的情况
+ * @param count 数据个数
+ * @param alloc_count 分配数据个数(默认-1)
+ * @return 实质读入的数据指针,请使用delete[]释放
+ * @return NULL 出错
+ */
+ template T *ReadArrays(int64 count)
+ {
+ if(count<=0)return(nullptr);
+
+ T *data=new T[count];
+
+ if(data==0)
+ return(nullptr);
+
+ if(ReadArrays(data,count)!=count)
+ {
+ delete[] data;
+ return(nullptr);
+ }
+
+ return data;
+ }
+
+ virtual bool ReadUTF16LEChars(u16char *,uint); ///<读取utf16-le格式字符阵列到u16char *
+ virtual bool ReadUTF16BEChars(u16char *,uint); ///<读取utf16-be格式字符阵列到u16char *
+
+ //32bit str-length
+ virtual bool ReadUTF8String (char *, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF8String (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF8String (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+
+ virtual bool ReadUTF16LEString (u16char *, uint max_len=0);
+ virtual bool ReadUTF16BEString (u16char *, uint max_len=0);
+
+ virtual bool ReadUTF16LEString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF16BEString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
+
+ //16bit str-length
+ virtual bool ReadUTF8ShortString (char *, uint max_len=0);
+ virtual bool ReadUTF8ShortString (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF8ShortString (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+
+ virtual bool ReadUTF16LEShortString (u16char *, uint max_len=0);
+ virtual bool ReadUTF16BEShortString (u16char *, uint max_len=0);
+
+ virtual bool ReadUTF16LEShortString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF16BEShortString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
+
+ //8bit str-length
+ virtual bool ReadUTF8TinyString (char *, uint max_len=0);
+ virtual bool ReadUTF8TinyString (UTF8String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF8TinyString (UTF16String &, uint max_len=0); ///<读取utf8格式字符串(前缀四字节的字符串字节长度)
+
+ virtual bool ReadUTF16LETinyString (u16char *, uint max_len=0);
+ virtual bool ReadUTF16BETinyString (u16char *, uint max_len=0);
+
+ virtual bool ReadUTF16LETinyString (UTF16String &, uint max_len=0); ///<读取utf16-le格式字符串(前缀四字节的字符串字节长度)
+ virtual bool ReadUTF16BETinyString (UTF16String &, uint max_len=0); ///<读取utf16-be格式字符串(前缀四字节的字符串字节长度)
+ };//class DataInputStream
+
+ template<> bool inline DataInputStream::ReadNumber(int8 &value){return ReadInt8(value);}
+ template<> bool inline DataInputStream::ReadNumber(uint8 &value){return ReadUint8(value);}
+
+ #define DIS_READ_NUMBER(type,name) template<> bool inline DataInputStream::ReadNumber(type &value){return Read##name(value);}
+
+ DIS_READ_NUMBER(int16, Int16 );
+ DIS_READ_NUMBER(int32, Int32 );
+ DIS_READ_NUMBER(int64, Int64 );
+
+ DIS_READ_NUMBER(uint16, Uint16 );
+ DIS_READ_NUMBER(uint32, Uint32 );
+ DIS_READ_NUMBER(uint64, Uint64 );
+
+ DIS_READ_NUMBER(u16char, UTF16Char);
+ DIS_READ_NUMBER(float, Float );
+ DIS_READ_NUMBER(double, Double );
+
+ #undef DIS_READ_NUMBER
+ }//namespace io
+}//namespace hgl
+#include
+#endif//HGL_IO_DATA_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/DataOutputStream.h b/inc/hgl/io/DataOutputStream.h
new file mode 100644
index 0000000..e1e7d29
--- /dev/null
+++ b/inc/hgl/io/DataOutputStream.h
@@ -0,0 +1,226 @@
+#ifndef HGL_IO_DATA_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_DATA_OUTPUT_STREAM_INCLUDE
+
+#include
+#include
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class OutputStream;
+
+ /**
+ * 格式数据输出流基类
+ */
+ class DataOutputStream ///格式数据输出流基类
+ {
+ protected:
+
+ OutputStream *out;
+
+ public:
+
+ DataOutputStream(OutputStream *os)
+ {
+ out=os;
+ }
+
+ virtual ~DataOutputStream()
+ {
+ }
+
+ virtual void Use(OutputStream *os)
+ {
+ out=os;
+ }
+
+ virtual int64 Write(const void *buf,int64 size)
+ {
+ if(!buf||size<0)return(-1);
+
+ return(out?out->Write(buf,size):-1);
+ }
+
+ virtual int64 WriteFully(const void *buf,int64 size)
+ {
+ if(!buf||size<0)return(-1);
+
+ return(out?out->WriteFully(buf,size):-1);
+ }
+
+ virtual int64 Seek(int64 offset,SeekOrigin so=SeekOrigin::Begin)
+ {
+ return(out?out->Seek(offset,so):-1);
+ }
+
+ virtual bool CanRestart ()const{return out?out->CanRestart ():false;} ///<是否可以复位
+ virtual bool CanSeek ()const{return out?out->CanSeek ():false;} ///<是否可以定位
+ virtual bool CanSize ()const{return out?out->CanSize ():false;} ///<是否可以取得尺寸
+
+ virtual bool Restart ()const{return out?out->Restart ():false;} ///<复位访问指针
+ virtual int64 Tell ()const{return out?out->Tell ():-1;} ///<返回当前访问位置
+ virtual int64 GetSize ()const{return out?out->GetSize ():-1;} ///<取得流长度
+ virtual int64 Available ()const{return out?out->Available ():-1;} ///<剩下的可以不受阻塞写入的字节数
+
+ template bool WriteNumber(const T &value);
+
+ #define STREAM_WRITE(type,name) virtual bool Write##name(const type &value) \
+ { \
+ return Write(value); \
+ } \
+ \
+ virtual int64 Write##name(const type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ return WriteArrays(data,count); \
+ }
+
+ STREAM_WRITE(char, Char );
+ STREAM_WRITE(bool, Bool );
+ STREAM_WRITE(int8, Int8 );
+ STREAM_WRITE(uint8, Uint8 );
+
+ #undef STREAM_WRITE
+
+ #define STREAM_WRITE(type,name) virtual bool Write##name(const type &)=0; \
+ virtual int64 Write##name(const type *,const int64)=0;
+
+ STREAM_WRITE(int16, Int16 );
+ STREAM_WRITE(int32, Int32 );
+ STREAM_WRITE(int64, Int64 );
+
+ STREAM_WRITE(uint16, Uint16 );
+ STREAM_WRITE(uint32, Uint32 );
+ STREAM_WRITE(uint64, Uint64 );
+
+ STREAM_WRITE(u16char, UTF16Char);
+ STREAM_WRITE(float, Float );
+ STREAM_WRITE(double, Double );
+
+ #undef STREAM_WRITE
+
+ bool Write(const Vector2f &vec){return WriteFloat((float *)&vec,2)==2;}
+ bool Write(const Vector3f &vec){return WriteFloat((float *)&vec,3)==3;}
+ bool Write(const Vector4f &vec){return WriteFloat((float *)&vec,4)==4;}
+
+ /**
+ * 自适应类型数据写入
+ * 请在多平台混用的情况下不要使用此函数,以免造成不同平台数据实质结构不一致的情况
+ */
+ template bool Write(const T &data)
+ {
+ return WriteFully(&data,sizeof(T))==sizeof(T);
+ }
+
+ /**
+ * 自适应类型数据阵列写入
+ * 请在多平台混用的情况下不要使用此函数,以免造成不同平台数据实质结构不一致的情况
+ * @param data 数据
+ * @param count 数据个数
+ * @return 实质写入的数据个数
+ * @return -1 出错
+ */
+ template int64 WriteArrays(const T *data,int64 count)
+ {
+ if(count<=0)return(count);
+ if(!data)return(-1);
+
+ return WriteFully(data,count*sizeof(T))/sizeof(T);
+ }
+
+ template bool WriteUTF8Chars (const T *str,uint count); ///<按utf8格式写入字符阵列
+ template bool WriteUTF16LEChars (const T *str,uint count); ///<按utf16-le格式写入字符阵列
+ template bool WriteUTF16BEChars (const T *str,uint count); ///<按utf16-be格式写入字符阵列
+
+ template bool WriteUTF8Chars (const BaseString &str){return WriteUTF8Chars (str.c_str(),str.Length());}
+ template bool WriteUTF16LEChars (const BaseString &str){return WriteUTF16LEChars (str.c_str(),str.Length());}
+ template bool WriteUTF16BEChars (const BaseString &str){return WriteUTF16BEChars (str.c_str(),str.Length());}
+
+ template bool WriteUTF8StringWithLength (const char *str,const uint length);
+ template bool WriteUTF8StringWithLength (const UTF16String &str);
+
+ template bool WriteUTF16StringWithLength(const u16char *str,const uint len);
+
+ public:
+
+ //32 bit length
+ bool WriteUTF8String (const char *str,uint length); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF8String (const char *str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF8String (const UTF8String &str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF8String (const UTF16String &str ); ///<按utf8格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEString (const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEString (const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEString (const UTF16String &str ); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEString (const UTF16String &str ); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEString (const u16char *str ); ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEString (const u16char *str ); ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEString (const UTF8String &str ){return WriteUTF16LEString(to_u16(str));} ///<按utf16-le格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEString (const UTF8String &str ){return WriteUTF16BEString(to_u16(str));} ///<按utf16-be格式写入字符串(前置4字节字符串长度,再写入字符阵列)
+
+ //16 bit length
+ bool WriteUTF8ShortString (const char *str,uint length); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF8ShortString (const char *str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF8ShortString (const UTF8String &str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF8ShortString (const UTF16String &str ); ///<按utf8格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEShortString(const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEShortString(const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEShortString(const UTF16String &str ); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEShortString(const UTF16String &str ); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEShortString(const u16char *str ); ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEShortString(const u16char *str ); ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LEShortString(const UTF8String &str ){return WriteUTF16LEShortString(to_u16(str));} ///<按utf16-le格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BEShortString(const UTF8String &str ){return WriteUTF16BEShortString(to_u16(str));} ///<按utf16-be格式写入字符串(前置2字节字符串长度,再写入字符阵列)
+
+ //8 bit length
+ bool WriteUTF8TinyString (const char *str,uint length); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF8TinyString (const char *str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF8TinyString (const UTF8String &str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF8TinyString (const UTF16String &str ); ///<按utf8格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LETinyString (const u16char *str,uint len); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BETinyString (const u16char *str,uint len); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LETinyString (const UTF16String &str ); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BETinyString (const UTF16String &str ); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LETinyString (const u16char *str ); ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BETinyString (const u16char *str ); ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+
+ bool WriteUTF16LETinyString (const UTF8String &str ){return WriteUTF16LETinyString(to_u16(str));} ///<按utf16-le格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ bool WriteUTF16BETinyString (const UTF8String &str ){return WriteUTF16BETinyString(to_u16(str));} ///<按utf16-be格式写入字符串(前置1字节字符串长度,再写入字符阵列)
+ };//class DataOutputStream
+
+ template<> bool inline DataOutputStream::WriteNumber(const int8 &value){return WriteInt8(value);}
+ template<> bool inline DataOutputStream::WriteNumber(const uint8 &value){return WriteUint8(value);}
+
+ #define DOS_WRITE_NUMBER(type,name) template<> bool inline DataOutputStream::WriteNumber(const type &value){return Write##name(value);}
+
+ DOS_WRITE_NUMBER(int16, Int16 );
+ DOS_WRITE_NUMBER(int32, Int32 );
+ DOS_WRITE_NUMBER(int64, Int64 );
+
+ DOS_WRITE_NUMBER(uint16, Uint16 );
+ DOS_WRITE_NUMBER(uint32, Uint32 );
+ DOS_WRITE_NUMBER(uint64, Uint64 );
+
+ DOS_WRITE_NUMBER(u16char, UTF16Char);
+ DOS_WRITE_NUMBER(float, Float );
+ DOS_WRITE_NUMBER(double, Double );
+
+ #undef DOS_WRITE_NUMBER
+ }//namespace io
+}//namespace hgl
+#include
+#endif//HGL_IO_DATA_OUTPUT_STREAM_INCLUDEs
diff --git a/inc/hgl/io/EndianDataInputStream.h b/inc/hgl/io/EndianDataInputStream.h
new file mode 100644
index 0000000..433cdd1
--- /dev/null
+++ b/inc/hgl/io/EndianDataInputStream.h
@@ -0,0 +1,100 @@
+#ifndef HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE
+#define HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class DirectDataInputStream:public DataInputStream
+ {
+ public:
+
+ using DataInputStream::DataInputStream;
+ virtual ~DirectDataInputStream()=default;
+
+ #define STREAM_DIRECT_READ(type,name) virtual bool Read##name(type &value) \
+ { \
+ return Read(value); \
+ } \
+ \
+ virtual int64 Read##name(type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ return ReadArrays(data,count); \
+ }
+
+ STREAM_DIRECT_READ(int16, Int16 );
+ STREAM_DIRECT_READ(int32, Int32 );
+ STREAM_DIRECT_READ(int64, Int64 );
+
+ STREAM_DIRECT_READ(uint16, Uint16 );
+ STREAM_DIRECT_READ(uint32, Uint32 );
+ STREAM_DIRECT_READ(uint64, Uint64 );
+
+ STREAM_DIRECT_READ(u16char,UTF16Char);
+ STREAM_DIRECT_READ(float, Float );
+ STREAM_DIRECT_READ(double, Double );
+
+ #undef STREAM_DIRECT_READ
+ };//class DirectDataInputStream
+
+ class SwapDataInputStream:public DataInputStream
+ {
+ public:
+
+ using DataInputStream::DataInputStream;
+ virtual ~SwapDataInputStream()=default;
+
+ #define STREAM_SWAP_READ(type,name) virtual bool Read##name(type &value) \
+ {\
+ type swap_value; \
+ \
+ if(!Read(swap_value)) \
+ return(false); \
+ \
+ value=EndianSwap(swap_value); \
+ return(true); \
+ } \
+ \
+ virtual int64 Read##name(type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ const int64 result=ReadArrays(data,count); \
+ \
+ if(result<=0)return(result); \
+ \
+ EndianSwap(data,result); \
+ return(result); \
+ }
+
+ STREAM_SWAP_READ(int16, Int16 );
+ STREAM_SWAP_READ(int32, Int32 );
+ STREAM_SWAP_READ(int64, Int64 );
+
+ STREAM_SWAP_READ(uint16, Uint16 );
+ STREAM_SWAP_READ(uint32, Uint32 );
+ STREAM_SWAP_READ(uint64, Uint64 );
+
+ STREAM_SWAP_READ(u16char, UTF16Char);
+ STREAM_SWAP_READ(float, Float );
+ STREAM_SWAP_READ(double, Double );
+
+ #undef STREAM_SWAP_READ
+ };//class SwapDataInputStream
+
+#if HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ typedef DirectDataInputStream LEDataInputStream;
+ typedef SwapDataInputStream BEDataInputStream;
+#else
+ typedef DirectDataInputStream BEDataInputStream;
+ typedef SwapDataInputStream LEDataInputStream;
+#endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_ENDIAN_DATA_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/EndianDataOutputStream.h b/inc/hgl/io/EndianDataOutputStream.h
new file mode 100644
index 0000000..fda089e
--- /dev/null
+++ b/inc/hgl/io/EndianDataOutputStream.h
@@ -0,0 +1,103 @@
+#ifndef HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class DirectDataOutputStream:public DataOutputStream
+ {
+ public:
+
+ DirectDataOutputStream(OutputStream *os):DataOutputStream(os)
+ {
+ }
+
+ virtual ~DirectDataOutputStream()
+ {
+ }
+
+ #define STREAM_DIRECT_WRITE(type,name) virtual bool Write##name(const type &value) \
+ { \
+ return Write(value); \
+ } \
+ \
+ virtual int64 Write##name(const type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ return WriteArrays(data,count); \
+ }
+
+ STREAM_DIRECT_WRITE(int16, Int16 );
+ STREAM_DIRECT_WRITE(int32, Int32 );
+ STREAM_DIRECT_WRITE(int64, Int64 );
+
+ STREAM_DIRECT_WRITE(uint16, Uint16 );
+ STREAM_DIRECT_WRITE(uint32, Uint32 );
+ STREAM_DIRECT_WRITE(uint64, Uint64 );
+
+ STREAM_DIRECT_WRITE(u16char,UTF16Char);
+ STREAM_DIRECT_WRITE(float, Float );
+ STREAM_DIRECT_WRITE(double, Double );
+
+ #undef STREAM_DIRECT_WRITE
+ };//class DirectDataOutputStream
+
+ class SwapDataOutputStream:public DataOutputStream
+ {
+ public:
+
+ SwapDataOutputStream(OutputStream *os):DataOutputStream(os)
+ {
+ }
+
+ virtual ~SwapDataOutputStream()
+ {
+ }
+
+ #define STREAM_SWAP_WRITE(type,name) virtual bool Write##name(const type &value) \
+ {\
+ return Write(EndianSwap(value)); \
+ } \
+ \
+ virtual int64 Write##name(const type *data,const int64 count) \
+ { \
+ if(count<=0)return(count); \
+ if(!data)return(-1); \
+ \
+ SharedArray swap_data=new type[count]; \
+ \
+ EndianSwap(swap_data,data,count); \
+ \
+ return WriteArrays(swap_data,count); \
+ }
+
+ STREAM_SWAP_WRITE(int16, Int16 );
+ STREAM_SWAP_WRITE(int32, Int32 );
+ STREAM_SWAP_WRITE(int64, Int64 );
+
+ STREAM_SWAP_WRITE(uint16, Uint16 );
+ STREAM_SWAP_WRITE(uint32, Uint32 );
+ STREAM_SWAP_WRITE(uint64, Uint64 );
+
+ STREAM_SWAP_WRITE(u16char, UTF16Char);
+ STREAM_SWAP_WRITE(float, Float );
+ STREAM_SWAP_WRITE(double, Double );
+
+ #undef STREAM_SWAP_WRITE
+ };//class SwapDataOutputStream
+
+#if HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ typedef DirectDataOutputStream LEDataOutputStream;
+ typedef SwapDataOutputStream BEDataOutputStream;
+#else
+ typedef DirectDataOutputStream BEDataOutputStream;
+ typedef SwapDataOutputStream LEDataOutputStream;
+#endif//HGL_ENDIAN == HGL_LITTLE_ENDIAN
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_ENDIAN_DATA_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/FileAccess.h b/inc/hgl/io/FileAccess.h
new file mode 100644
index 0000000..0dc09fa
--- /dev/null
+++ b/inc/hgl/io/FileAccess.h
@@ -0,0 +1,83 @@
+#ifndef HGL_IO_FILE_ACCESS_INCLUDE
+#define HGL_IO_FILE_ACCESS_INCLUDE
+
+#include
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ enum FileOpenMode ///文件访问模式枚举
+ {
+ fomNone=0,
+
+ fomCreate, ///<创建文件,如存在则失败
+ fomCreateTrunc, ///<强制创建,如存在则抹掉
+ fomCreateTemp,
+ fomOnlyRead, ///<只读方式
+ fomOnlyWrite, ///<只写方式
+ fomReadWrite, ///<可读可写
+ fomAppend, ///<追加模式
+
+ fomEnd
+ };//enum FileOpenMode
+
+ /**
+ * 文件访问实例管理类
+ */
+ class FileAccess ///文件访问实例管理类
+ {
+ protected:
+
+ OSString filename;
+
+ int fp;
+
+ struct_stat64 file_state;
+
+ FileOpenMode mode;
+
+ public:
+
+ FileAccess();
+ virtual ~FileAccess();
+
+ virtual bool Open(const OSString &,FileOpenMode fom); ///<以指定模式打开一个文件
+ virtual bool Create(const OSString &fn){return Open(fn,fomCreate);} ///<创建一个新文件,如文件已存在则创建失败
+ virtual bool CreateTrunc(const OSString &fn){return Open(fn,fomCreateTrunc);} ///<创建一个新文件,如文件已存在则抹消它
+ virtual bool OpenRead(const OSString &fn){return Open(fn,fomOnlyRead);} ///<以只读模式打开一个文件
+ virtual bool OpenWrite(const OSString &fn){return Open(fn,fomOnlyWrite);} ///<以只写模式打开一个文件
+ virtual bool OpenReadWrite(const OSString &fn){return Open(fn,fomReadWrite);} ///<以读写模式打开一个文件
+ virtual bool CreateTemp();
+
+ virtual void Close(); ///<关闭文件
+ virtual void CloseRead(); ///<仅关闭读取
+ virtual void CloseWrite(); ///<仅关闭写入
+
+ virtual int GetFileHandle()const{return fp;}
+
+ virtual bool CanRead()const; ///<文件是否可读
+ virtual bool CanPeek()const{return(CanRead()&&CanSeek());} ///<文件是否可预读
+ virtual bool CanWrite()const; ///<文件是否可写
+ virtual bool CanSeek()const; ///<文件是否可定位访问指针
+ virtual bool CanRestart()const{return CanSeek();} ///<文件是否可复位访问
+ virtual bool CanSize()const{return(true);} ///<文件是否可取得长度
+
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<定位访问指针
+ virtual int64 Tell()const; ///<取得访问指针位置
+ virtual int64 GetSize(); ///<取得文件长度
+ virtual bool Restart(); ///<复位访问指针
+
+ virtual int64 Read(void *,int64); ///<读取指定长度数据
+ virtual int64 Peek(void *,int64); ///<预读指定长度数据
+ virtual int64 Write(const void *,int64); ///<写入指定长度数据
+
+ virtual int64 AvailableRead(); ///<剩下的可读数据
+
+ virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
+ virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
+ };//class FileAccess
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_FILE_ACCESS_INCLUDE
diff --git a/inc/hgl/io/FileInputStream.h b/inc/hgl/io/FileInputStream.h
new file mode 100644
index 0000000..c364187
--- /dev/null
+++ b/inc/hgl/io/FileInputStream.h
@@ -0,0 +1,78 @@
+#ifndef HGL_IO_FILE_INPUT_STREAM_INCLUDE
+#define HGL_IO_FILE_INPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 文件输入流类
+ */
+ class FileInputStream:public InputStream ///文件输入流类
+ {
+ protected:
+
+ SharedPtr file; ///<文件访问指针
+
+ public:
+
+ FileInputStream();
+ FileInputStream(SharedPtr &);
+ virtual ~FileInputStream();
+
+ virtual bool Open(const OSString &); ///<打开文件
+ virtual void Close(); ///<关闭文件输入流
+
+ virtual int GetFileHandle()const{return file->GetFileHandle();}
+
+ virtual int64 Read(void *,int64); ///<读取数据
+ virtual int64 Peek(void *,int64); ///<预读数据
+
+ virtual bool CanSeek()const; ///<是否可移动访问指针
+ virtual bool CanRestart()const; ///<是否可复位访问
+ virtual bool CanSize()const; ///<是否可访问文件长度
+ virtual bool CanPeek()const; ///<是否可预读数据
+
+ virtual int64 Skip(int64); ///<跳过指定字节
+ virtual int64 Tell()const; ///<取当前位置
+ virtual int64 GetSize()const; ///<取得文件长度
+ virtual bool Restart(); ///<复位访问指针
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
+
+ virtual int64 Available()const; ///<剩下的可以不受阻塞访问的字节数
+
+ virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
+ };//class FileInputStream
+
+ class OpenFileInputStream
+ {
+ FileInputStream *fis;
+
+ public:
+
+ OpenFileInputStream(const OSString &filename)
+ {
+ fis=new FileInputStream();
+
+ if(!fis->Open(filename))
+ {
+ delete fis;
+ fis=nullptr;
+ }
+ }
+
+ ~OpenFileInputStream()
+ {
+ SAFE_CLEAR(fis);
+ }
+
+ const bool operator !(){return !fis;}
+ operator FileInputStream *(){return fis;}
+ FileInputStream *operator &(){return fis;}
+ FileInputStream *operator ->(){return fis;}
+ };//class OpenFileInputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_FILE_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/FileOutputStream.h b/inc/hgl/io/FileOutputStream.h
new file mode 100644
index 0000000..0483103
--- /dev/null
+++ b/inc/hgl/io/FileOutputStream.h
@@ -0,0 +1,93 @@
+#ifndef HGL_IO_FILE_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_FILE_OUTPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 文件输出流类
+ */
+ class FileOutputStream:public OutputStream ///文件输出流类
+ {
+ protected:
+
+ SharedPtr file; ///<文件访问指针
+
+ virtual bool OpenFile(const OSString &,FileOpenMode);
+
+ public:
+
+ FileOutputStream();
+ FileOutputStream(SharedPtr &);
+ virtual ~FileOutputStream();
+
+ virtual bool Open(const OSString &fn,FileOpenMode mode){return OpenFile(fn,mode);} ///<打开文件,指定一个模式
+ virtual bool Open(const OSString &fn){return OpenFile(fn,fomOnlyWrite);} ///<打开文件
+ virtual bool Create(const OSString &fn){return OpenFile(fn,fomCreate);} ///<创建文件,如存在创建失败
+ virtual bool CreateTrunc(const OSString &fn){return OpenFile(fn,fomCreateTrunc);} ///<创建文件,如存在则抹去
+ virtual bool OpenAppend(const OSString &fn){return OpenFile(fn,fomAppend);} ///<打开文件,追加模式
+
+ virtual void Close(); ///<关闭文件
+
+ virtual int64 Write(const void *,int64); ///<写入数据
+
+ virtual bool CanSeek()const; ///<是否可移动访问指针
+ virtual bool CanRestart()const; ///<是否可复位访问
+ virtual bool CanSize()const; ///<是否可访问文件长度
+
+ virtual int64 Tell()const; ///<取当前位置
+ virtual int64 GetSize()const; ///<取得文件长度
+ virtual bool Restart(); ///<复位访问指针
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
+ virtual int64 Available()const{return -1;} ///<可不受影响写入的字节数
+
+ virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
+ };//class FileOutputStream
+
+ /**
+ * 打开一个文件输出流
+ */
+ class OpenFileOutputStream
+ {
+ FileOutputStream *fos;
+
+ public:
+
+ OpenFileOutputStream()
+ {
+ fos=nullptr;
+ }
+
+ /**
+ * 打开一个文件输出流构造函数
+ * @param filename 文件名
+ * @param mode 打开模式,默认只写(必然可读)
+ * @see FileOpenMode
+ */
+ OpenFileOutputStream(const OSString &filename,FileOpenMode mode=fomOnlyWrite)
+ {
+ fos=new FileOutputStream();
+
+ if(!fos->Open(filename))
+ {
+ delete fos;
+ fos=nullptr;
+ }
+ }
+
+ ~OpenFileOutputStream()
+ {
+ SAFE_CLEAR(fos);
+ }
+
+ const bool operator !(){return !fos;}
+ operator FileOutputStream *(){return fos;}
+ FileOutputStream *operator &(){return fos;}
+ FileOutputStream *operator ->(){return fos;}
+ };//class OpenFileInputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_FILE_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/IOType.h b/inc/hgl/io/IOType.h
new file mode 100644
index 0000000..d09068a
--- /dev/null
+++ b/inc/hgl/io/IOType.h
@@ -0,0 +1,34 @@
+#ifndef HGL_IO_TYPE_INCLUDE
+#define HGL_IO_TYPE_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ class DataInputStream;
+ class DataOutputStream;
+
+ template struct io_type
+ {
+ T value;
+
+ public:
+
+ io_type()=default;
+ io_type(const T &v){value=v;}
+
+ bool Read(DataInputStream *);
+ bool Write(DataOutputStream *)const;
+
+ void operator = (const T &v)
+ {
+ value=v;
+ }
+
+ operator T (){return value;}
+ operator const T ()const{return value;}
+ };//template struct io_type
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_TYPE_INCLUDE
diff --git a/inc/hgl/io/InputStream.h b/inc/hgl/io/InputStream.h
new file mode 100644
index 0000000..ab26b41
--- /dev/null
+++ b/inc/hgl/io/InputStream.h
@@ -0,0 +1,39 @@
+#ifndef HGL_IO_INPUT_STREAM_INCLUDE
+#define HGL_IO_INPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 数据输入流基类
+ */
+ class InputStream:public SeekAccess ///数据输入流基类
+ {
+ public:
+
+ virtual ~InputStream()=default;
+
+ virtual void Close()=0; ///<关闭输入流
+
+ virtual int64 Read(void *,int64)=0; ///<读取数据
+ virtual int64 Peek(void *,int64)=0; ///<预览数据
+ virtual int64 ReadFully(void *buf,int64 buf_size){return Read(buf,buf_size);} ///<充分读取,保证读取到指定长度的数据(不计算超时)
+
+ virtual bool CanRestart()const=0; ///<是否可以复位
+ virtual bool CanSeek()const=0; ///<是否可以定位
+ virtual bool CanSize()const=0; ///<是否可以取得尺寸
+ virtual bool CanPeek()const=0; ///<是否可以预览数据
+
+ virtual bool Restart()=0; ///<复位访问指针
+ virtual int64 Skip(int64)=0; ///<跳过指定字节不访问
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
+ virtual int64 Tell()const=0; ///<返回当前访问位置
+ virtual int64 GetSize()const=0; ///<取得流长度
+ virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数
+ };//class InputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/JavaInputStream.h b/inc/hgl/io/JavaInputStream.h
new file mode 100644
index 0000000..3b07a1c
--- /dev/null
+++ b/inc/hgl/io/JavaInputStream.h
@@ -0,0 +1,71 @@
+#ifndef HGL_IO_JAVA_INPUT_STREAM_INCLUDE
+#define HGL_IO_JAVA_INPUT_STREAM_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * Java数据输入流
+ * 接口类似于java.io.DataInputStream,用于和Java程序进行交互
+ */
+ class JavaInputStream
+ {
+ protected:
+
+ BEDataInputStream *in;
+
+ public:
+
+ JavaInputStream(InputStream *is)
+ {
+ in=new BEDataInputStream(is);
+ }
+
+ virtual ~JavaInputStream()
+ {
+ delete in;
+ }
+
+ int64 read (void *ptr,int size){return in?in->ReadFully(ptr,size):-1;}
+ int skipBytes (int size) {return in?in->Seek(size,soCurrent):-1;}
+
+ bool readBoolean (bool &b) {return in?in->ReadBool (b):false;}
+ bool readByte (int8 &i) {return in?in->ReadInt8 (i):false;}
+ bool readUnsignedByte (uint8 &i) {return in?in->ReadUint8 (i):false;}
+
+ bool readShort (int16 &i) {return in?in->ReadInt16 (i):false;}
+ bool readUnsignedShort (uint16 &i) {return in?in->ReadUint16 (i):false;}
+ bool readInt (int32 &i) {return in?in->ReadInt32 (i):false;}
+ bool readLong (int64 &i) {return in?in->ReadInt64 (i):false;}
+ bool readFloat (float &f) {return in?in->ReadFloat (f):false;}
+ bool readDouble (double &d) {return in?in->ReadDouble (d):false;}
+
+ bool readChar (u16char &c)
+ {
+ if(!in)
+ return(false);
+
+ uint16 c16;
+
+ if(!in->Read(c16))
+ return(false);
+
+ c=BigToCurrentEndian(c16);
+ return(true);
+ }
+
+ bool readChars (u16char *wstr,const int count)
+ {
+ return in?in->ReadUTF16BEChars(wstr,count):false;
+ }
+
+ bool readUTF (UTF16String &str)
+ {
+ return in?in->ReadUTF8ShortString(str);
+ }
+ };//class JavaInputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_JAVA_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/JavaOutputStream.h b/inc/hgl/io/JavaOutputStream.h
new file mode 100644
index 0000000..bf2d91d
--- /dev/null
+++ b/inc/hgl/io/JavaOutputStream.h
@@ -0,0 +1,62 @@
+#ifndef HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * Java数据输出流
+ * 接口类似于java.io.DataOutputStream,用于和Java程序进行交互
+ */
+ class JavaOutputStream
+ {
+ protected:
+
+ BEDataOutputStream *out;
+
+ public:
+
+ JavaOutputStream(OutputStream *os)
+ {
+ out=new BEDataOutputStream(os);
+ }
+
+ virtual ~JavaOutputStream()
+ {
+ delete out;
+ }
+
+ int64 write (const void *ptr,int size) {return out?out->WriteFully(ptr,size):-1;}
+
+ bool writeBoolean (const bool &b) {return out?out->WriteBool (b):false;}
+ bool writeByte (const int8 &i) {return out?out->WriteInt8 (i):false;}
+ bool writeUnsignedByte (const uint8 &i) {return out?out->WriteUint8 (i):false;}
+
+ bool writeShort (const int16 &i) {return out?out->WriteInt16 (i):false;}
+ bool writeUnsignedShort (const uint16 &i) {return out?out->WriteUint16(i):false;}
+ bool writeInt (const int32 &i) {return out?out->WriteInt32 (i):false;}
+ bool writeLong (const int64 &i) {return out?out->WriteInt64 (i):false;}
+ bool writeFloat (const float &f) {return out?out->WriteFloat (f):false;}
+ bool writeDouble (const double &d) {return out?out->WriteDouble(d):false;}
+
+ bool writeChar (const u16char &c)
+ {
+ if(!out)
+ return(false);
+
+ return out->Write(ToBigEndian(c));
+ }
+
+ bool writeChars (const u16char *wstr,const int64 count)
+ {
+ return out?out->WriteUTF16BEChars(wstr,count):false;
+ }
+
+ bool writeUTF (const UTF8String &str){return out?out->WriteUTF8ShortString(str);}
+ bool writeUTF (const UTF16String &str){return out?out->WriteUTF8ShortString(str);}
+ };//class JavaOutputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/MemoryInputStream.h b/inc/hgl/io/MemoryInputStream.h
new file mode 100644
index 0000000..8cebe5f
--- /dev/null
+++ b/inc/hgl/io/MemoryInputStream.h
@@ -0,0 +1,162 @@
+#ifndef HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
+#define HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 内存数据输入流,从内存块中取得数据。
+ */
+ class MemoryInputStream:public InputStream ///内存数据输入流
+ {
+ protected:
+
+ const uint8 *buf;
+ size_t buf_size;
+ size_t cur_pos;
+
+ public:
+
+ MemoryInputStream()
+ {
+ buf=0;
+
+ buf_size=0;
+ cur_pos=0;
+ }
+
+ virtual ~MemoryInputStream()
+ {
+ }
+
+ /**
+ * 关联一个数据区到当前输入流
+ * @param data 数据指针
+ * @param size 数据长度字节数
+ * @return 是否成功
+ */
+ bool Link(const void *data,const size_t size)
+ {
+ if(!data)
+ return(false);
+
+ buf=(uint8 *)data;
+ buf_size=size;
+ cur_pos=0;
+
+ return(true);
+ }
+
+ /**
+ * 更新关联的数据区长度,不复位cur_pos
+ * @param data 数据指针
+ * @param size 数据长度字节数
+ * @return 是否成功
+ */
+ bool Update(void *data,size_t size)
+ {
+ if(!data)
+ return(false);
+
+ buf=(uint8 *)data;
+ buf_size=size;
+
+ return(true);
+ }
+
+ void Unlink()
+ {
+ buf=0;
+ }
+
+ void Close()
+ {
+ Unlink();
+ }
+
+ int64 Read(void *data,int64 size)
+ {
+ const int result=Peek(data,size);
+
+ if(result>0)
+ cur_pos+=result;
+
+ return result;
+ }
+
+ int64 Peek(void *data,int64 size)
+ {
+ if(!buf||!data||size<0)
+ return(-1);
+
+ if(cur_pos+size>buf_size)
+ size=buf_size-cur_pos;
+
+ if(size<=0)
+ return(0);
+
+ memcpy(data,buf+cur_pos,size);
+
+ return size;
+ }
+
+ bool CanRestart()const{return true;}
+ bool CanSeek()const{return true;}
+ bool CanSize()const{return true;}
+ bool CanPeek()const{return true;}
+
+ bool Restart()
+ {
+ cur_pos=0;
+ return(true);
+ }
+
+ int64 Skip(int64 bytes)
+ {
+ return Seek(bytes,SeekOrigin::Current);
+ }
+
+ int64 Seek(int64 off,SeekOrigin so)
+ {
+ if(!CanSeek())return(-1);
+
+ if(so==SeekOrigin::Current)
+ {
+ off+=cur_pos;
+ }
+ else
+ if(so==SeekOrigin::End)
+ {
+ off+=buf_size;
+ }
+
+ if(off<0||off>=buf_size)
+ return(-1);
+
+ cur_pos=off;
+ return cur_pos;
+ }
+
+ int64 Tell()const
+ {
+ if(!buf)return(-1);
+ return cur_pos;
+ }
+
+ int64 GetSize()const
+ {
+ if(!buf)return(-1);
+ return buf_size;
+ }
+
+ int64 Available()const
+ {
+ if(!buf)return(-1);
+ return buf_size-cur_pos;
+ }
+ };//class MemoryInputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/MemoryOutputStream.h b/inc/hgl/io/MemoryOutputStream.h
new file mode 100644
index 0000000..04baf93
--- /dev/null
+++ b/inc/hgl/io/MemoryOutputStream.h
@@ -0,0 +1,235 @@
+#ifndef HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 内存数据输出流,将数据输出到一个内存块中。
+ */
+ class MemoryOutputStream:public OutputStream ///内存数据输出流
+ {
+ protected:
+
+ uint8 *buf;
+
+ size_t max_size;
+ size_t buf_size;
+ size_t cur_pos;
+
+ bool one;
+
+ public:
+
+ MemoryOutputStream()
+ {
+ buf=0;
+ max_size=0;
+ buf_size=0;
+ cur_pos=0;
+ one=false;
+ }
+
+ virtual ~MemoryOutputStream()
+ {
+ Close();
+ }
+
+ void *GetData()const{return buf;}
+
+ /**
+ * 创建一个当前流数据的内存拷贝,此函数需用户自行delete[]
+ * @param len 存放数据长度的指针
+ * @return 创建好的内存拷贝
+ */
+ void *CreateCopyData(uint *len)const
+ {
+ if(buf_size<=0)
+ return(nullptr);
+
+ uint8 *data=new uint8[buf_size+1];
+ memcpy(data,buf,buf_size);
+ data[buf_size]=0;
+
+ if(len)
+ *len=buf_size;
+
+ return data;
+ }
+
+ /**
+ * 关联一个数据区到当前输出流
+ * @param ptr 数据指针
+ * @param size 数据长度字节数
+ * @param one_instance 是否仅此一份实例(如果是,将由MemoryOutputStream类负责释放)
+ * @return 是否成功
+ */
+ bool Link(void *ptr,size_t size,bool one_instance=false)
+ {
+ if(!ptr||!size)
+ return(false);
+
+ buf=(uint8 *)ptr;
+ buf_size=size;
+ max_size=size;
+ cur_pos=0;
+
+ one=one_instance;
+
+ return(true);
+ }
+
+ /**
+ * 更新关联的数据区长度,不复位cur_pos
+ * @param ptr 数据指针
+ * @param size 数据长度字节数
+ * @return 是否成功
+ */
+ bool Update(void *ptr,size_t size)
+ {
+ if(!ptr||!size)
+ return(false);
+
+ buf=(uint8 *)ptr;
+ buf_size=size;
+ max_size=0;
+
+ return(true);
+ }
+
+ void Unlink()
+ {
+ buf=0;
+ buf_size=0;
+ max_size=0;
+ }
+
+ bool Create(int64 size)
+ {
+ Close();
+
+ if(size<=0)
+ return(false);
+
+ buf=(uint8 *)hgl_malloc(size);
+
+ if(!buf)
+ return(false);
+
+ one=true;
+ cur_pos=0;
+ buf_size=size;
+ max_size=size;
+
+ return(true);
+ }
+
+ void Close() override
+ {
+ if(buf)
+ {
+ if(one)
+ hgl_free(buf);
+
+ buf=0;
+ }
+
+ buf_size=0;
+ max_size=0;
+ }
+
+ void ClearData()
+ {
+ cur_pos=0;
+ buf_size=0;
+ }
+
+ int64 Write(const void *ptr,int64 size) override
+ {
+ if(!ptr||size<0)
+ return(-1);
+
+ if(!buf)
+ {
+ if(!Create(size))
+ return(-1);
+ }
+
+ if(cur_pos+size>buf_size)
+ {
+ if(one)
+ {
+ buf_size=cur_pos+size;
+
+ if(buf_size>max_size)
+ {
+ max_size=power_to_2(buf_size);
+
+ buf=(uint8 *)hgl_realloc(buf,max_size);
+ }
+ }
+ else
+ size=buf_size-cur_pos;
+ }
+
+ if(size<=0)
+ return(0);
+
+ memcpy(buf+cur_pos,ptr,size);
+
+ cur_pos+=size;
+
+ return size;
+ }
+
+ bool CanRestart()const override{return true;}
+ bool CanSeek()const override{return true;}
+ bool CanSize()const override{return true;}
+
+ bool Restart() override
+ {
+ cur_pos=0;
+ return(true);
+ }
+
+ int64 Seek(int64 off,SeekOrigin so=SeekOrigin::Begin) override
+ {
+ if(!CanSeek())return(-1);
+
+ if(so==SeekOrigin::Current)
+ {
+ off+=cur_pos;
+ }
+ else
+ if(so==SeekOrigin::End)
+ {
+ off+=buf_size;
+ }
+
+ if(off<0||off>=buf_size)
+ return(-1);
+
+ cur_pos=off;
+ return cur_pos;
+ }
+
+ int64 Tell()const override
+ {
+ return cur_pos;
+ }
+
+ int64 GetSize()const override
+ {
+ return buf_size;
+ }
+
+ int64 Available()const override
+ {
+ return buf_size-cur_pos;
+ }
+ };//class MemoryOutputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/OutputStream.h b/inc/hgl/io/OutputStream.h
new file mode 100644
index 0000000..624f6cf
--- /dev/null
+++ b/inc/hgl/io/OutputStream.h
@@ -0,0 +1,36 @@
+#ifndef HGL_IO_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_OUTPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 数据输出流基类
+ */
+ class OutputStream:public SeekAccess ///数据输出流基类
+ {
+ public:
+
+ virtual ~OutputStream()=default;
+
+ virtual void Close()=0; ///<关闭输出流
+
+ virtual int64 Write(const void *,int64)=0; ///<写入数据
+ virtual int64 WriteFully(const void *buf,int64 buf_size){return Write(buf,buf_size);} ///<充分写入,保证完整写入指定长度的数据
+
+ virtual bool CanRestart()const=0; ///<是否可以复位
+ virtual bool CanSeek()const=0; ///<是否可以定位
+ virtual bool CanSize()const=0; ///<是否可以取得尺寸
+
+ virtual bool Restart()=0; ///<复位访问指针
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
+ virtual int64 Tell()const=0; ///<返回当前访问位置
+ virtual int64 GetSize()const=0; ///<取得流长度
+ virtual int64 Available()const=0; ///<剩下的可以不受阻塞写入的字节数
+ };//class OutputStream
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/io/RandomAccessFile.h b/inc/hgl/io/RandomAccessFile.h
new file mode 100644
index 0000000..ed24b74
--- /dev/null
+++ b/inc/hgl/io/RandomAccessFile.h
@@ -0,0 +1,47 @@
+#ifndef HGL_IO_RANDOM_ACCESS_FILE_INCLUDE
+#define HGL_IO_RANDOM_ACCESS_FILE_INCLUDE
+
+#include
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 随机文件访问
+ * 可同时被DataInputStream/DataOutputStream包含引用,但需注意他们将共用一个访问指针
+ */
+ class RandomAccessFile:public InputStream,public OutputStream
+ {
+ protected:
+
+ SharedPtr file; ///<文件访问指针
+
+ public:
+
+ RandomAccessFile();
+ RandomAccessFile(SharedPtr &);
+ ~RandomAccessFile();
+
+ virtual bool Open(const OSString &); ///<打开文件
+ virtual void Close(); ///<关闭文件
+
+ virtual int64 Read(void *,int64); ///<读取数据
+ virtual int64 Write(const void *,int64); ///<写入数据
+
+ virtual int64 Read(int64,void *,int64); ///<在指定位置读取指定长度的数据
+ virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据
+
+ virtual bool CanSeek()const; ///<是否可移动访问指针
+ virtual bool CanRestart()const; ///<是否可复位访问
+ virtual bool CanSize()const; ///<是否可访问文件长度
+
+ virtual int64 Tell()const; ///<取当前位置
+ virtual int64 GetSize(); ///<取得文件长度
+ virtual bool Restart(); ///<复位访问指针
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
+ };//class RandomAccessFile
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_RANDOM_ACCESS_FILE_INCLUDE
diff --git a/inc/hgl/io/SeekAccess.h b/inc/hgl/io/SeekAccess.h
new file mode 100644
index 0000000..8977421
--- /dev/null
+++ b/inc/hgl/io/SeekAccess.h
@@ -0,0 +1,36 @@
+#ifndef HGL_IO_SEEK_ACCESS_INCLUDE
+#define HGL_IO_SEEK_ACCESS_INCLUDE
+
+#include
+namespace hgl
+{
+ namespace io
+ {
+ enum class SeekOrigin /// 资源偏移方向枚举
+ {
+ Begin=0, ///<从资源最开始处开始,offset必须大于0。移到资源的offset位置
+ Current, ///<从资源当前位置开始,移到资源的Position+offset位置
+ End ///<从资源的结束位置开始,offset必须小于0,表示结束前的字符数
+ };//enum SeekOrigin
+
+ /**
+ * 定位访问功能基类
+ */
+ class SeekAccess
+ {
+ public:
+
+ virtual ~SeekAccess()=default;
+
+ virtual bool CanRestart()const=0; ///<是否可以复位
+ virtual bool CanSeek()const=0; ///<是否可以定位
+ virtual bool CanSize()const=0; ///<是否可以取得尺寸
+
+ virtual bool Restart()=0; ///<复位访问指针
+ virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
+ virtual int64 Tell()const=0; ///<返回当前访问位置
+ virtual int64 GetSize()const=0; ///<取得文件长度
+ };//class SeekAccess
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_SEEK_ACCESS_INCLUDE
diff --git a/inc/hgl/io/TextOutputStream.h b/inc/hgl/io/TextOutputStream.h
new file mode 100644
index 0000000..20f838b
--- /dev/null
+++ b/inc/hgl/io/TextOutputStream.h
@@ -0,0 +1,176 @@
+#ifndef HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE
+#define HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ namespace io
+ {
+ /**
+ * 文本输出流
+ * 用于将数据输出成文件,用于日志、配置等文本信息处理。
+ */
+ class TextOutputStream
+ {
+ protected:
+
+ ByteOrderMask bom; ///<文本编码
+ DataOutputStream *out; ///<数据输出流
+
+ public:
+
+ TextOutputStream(ByteOrderMask _bom,DataOutputStream *_out)
+ {
+ bom=_bom;
+ out=_out;
+ }
+
+ virtual ~TextOutputStream()
+ {
+ delete out;
+ }
+
+ const ByteOrderMask GetBOM()const
+ {
+ return bom;
+ }
+
+ DataOutputStream *GetDataOutputStream()
+ {
+ return out;
+ }
+
+ operator DataOutputStream *()
+ {
+ return out;
+ }
+
+ bool WriteBOM() ///<写入文本文件bom头
+ {
+ if(!out)return(false);
+
+ const BOMFileHeader *bom_item=BOMData+bom;
+
+ return(out->Write(bom_item->data,bom_item->size)==bom_item->size);
+ }
+
+ virtual bool WriteChars(const char *,int64)=0; ///<写入一个字符串
+ virtual bool WriteChars(const u16char *,int64)=0; ///<写入一个字符串
+
+ template
+ bool WriteString(const BaseString &str) ///<写入一个字符串
+ {
+ return WriteChars(str.c_str(),str.Length());
+ }
+
+ bool WriteLineEnd() ///<写入一个换行符
+ {
+ return WriteChars(HGL_LINE_END,HGL_LINE_END_SIZE);
+ }
+
+ template
+ bool WriteLine(const N *str,int64 size)
+ {
+ if(!WriteChars(str,size))
+ return(false);
+
+ return WriteLineEnd();
+ }
+
+ template
+ bool WriteLine(const BaseString &str)
+ {
+ return WriteLine(str.c_str(),str.Length());
+ }
+
+ /**
+ * 向流中写入一个文本(注:整体按标准文本文件模式)
+ */
+ template
+ bool WriteText(const StringList &sl)
+ {
+ const int count=sl.GetCount();
+
+ for(int i=0;i
+ bool Write(const StringList &sl)
+ {
+ const int count=sl.GetCount();
+
+ if(!out->WriteInt32(count)) //写入行数
+ return(false);
+
+ if(count<=0)
+ return(true);
+
+ SharedArray line_length=new int32[count];
+ SharedArray str_list=new T *[count];
+ int32 *line_p=line_length;
+ T **str_p=str_list;
+
+ int32 total=0;
+
+ for(int i=0;i &str=sl[i];
+
+ const int len=str.Length();
+
+ total+=len;
+
+ *line_p++=len;
+
+ *str_list++=str.c_str();
+ }
+
+ if(out->WriteInt32(line_length,count)!=count) //写入每行长度
+ return(false);
+
+ line_p=line_length;
+ str_p=str_list;
+
+ SharedArray text=new T[total];
+ T *text_p=text;
+
+ for(int i=0;i class EndianTextOutputStream:public TextOutputStream ///文本输出流
+ {
+ public:
+
+ EndianTextOutputStream(OutputStream *);
+
+ bool WriteChars(const char *,int64); ///<写入一个字符串
+ bool WriteChars(const u16char *,int64); ///<写入一个字符串
+ };//template class EndianTextOutputStream
+
+ typedef EndianTextOutputStream UTF8TextOutputStream;
+ typedef EndianTextOutputStream UTF16LETextOutputStream;
+ typedef EndianTextOutputStream UTF16BETextOutputStream;
+
+ template TextOutputStream *CreateTextOutputStream(OutputStream *os);
+ }//namespace io
+}//namespace hgl
+#endif//HGL_IO_TEXT_OUTPUT_STREAM_INCLUDE
diff --git a/inc/hgl/math/FastTriangle.h b/inc/hgl/math/FastTriangle.h
new file mode 100644
index 0000000..3c4d68d
--- /dev/null
+++ b/inc/hgl/math/FastTriangle.h
@@ -0,0 +1,23 @@
+#ifndef HGL_ALGORITHM_MATH_FAST_TRIANGLE_FUNCTION_INCLUDE
+#define HGL_ALGORITHM_MATH_FAST_TRIANGLE_FUNCTION_INCLUDE
+
+namespace hgl
+{
+ double Lsin(int angle); ///<低精度sin计算,注意传入的参数为角度而非弧度
+ double Lcos(int angle); ///<低精度cos计算,注意传入的参数为角度而非弧度
+ void Lsincos(int angle, double &s, double &c); ///<低精度sin+cos计算,注意传入的参数为角度而非弧度
+
+ /**
+ * 低精度atan函数
+ */
+ double inline Latan(double z)
+ {
+ constexpr double n1 = 0.97239411f;
+ constexpr double n2 = -0.19194795f;
+
+ return (n1 + n2 * z * z) * z;
+ }
+
+ double Latan2(double y, double x); ///<低精度atan2函数
+}//namespace hgl
+#endif//HGL_ALGORITHM_MATH_FAST_TRIANGLE_FUNCTION_INCLUDE
diff --git a/inc/hgl/math/Math.h b/inc/hgl/math/Math.h
new file mode 100644
index 0000000..6637bfb
--- /dev/null
+++ b/inc/hgl/math/Math.h
@@ -0,0 +1,8 @@
+#ifndef HGL_ALGORITHM_MATH_INCLUDE
+#define HGL_ALGORITHM_MATH_INCLUDE
+
+#include
+#include // Game Math and Geometry Library
+#include
+
+#endif//HGL_ALGORITHM_MATH_INCLUDE
diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h
new file mode 100644
index 0000000..10e7ea9
--- /dev/null
+++ b/inc/hgl/math/Matrix.h
@@ -0,0 +1,156 @@
+#ifndef HGL_ALGORITHM_MATH_VECTOR_MATRIX_INCLUDE
+#define HGL_ALGORITHM_MATH_VECTOR_MATRIX_INCLUDE
+
+#include
+#include
+//注:GLM/CML(OpenGLMode)是列矩阵,计算坐标matrix*pos
+// 而MGL是行矩阵,需要反过来pos*matrix
+
+namespace hgl
+{
+ using Matrix3f=float3x3;
+ using Matrix4f=float4x4;
+
+ struct WorldMatrix
+ {
+ alignas(16) Matrix4f ortho; //2D正角视图矩阵
+
+ alignas(16) Matrix4f projection;
+// alignas(16) Matrix4f inverse_projection;
+ alignas(16) Matrix4f modelview;
+ alignas(16) Matrix4f mvp;
+ alignas(16) Vector4f view_pos; //眼睛坐标
+ };//struct WorldMatrix
+
+ inline Matrix4f identity()
+ {
+ return Matrix4f::identity;
+ }
+
+ inline Matrix4f inverse(const Matrix4f &m)
+ {
+ return m.Inverted();
+ }
+
+ inline Matrix4f ortho( float left,
+ float right,
+ float bottom,
+ float top,
+ float znear,
+ float zfar )
+ {
+ return Matrix4f(
+ 2.0f / (right - left), 0.0f, 0.0f, -(right + left) / (right - left),
+ 0.0f, 2.0f / (bottom - top), 0.0f, -(bottom + top) / (bottom - top),
+ 0.0f, 0.0f, 1.0f / (znear - zfar), znear / (znear - zfar),
+ 0.0f, 0.0f, 0.0f, 1.0f);
+ }
+
+ /**
+ * 生成一个正角视图矩阵
+ * @param width 宽
+ * @param height 高
+ * @param znear 近平面z值
+ * @param zfar 远平台z值
+ */
+ inline Matrix4f ortho(float width,float height,float znear,float zfar)
+ {
+ return Matrix4f(
+ 2.0f / width, 0.0f, 0.0f, -1,
+ 0.0f, 2.0f / height, 0.0f, -1,
+ 0.0f, 0.0f, 1.0f / (znear - zfar), znear / (znear - zfar),
+ 0.0f, 0.0f, 0.0f, 1.0f);
+ }
+
+ /**
+ * 生成一个正角视图矩阵
+ * @param width 宽
+ * @param height 高
+ */
+ inline Matrix4f ortho(float width,float height)
+ {
+ return Matrix4f(
+ 2.0f / width, 0.0f, 0.0f, -1,
+ 0.0f, 2.0f / height, 0.0f, -1,
+ 0.0f, 0.0f, -1.0f , 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f);
+ }
+
+ /**
+ * 生成一个透视矩阵
+ * @param aspect_ratio 宽高比
+ * @param field_of_view 视野
+ * @param znear 近截面
+ * @param zfar 远截面
+ */
+ inline Matrix4f perspective(float field_of_view,
+ float aspect_ratio,
+ float znear,
+ float zfar)
+ {
+ const float f = 1.0f / tan( hgl_ang2rad( 0.5f * field_of_view ) );
+
+ // float scaleX, shearXy, shearXz, x;
+ //float shearYx, scaleY, shearYz, y;
+ //float shearZx, shearZy, scaleZ, z;
+ //float shearWx, shearWy, shearWz, w;
+
+ return Matrix4f(
+ f / aspect_ratio, 0.0f, 0.0f, 0.0f,
+ 0.0f, -f, 0.0f, 0.0f,
+ 0.0f, 0.0f, zfar / (znear - zfar), (znear * zfar) / (znear - zfar),
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ // 某些引擎这两项会乘0.5,那是因为他们是 -1 to 1 的Z值设定,而我们是0 to 1,所以这里不用乘
+ // 同理,camera的znear为接近0的正数,zfar为一个较大的正数,默认使用16/256
+
+ 0.0f, 0.0f, -1.0f, 0.0f);
+ }
+
+ inline Matrix4f translate(const Vector3f &v)
+ {
+ return Matrix4f::Translate(v);
+ }
+
+ inline Matrix4f translate(float x,float y,float z)
+ {
+ return Matrix4f::Translate(x,y,z);
+ }
+
+ inline Matrix4f scale(const Vector3f &v)
+ {
+ return Matrix4f::Scale(v,Vector3f::zero);
+ }
+
+ inline Matrix4f scale(float x,float y,float z)
+ {
+ return Matrix4f::Scale(Vector3f(x,y,z),Vector3f::zero);
+ }
+
+ inline Matrix4f scale(float s)
+ {
+ return Matrix4f::Scale(Vector3f(s,s,s),Vector3f::zero);
+ }
+
+ inline Matrix4f rotate(float angle,const Vector3f &axis)
+ {
+ return Matrix4f::RotateAxisAngle(axis.Normalized(),angle);
+ }
+
+ inline Matrix4f rotate(float angle,float x,float y,float z)
+ {
+ return rotate(angle,Vector3f(x,y,z));
+ }
+
+ inline Matrix4f rotate(float angle,const Vector4f &axis)
+ {
+ return rotate(angle,Vector3f(axis.x,axis.y,axis.z));
+ }
+
+ inline Vector3f rotate(const Vector3f &v3f,float angle,const Vector3f &axis)
+ {
+ Vector4f result=rotate(angle,axis)*Vector4f(v3f,1.0f);
+
+ return result.xyz();
+ }
+}//namespace hgl
+#endif//HGL_ALGORITHM_MATH_VECTOR_MATRIX_INCLUDE
diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h
new file mode 100644
index 0000000..6ad9854
--- /dev/null
+++ b/inc/hgl/math/Vector.h
@@ -0,0 +1,346 @@
+#ifndef HGL_ALGORITHM_MATH_VECTOR_INCLUDE
+#define HGL_ALGORITHM_MATH_VECTOR_INCLUDE
+
+#ifdef _MSC_VER
+#pragma warning(disable:4244) // double -> int 精度丢失警告
+#endif//_MSC_VER
+
+#include
+#include
+
+/**
+ * MathGeoLib
+ * Game Math and Geometry Library
+ *
+ * My C++ library for 3D mathematics and geometry manipulation.
+ * Jukka Jylänki
+ *
+ * offical web: http://clb.demon.fi/MathGeoLib/nightly/
+ *
+ * License:
+ *
+ * This library is licensed under the Apache 2 license. I am not a lawyer, but to me that
+ * license means that you can use this code for any purpose, both commercial and closed source.
+ * You are however restricted from claiming you wrote it yourself, and cannot hold me liable
+ * for anything over this code.
+ * I acknowledge that most of the non-trivial math routines are taken off a book or a
+ * research paper. In all places, I have tried to be diligent to properly attribute the original
+ * source. Please contact me if you feel I have misattributed something.
+ */
+
+namespace hgl
+{
+ using Vector2f=float2;
+ using Vector3f=float3;
+ using Vector4f=float4;
+
+ inline bool operator == (const Vector2f &lhs,const Vector2f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(false);
+ if(lhs.y!=rhs.y)return(false);
+ return(true);
+ }
+
+ inline bool operator != (const Vector2f &lhs,const Vector2f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(true);
+ if(lhs.y!=rhs.y)return(true);
+ return(false);
+ }
+
+ inline bool operator == (const Vector3f &lhs,const Vector3f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(false);
+ if(lhs.y!=rhs.y)return(false);
+ if(lhs.z!=rhs.z)return(false);
+ return(true);
+ }
+
+ inline bool operator != (const Vector3f &lhs,const Vector3f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(true);
+ if(lhs.y!=rhs.y)return(true);
+ if(lhs.z!=rhs.z)return(true);
+ return(false);
+ }
+
+ inline bool operator == (const Vector4f &lhs,const Vector4f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(false);
+ if(lhs.y!=rhs.y)return(false);
+ if(lhs.z!=rhs.z)return(false);
+ if(lhs.w!=rhs.w)return(false);
+ return(true);
+ }
+
+ inline bool operator != (const Vector4f &lhs,const Vector4f &rhs)
+ {
+ if(lhs.x!=rhs.x)return(true);
+ if(lhs.y!=rhs.y)return(true);
+ if(lhs.z!=rhs.z)return(true);
+ if(lhs.w!=rhs.w)return(true);
+ return(false);
+ }
+
+ inline void vec3to2(Vector2f &dst,const Vector3f &src)
+ {
+ dst.x=src.x;
+ dst.y=src.y;
+ }
+
+ inline Vector2f vec3to2(const Vector3f &src)
+ {
+ return Vector2f(src.x,src.y);
+ }
+
+ inline void vec2to3(Vector3f &dst,const Vector2f &src,const float z)
+ {
+ dst.x=src.x;
+ dst.y=src.y;
+ dst.z=z;
+ }
+
+ inline Vector3f vec2to3(const Vector2f &src,const float z)
+ {
+ return Vector3f(src.x,src.y,z);
+ }
+
+ template
+ inline T normalized(const T &v)
+ {
+ return v.Normalized();
+ }
+
+ template
+ inline void normalize(T &v)
+ {
+ v.Normalize();
+ }
+
+ template
+ inline T cross(const T &v1,const T &v2)
+ {
+ return v1.Cross(v2);
+ }
+
+ template
+ inline float dot(const T &v1,const T &v2)
+ {
+ return v1.Dot(v2);
+ }
+
+ inline float ray_angle_cos(const Ray &ray,const vec &pos)
+ {
+ return ray.dir.Dot((pos-ray.pos).Normalized());
+ }
+
+ inline float length_squared(const Vector2f &v)
+ {
+ return (v.x*v.x) + (v.y*v.y);
+ }
+
+ inline float length_squared_2d(const Vector3f &v)
+ {
+ return (v.x*v.x) + (v.y*v.y);
+ }
+
+ inline float length_squared(const Vector3f &v)
+ {
+ return (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
+ }
+
+ inline float length_squared(const Vector4f &v)
+ {
+ return (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
+ }
+
+ template
+ inline float length(const T &v)
+ {
+ return sqrt(length_squared(v));
+ }
+
+ inline float length_2d(const Vector3f &v)
+ {
+ return sqrt(length_squared_2d(v));
+ }
+
+ template
+ inline float length_squared(const T1 &v1, const T2 &v2)
+ {
+ const float x = (v1.x - v2.x);
+ const float y = (v1.y - v2.y);
+
+ return x*x + y*y;
+ }
+
+ template
+ inline float length(const T1 &v1, const T2 &v2)
+ {
+ return sqrt(length_squared(v1, v2));
+ }
+
+ inline float length_squared(const Vector3f &v1, const Vector3f &v2)
+ {
+ const float x = (v1.x - v2.x);
+ const float y = (v1.y - v2.y);
+ const float z = (v1.z - v2.z);
+
+ return x*x + y*y + z*z;
+ }
+
+ template
+ inline float length_squared_2d(const T1 &v1, const T2 &v2)
+ {
+ const float x = (v1.x - v2.x);
+ const float y = (v1.y - v2.y);
+
+ return x*x + y*y;
+ }
+
+ inline float length(const Vector3f &v1, const Vector3f &v2)
+ {
+ return sqrt(length_squared(v1, v2));
+ }
+
+ template
+ inline float length_2d(const T1 &v1, const T2 &v2)
+ {
+ return sqrt(length_squared_2d(v1, v2));
+ }
+
+ inline Vector2f to(const Vector2f &start, const Vector2f &end, float pos)
+ {
+ return Vector2f(start.x + (end.x - start.x)*pos,
+ start.y + (end.y - start.y)*pos);
+ }
+
+ inline Vector3f to(const Vector3f &start, const Vector3f &end, float pos)
+ {
+ return Vector3f(start.x + (end.x - start.x)*pos,
+ start.y + (end.y - start.y)*pos,
+ start.z + (end.z - start.z)*pos);
+ }
+
+ template
+ inline void to_2d(T &result, const T &start, const T &end, float pos)
+ {
+ result.x = start.x + (end.x - start.x)*pos;
+ result.y = start.y + (end.y - start.y)*pos;
+ }
+
+ inline float ray_angle_cos(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos)
+ {
+ return dot(ray_dir, normalized(pos - ray_pos));
+ }
+
+ /**
+ * 做一个2D旋转计算
+ * @param result 结果
+ * @param source 原始点坐标
+ * @param center 圆心坐标
+ * @param ang 旋转角度
+ */
+ template
+ inline void rotate2d(T1 &result, const T2 &source, const T3 ¢er, const double ang)
+ {
+ double as, ac;
+ // double nx,ny;
+
+ // as=sin(ang*(HGL_PI/180.0f));
+ // ac=cos(ang*(HGL_PI/180.0f));
+ //sincos(ang*(HGL_PI/180.0f),&as,&ac); //在80x87指令上,sin/cos是一个指令同时得出sin和cos,所以可以这样做
+ Lsincos(ang, as, ac); //低精度sin/cos计算
+
+ result.x = center.x + ((source.x - center.x)*ac - (source.y - center.y)*as);
+ result.y = center.y + ((source.x - center.x)*as + (source.y - center.y)*ac);
+ }
+
+ template union vec2
+ {
+ struct { T x,y; };
+ struct { T r,g; };
+ struct { T u,v; };
+ T data[2];
+
+ public:
+
+ vec2(){x=y=0;}
+ vec2(T v1,T v2):x(v1),y(v2){}
+ vec2(const vec2 &v2)
+ {
+ x=v2.x;
+ y=v2.y;
+ }
+
+ vec2(const Vector2f &v2f)
+ {
+ x=v2f.x;
+ y=v2f.y;
+ }
+
+ operator const Vector2f()const{return Vector2f(x,y);}
+ };
+
+ template union vec3
+ {
+ struct { T x,y,z; };
+ struct { T r,g,b; };
+ struct { T u,v,w; };
+ T data[3];
+
+ public:
+
+ vec3(){x=y=z=0;}
+ vec3(T v1,T v2,T v3):x(v1),y(v2),z(v3){}
+ vec3(const vec3 &v3)
+ {
+ x=v3.x;
+ y=v3.y;
+ z=v3.z;
+ }
+
+ vec3(const Vector3f &v3f)
+ {
+ x=v3f.x;
+ y=v3f.y;
+ z=v3f.z;
+
+ return *this;
+ }
+
+ operator const Vector3f()const{return Vector3f(x,y,z);}
+ };
+
+ template union vec4
+ {
+ struct { T x,y,z,w; };
+ struct { T r,g,b,a; };
+ T data[4];
+
+ public:
+
+ vec4(){x=y=z=w=0;}
+ vec4(T v1,T v2,T v3,T v4):x(v1),y(v2),z(v3),w(v4){}
+ vec4(const vec4 &v4)
+ {
+ x=v4.x;
+ y=v4.y;
+ z=v4.z;
+ w=v4.w;
+ }
+
+ vec4(const Vector4f &v4f)
+ {
+ x=v4f.x;
+ y=v4f.y;
+ z=v4f.z;
+ w=v4f.w;
+
+ return *this;
+ }
+
+ operator const Vector4f()const{return Vector4f(x,y,z,w);}
+ };
+}//namespace hgl
+#endif//HGL_ALGORITHM_MATH_VECTOR_INCLUDE
diff --git a/inc/hgl/platform/Exit.h b/inc/hgl/platform/Exit.h
new file mode 100644
index 0000000..33838c2
--- /dev/null
+++ b/inc/hgl/platform/Exit.h
@@ -0,0 +1,10 @@
+#ifndef HGL_EXIT_INCLUDE
+#define HGL_EXIT_INCLUDE
+
+namespace hgl
+{
+ typedef int (*SignalAppExitFunc)(); //程序退出处理事件函数
+
+ void SetSignalAppExit(SignalAppExitFunc); //设置程序退出处理事件函数
+}//namespace hgl
+#endif//HGL_EXIT_INCLUDE
diff --git a/inc/hgl/platform/ExternalModule.h b/inc/hgl/platform/ExternalModule.h
new file mode 100644
index 0000000..97463bf
--- /dev/null
+++ b/inc/hgl/platform/ExternalModule.h
@@ -0,0 +1,36 @@
+#ifndef HGL_EXTERNAL_MODULE_INCLUDE
+#define HGL_EXTERNAL_MODULE_INCLUDE
+
+#include
+#include
+#include OS_EXTERNAL_H
+namespace hgl
+{
+ /**
+ * 这个类用于对外部动态库的调用,支持Windows/Linux/BSD/MacOSX
+ * Windows 下动态库扩展名为.DLL
+ * FreeBSD/MacOSX 下动态库扩展名为.dylib
+ * Linux 下动态库扩展名为.so
+ */
+ class ExternalModule ///外部模块调用类
+ {
+ ExternalModulePointer fp;
+
+ public: //方法
+
+ ExternalModule(); ///<本类构造函数
+ ExternalModule(ExternalModulePointer); ///<本类构造函数
+ virtual ~ExternalModule(); ///<本类析构函数
+
+ bool Load(const os_char *); ///<加载一个外部模块
+ void Clear(); ///<清除当前模块
+
+ void *FindFunc(const char *); ///<查找函数
+ void *GetFunc(const char *); ///<取得函数
+
+ int Get(FuncLoad *); ///<加载函数列表
+ };//class ExternalModule
+
+ ExternalModule *LoadExternalModule(const os_char *); ///<加载一个外部模块
+}//namespace hgl
+#endif//HGL_EXTERNAL_MODULE_INCLUDE
diff --git a/inc/hgl/platform/FuncLoad.h b/inc/hgl/platform/FuncLoad.h
new file mode 100644
index 0000000..8686ee8
--- /dev/null
+++ b/inc/hgl/platform/FuncLoad.h
@@ -0,0 +1,31 @@
+#ifndef HGL_FUNC_LOAD_INCLUDE
+#define HGL_FUNC_LOAD_INCLUDE
+
+namespace hgl
+{
+ /**
+ * 函数加载定义数据结构
+ */
+ struct FuncLoad
+ {
+ char func_name[64]; ///<函数名称
+ void **func_pointer; ///<函数指针
+ };//struct FuncLoad
+
+ #define HGL_FUNC_LOAD_LIST_BEGIN(name) struct FuncLoad name[]={
+ #define HGL_FUNC_LOAD(name) {#name,(void **)&name},
+ #define HGL_FUNC_LOAD_LIST_END {"",(void **)0}};
+
+ inline void ClearFuncLoadPointer(struct FuncLoad *flp)
+ {
+ if(!flp)return;
+
+ while(flp->func_pointer)
+ {
+ flp->func_pointer=(void **)0;
+
+ ++flp;
+ }
+ }
+}//namespace hgl
+#endif//HGL_FUNC_LOAD_INCLUDE
diff --git a/inc/hgl/platform/Platform.h b/inc/hgl/platform/Platform.h
new file mode 100644
index 0000000..43e9522
--- /dev/null
+++ b/inc/hgl/platform/Platform.h
@@ -0,0 +1,334 @@
+#ifndef HGL_PLATFORM_INCLUDE
+#define HGL_PLATFORM_INCLUDE
+
+#ifdef _DEBUG
+ #define HGL_LIB_DEBUG_NAME "Debug"
+#else
+ #define HGL_LIB_DEBUG_NAME "Release"
+#endif//
+
+#define HGL_MERGE32(a,b,c,d) (a|b<<8|c<<16|d<<24)
+
+#define HGL_OS_Windows HGL_MERGE32('W','i','n',' ')
+#define HGL_OS_macOS HGL_MERGE32('m','a','c',' ')
+#define HGL_OS_iOS HGL_MERGE32('i','O','S',' ')
+#define HGL_OS_FreeBSD HGL_MERGE32('F','B','S','D')
+#define HGL_OS_NetBSD HGL_MERGE32('N','B','S','D')
+#define HGL_OS_OpenBSD HGL_MERGE32('O','B','S','D')
+#define HGL_OS_Linux HGL_MERGE32('L','i','n','u')
+#define HGL_OS_Cygwin HGL_MERGE32('C','y','g','w')
+#define HGL_OS_PSP2 HGL_MERGE32('P','S','P','2')
+#define HGL_OS_PS4 HGL_MERGE32('P','S','4',' ')
+#define HGL_OS_AIX HGL_MERGE32('A','I','X',' ')
+#define HGL_OS_Android HGL_MERGE32('A','n','d','r')
+#define HGL_OS_Wasm HGL_MERGE32('W','a','s','m')
+
+#define HGL_CPU_X86_32 HGL_MERGE32('8','6','3','2')
+#define HGL_CPU_X86_64 HGL_MERGE32('8','6','6','4')
+#define HGL_CPU_MIPS HGL_MERGE32('M','I','P','S')
+#define HGL_CPU_MIPSel HGL_MERGE32('M','I','e','l')
+#define HGL_CPU_MIPS64 HGL_MERGE32('M','I','6','4')
+#define HGL_CPU_PowerPC HGL_MERGE32('P','P','C',' ')
+#define HGL_CPU_PowerPC64 HGL_MERGE32('P','P','6','4')
+#define HGL_CPU_Cell HGL_MERGE32('C','E','L','L')
+#define HGL_CPU_ARM7 HGL_MERGE32('A','R','M','7')
+#define HGL_CPU_ARM64 HGL_MERGE32('A','R','6','4')
+
+#define HGL_COMPILER_Microsoft HGL_MERGE32('M','S','C',' ')
+#define HGL_COMPILER_GNU HGL_MERGE32('G','N','U',' ')
+#define HGL_COMPILER_MinGW32 HGL_MERGE32('M','G','3','2')
+#define HGL_COMPILER_Intel HGL_MERGE32('I','n','t','e')
+#define HGL_COMPILER_IBM HGL_MERGE32('I','B','M',' ')
+#define HGL_COMPILER_DigitalMars HGL_MERGE32('D','i','M','a')
+#define HGL_COMPILER_LLVM HGL_MERGE32('L','L','V','M')
+#define HGL_COMPILER_PGI HGL_MERGE32('P','G','I',' ')
+
+#define HGL_BIG_ENDIAN 'B'
+#define HGL_LITTLE_ENDIAN 'L'
+
+#if defined(__amd64__) ||defined(__amd64) || \
+ defined(__x86_64__) ||defined(__x86_64) || \
+ defined(_M_AMD64) ||defined(_M_X64)
+ #define HGL_CPU HGL_CPU_X86_64
+ #define HGL_CPU_NAME OS_TEXT("X86-64Bit")
+ #define HGL_LIB_CPU_NAME OS_TEXT("x64")
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 8
+ #define HGL_ENDIAN HGL_LITTLE_ENDIAN
+#elif defined(i386) || defined(__i386__) || defined(__i386) ||defined(_M_IX86)
+ #define HGL_CPU HGL_CPU_X86_32
+ #define HGL_CPU_NAME OS_TEXT("X86-32Bit")
+ #define HGL_LIB_CPU_NAME OS_TEXT("x86")
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 4
+ #define HGL_ENDIAN HGL_LITTLE_ENDIAN
+#elif defined(_M_MIPS)||defined(_MIPS_ARCH)||defined(__mips__)||defined(__mips)||defined(mips)||defined(__MIPS__)
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 4
+ #ifdef __MIPSEL__
+ #define HGL_CPU HGL_CPU_MIPSel
+ #define HGL_CPU_NAME OS_TEXT("MIPSel")
+ #define HGL_LIB_CPU_NAME OS_TEXT("MIPSel")
+ #define HGL_ENDIAN HGL_LITTLE_ENDIAN
+ #else
+ #define HGL_CPU HGL_CPU_MIPS
+ #define HGL_CPU_NAME OS_TEXT("MIPS")
+ #define HGL_LIB_CPU_NAME OS_TEXT("MIPS")
+ #define HGL_ENDIAN HGL_BIG_ENDIAN
+ #endif//__MIPSEL__
+#elif defined(__mips64__)||defined(mips64)
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 8
+ #define HGL_CPU HGL_CPU_MIPS64
+ #define HGL_CPU_NAME OS_TEXT("MIPS64")
+ #define HGL_LIB_CPU_NAME OS_TEXT("MIPS64")
+ #define HGL_ENDIAN HGL_BIG_ENDIAN
+#elif defined(__powerpc__) || defined(__powerpc) \
+ ||defined(__POWERPC__) \
+ || defined(__ppc__) || defined(__PPC__) || defined(__ppc) \
+ || defined(_M_PPC) ||defined(_M_MPPC) \
+ || defined(_ARCH_PPC) || defined(_ARCH_PWR)
+ #ifdef __PPU__
+ #define HGL_CPU HGL_CPU_Cell
+ #define HGL_CPU_NAME OS_TEXT("Cell")
+ #define HGL_LIB_CPU_NAME OS_TEXT("Cell")
+ #else
+ #ifdef defined(__ppc64__)||defined(__PPC64__)||defined(__powerpc64__) \
+ ||defined(_ARCH_PPC64)||defined(__64BIT__)
+ #define HGL_CPU HGL_CPU_PowerPC64
+ #define HGL_CPU_NAME OS_TEXT("PowerPC64")
+ #define HGL_LIB_CPU_NAME OS_TEXT("PowerPC64")
+ #else
+ #define HGL_CPU HGL_CPU_PowerPC
+ #define HGL_CPU_NAME OS_TEXT("PowerPC")
+ #define HGL_LIB_CPU_NAME OS_TEXT("PowerPC")
+ #endif//PowerPC64
+ #endif
+
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 8
+ #define HGL_ENDIAN HGL_BIG_ENDIAN
+#elif defined(__arm__)||defined(__arm) \
+ ||defined(_ARM) \
+ ||defined(_M_ARM) \
+ ||defined(__ARM_ARCH__7__) \
+ ||defined(__ARM_ARCH__7A__) \
+ ||defined(__ARM_ARCH__7R__) \
+ ||defined(__ARM_ARCH__7M__) \
+ ||defined(__ARM_ARCH__7S__)
+ #define HGL_CPU HGL_CPU_ARM7
+ #define HGL_CPU_NAME OS_TEXT("ARM7")
+ #define HGL_LIB_CPU_NAME OS_TEXT("ARM7")
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 4
+ #define HGL_ENDIAN HGL_LITTLE_ENDIAN
+#elif defined(__aarch64__)
+ #define HGL_CPU HGL_CPU_ARM64
+ #define HGL_CPU_NAME OS_TEXT("ARM64")
+ #define HGL_LIB_CPU_NAME OS_TEXT("ARM64")
+ #define HGL_MIN_MEMORY_ALLOC_BYTES 4
+ #define HGL_ENDIAN HGL_LITTLE_ENDIAN
+#elif defined(__wasm__)
+
+ #error Not support WebAssembly.please wait update......
+
+ #define HGL_OS HGL_OS_Wasm
+ #define HGL_COMPILER HGL_COMPILER_LLVM
+#else
+ #error Not support the cpu.
+#endif
+
+#if HGL_ENDIAN == HGL_BIG_ENDIAN
+ #define HGL_CPU_ENDIAN OS_TEXT("Big Endian")
+#else
+ #define HGL_CPU_ENDIAN OS_TEXT("Little Endian")
+#endif//HGL_ENDIAN == HGL_BIG_ENDIAN
+
+#if defined(__WIN32__)||defined(_WIN32)||defined(WIN32)||defined(__WINDOWS__)||defined(__WIN64__)||defined(_WIN64)||defined(WIN64)
+ #define HGL_OS HGL_OS_Windows
+#elif defined(__APPLE__)||defined(__MAC__)||defined(macintosh)||defined(__APPLE_CC__)
+
+ #define HGL_OS_BSD 1
+
+ #include "TargetConditionals.h"
+ #if TARGET_OS_IPHONE
+ #if TARGET_IPHONE_SIMULATOR
+ #define HGL_OS HGL_OS_iOS_Simulator
+ #else
+ #define HGL_OS HGL_OS_iOS
+ #endif//TARGET_IPHONE_SIMULATOR
+ #elif TARGET_OS_MAC
+ #define HGL_OS HGL_OS_macOS
+ #endif//
+#elif defined(__ANDROID__)
+ #define HGL_OS HGL_OS_Android
+#elif defined(__FreeBSD)||defined(__FreeBSD__)
+ #define HGL_OS HGL_OS_FreeBSD
+ #define HGL_OS_BSD 1
+#elif defined(__NetBSD)||defined(__NetBSD__)
+ #define HGL_OS HGL_OS_NetBSD
+ #define HGL_OS_BSD 1
+#elif defined(__OPENBSD)||defined(__OpenBSD__)
+ #define HGL_OS HGL_OS_OpenBSD
+ #define HGL_OS_BSD 1
+#elif defined(__linux__)||defined(__LINUX__)||defined(linux)||defined(__linux)
+ #define HGL_OS HGL_OS_Linux
+#elif defined(__CYGWIN__)
+ #define HGL_OS HGL_OS_Cygwin
+#elif defined(SN_TARGET_PSP2)||defined(__PSV__)||defined(__psv__)||defined(_PSV)||defined(__PSVita__)||defined(__PSVita)
+ #define HGL_OS HGL_OS_PSP2
+#elif defined(SN_TARGET_ORBIS)
+ #define HGL_OS HGL_OS_PS4
+#elif defined(_AIX)||defined(__AIX)||defined(__AIX__)||defined(__aix)||defined(__aix__)
+ #define HGL_OS HGL_OS_AIX
+#endif//
+
+#if defined(__clang__)
+ #define HGL_COMPILER HGL_COMPILER_LLVM
+#elif defined(__INTEL_COMPILER)||defined(__ECL)||defined(__ICL)||defined(__ICC)
+ #define HGL_COMPILER HGL_COMPILER_Intel
+#elif defined(__IBMC__)||defined(__IBMCPP__)
+ #define HGL_COMPILER HGL_COMPILER_IBM
+#elif defined(__DMC__)||defined(__SC__)||defined(__ZTC__)
+ #define HGL_COMPILER HGL_COMPILER_DigitalMars
+#elif defined(_MSC_VER)
+ #define HGL_COMPILER HGL_COMPILER_Microsoft
+#elif defined(__PGI)
+ #define HGL_COMPILER HGL_COMPILER_PGI
+#elif defined(__MINGW32__)
+ #define HGL_COMPILER HGL_COMPILER_MinGW32
+#elif defined(__GNUC__)
+ #define HGL_COMPILER HGL_COMPILER_GNU
+#else
+ #error Can not support the Compiler.
+#endif//
+
+#if defined(SetEventCall)||defined(SafeCallEvent)||defined(CallEvent)||defined(DefEvent)
+ #error SetEventCall,SafeCallEvent,CallEvent,DefEvent 其中之一已经定义
+#endif//
+
+#if defined(Property)||defined(PropertyRead)||defined(PropertyWrite)
+ #error Property,PropertyRead,PropertyWrite 其中之一已经定义
+#endif//
+
+// #ifndef UNICODE
+// #define UNICODE //定义使用UNICODE编码
+// #endif//UNICODE
+
+#if HGL_OS == HGL_OS_Windows
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_Microsoft
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_Intel
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_IBM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_MINGW32
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif
+
+#elif HGL_OS == HGL_OS_Cygwin
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_LLVM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif//GNU
+
+#elif (HGL_OS == HGL_OS_FreeBSD)||(HGL_OS == HGL_OS_NetBSD)||(HGL_OS == HGL_OS_OpenBSD)
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_LLVM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif//GNU
+
+#elif HGL_OS == HGL_OS_Linux
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_CBuilder
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_Intel
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_IBM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_Watcom
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_LLVM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif
+
+#elif HGL_OS == HGL_OS_macOS
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_Intel
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_LLVM
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif
+
+#elif HGL_OS == HGL_OS_iOS
+
+ #include
+ #include
+
+#elif HGL_OS == HGL_OS_PSP2
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif
+
+#elif HGL_OS == HGL_OS_AIX
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_IBM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_SGI
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif
+
+#elif HGL_OS == HGL_OS_Android
+
+ #include
+
+ #if HGL_COMPILER == HGL_COMPILER_LLVM
+ #include
+ #elif HGL_COMPILER == HGL_COMPILER_GNU
+ #include
+ #else
+ #error Unrecognized compiler
+ #endif//GNU
+#endif//HGL_OS
+
+namespace hgl
+{
+ #define HGL_WINDOW_DIRECTORY_SEPARATOR OS_TEXT('\\')
+ #define HGL_UNIX_DIRECTORY_SPEARATOR OS_TEXT('/')
+}//namespace hgl
+
+#endif//HGL_PLATFORM_INCLUDE
diff --git a/inc/hgl/platform/SystemInfo.h b/inc/hgl/platform/SystemInfo.h
new file mode 100644
index 0000000..ee72268
--- /dev/null
+++ b/inc/hgl/platform/SystemInfo.h
@@ -0,0 +1,69 @@
+#ifndef HGL_SYSTEMINFO_INCLUDE
+#define HGL_SYSTEMINFO_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ /**
+ * 内存信息结构体
+ */
+ struct MemInfo ///内存信息结构体
+ {
+ uint64 AvailPhys; ///<有效物理内存
+ uint64 TotalPhys; ///<总共物理内存
+
+ uint64 AvailPageFile; ///<有效页面文件
+ uint64 TotalPageFile; ///<总共页面文件
+
+ uint64 AvailVirtual; ///<有效虚拟内存
+ uint64 TotalVirtual; ///<总计虚拟内存
+
+ public:
+
+ MemInfo();
+ };//struct MemInfo
+
+ /**
+ * 操作系统及引擎相关路径
+ */
+ struct SystemPath ///操作系统及引擎相关路径
+ {
+ OSString start; ///<当前应用程序起始路径
+
+ OSString os; ///<操作系统路径
+ OSString osfont; ///<操作系统字库路径
+ OSString library; ///<操作系统辅助库路径
+
+ OSString common_data; ///<所有用户共用应用程序数据路径
+ OSString local_data; ///<本地应用程序数据路径
+
+ OSString temp; ///<临时文件路径
+
+ OSString mydata; ///<当前用户应用程序数据保存路径
+ OSString myprogram; ///<“我的程序”路径(Windows下为开始菜单程序路径,Mac下为应用程序路径)
+ OSString mydesktop; ///<“桌面”路径
+
+ OSString desktop; ///<所有用户桌面路径
+
+ OSString engine; ///<引擎所在路径
+ OSString plug_ins; ///<引擎插件路径
+ };//struct SystemPath
+
+ /**
+ * 系统信息
+ */
+ struct SystemInfo ///系统信息结构
+ {
+ MemInfo mem; ///<内存信息
+
+ u16char os_name[256]; ///<操作系统全名
+
+ SystemPath path; ///<系统相关路径
+
+ public:
+
+ SystemInfo();
+ };//struct SystemInfo
+}//namespace hgl
+#endif//HGL_SYSTEMINFO_INCLUDE
diff --git a/inc/hgl/platform/compiler/DataTypeGNU.h b/inc/hgl/platform/compiler/DataTypeGNU.h
new file mode 100644
index 0000000..18b403a
--- /dev/null
+++ b/inc/hgl/platform/compiler/DataTypeGNU.h
@@ -0,0 +1,21 @@
+#ifndef HGL_DATATYPE_GNU_INCLUDE
+#define HGL_DATATYPE_GNU_INCLUDE
+
+namespace hgl
+{
+ using int8 = signed char; ///<有符号 8位整型
+ using uint8 =unsigned char; ///<无符号 8位整型
+ using int16 = signed short; ///<有符号16位整型
+ using uint16 =unsigned short; ///<无符号16位整型
+ using int32 = signed int; ///<有符号32位整型
+ using uint32 =unsigned int; ///<无符号32位整型
+
+ //64位系统下long/long long都是64位,32位系列下只有long long是64位
+
+ using int64 = signed long long; ///<有符号64位整型
+ using uint64 =unsigned long long; ///<无符号64位整型
+
+ using float32 =float;
+ using float64 =double;
+}//namespace hgl
+#endif//HGL_DATATYPE_GNU_INCLUDE
diff --git a/inc/hgl/platform/compiler/DataTypeTiny.h b/inc/hgl/platform/compiler/DataTypeTiny.h
new file mode 100644
index 0000000..2af4d18
--- /dev/null
+++ b/inc/hgl/platform/compiler/DataTypeTiny.h
@@ -0,0 +1,29 @@
+#ifndef HGL_DATA_TYPE_TINY_INCLUDE
+#define HGL_DATA_TYPE_TINY_INCLUDE
+
+namespace hgl
+{
+ using i8=int8;
+ using i16=int16;
+ using i32=int32;
+ using i64=int64;
+
+ using u8=uint8;
+ using u16=uint16;
+ using u32=uint32;
+ using u64=uint64;
+
+ using f32=float;
+ using f64=double;
+
+ #define enum_int(name) enum name:int
+ #define enum_uint(name) enum name:uint
+
+ using void_pointer=void *;
+
+ using uchar = unsigned char; ///< 无符号字符型
+ using ushort = unsigned short; ///< 无符号短整型
+ using uint = unsigned int; ///< 无符号整型
+ using ulong = unsigned long; ///< 无符号长整型
+}//namespace hgl
+#endif//HGL_DATA_TYPE_TINY_INCLUDE
diff --git a/inc/hgl/platform/compiler/DataTypeWin.h b/inc/hgl/platform/compiler/DataTypeWin.h
new file mode 100644
index 0000000..a2a23d1
--- /dev/null
+++ b/inc/hgl/platform/compiler/DataTypeWin.h
@@ -0,0 +1,17 @@
+#ifndef HGL_DATATYPE_WINDOWS_INCLUDE
+#define HGL_DATATYPE_WINDOWS_INCLUDE
+namespace hgl
+{
+ using int8 = signed __int8 ; ///<有符号 8位整型
+ using uint8 =unsigned __int8 ; ///<无符号 8位整型
+ using int16 = signed __int16; ///<有符号16位整型
+ using uint16 =unsigned __int16; ///<无符号16位整型
+ using int32 = signed __int32; ///<有符号32位整型
+ using uint32 =unsigned __int32; ///<无符号32位整型
+ using int64 = signed __int64; ///<有符号64位整型
+ using uint64 =unsigned __int64; ///<无符号64位整型
+
+ using float32 =float;
+ using float64 =double;
+}//namespace hgl
+#endif//HGL_DATATYPE_WINDOWS_INCLUDE
diff --git a/inc/hgl/platform/compiler/EventFunc.h b/inc/hgl/platform/compiler/EventFunc.h
new file mode 100644
index 0000000..7574ec1
--- /dev/null
+++ b/inc/hgl/platform/compiler/EventFunc.h
@@ -0,0 +1,250 @@
+#ifndef HGL_EVENT_FUNC_INCLUDE
+#define HGL_EVENT_FUNC_INCLUDE
+
+#include
+#include
+namespace hgl
+{
+ #ifdef __BORLANDC__
+
+ #define SetEventCall(event_obj,obj_this,class_name,event_func) event_obj=obj_this->class_name::event_func
+ #define SafeCallEvent(event_obj,intro) {if(event_obj)event_obj intro;}
+ #define CallEvent(event_obj,intro) event_obj intro
+ #define DefEvent(result,name,intro) result (__closure *name)intro
+
+ #else
+
+ template struct EventFunc
+ {
+ typedef EventFunc