├── CMakeFiles ├── progress.marks ├── mysqltest.dir │ ├── progress.make │ ├── tests │ │ └── mysqltest.cpp.o │ ├── depend.make │ ├── depend.internal │ ├── link.txt │ ├── cmake_clean.cmake │ ├── flags.make │ ├── CXX.includecache │ ├── DependInfo.cmake │ └── build.make ├── redispool_test.dir │ ├── progress.make │ ├── tests │ │ └── redispool_test.cpp.o │ ├── link.txt │ ├── cmake_clean.cmake │ ├── flags.make │ ├── depend.internal │ ├── depend.make │ ├── DependInfo.cmake │ ├── CXX.includecache │ └── build.make ├── redishelper_test.dir │ ├── progress.make │ ├── tests │ │ └── redishelper_test.cpp.o │ ├── link.txt │ ├── cmake_clean.cmake │ ├── flags.make │ ├── depend.internal │ ├── depend.make │ ├── DependInfo.cmake │ ├── CXX.includecache │ └── build.make ├── cmake.check_cache ├── 3.16.3 │ ├── CompilerIdC │ │ ├── a.out │ │ └── CMakeCCompilerId.c │ ├── CompilerIdCXX │ │ ├── a.out │ │ └── CMakeCXXCompilerId.cpp │ ├── CMakeDetermineCompilerABI_C.bin │ ├── CMakeDetermineCompilerABI_CXX.bin │ ├── CMakeSystem.cmake │ ├── CMakeCCompiler.cmake │ └── CMakeCXXCompiler.cmake ├── 3.18.6 │ ├── CompilerIdC │ │ └── a.out │ ├── CompilerIdCXX │ │ ├── a.out │ │ └── CMakeCXXCompilerId.cpp │ ├── CMakeDetermineCompilerABI_C.bin │ ├── CMakeDetermineCompilerABI_CXX.bin │ ├── CMakeSystem.cmake │ ├── CMakeCCompiler.cmake │ └── CMakeCXXCompiler.cmake ├── TargetDirectories.txt ├── CMakeDirectoryInformation.cmake ├── Makefile.cmake └── Makefile2 ├── hiredis.tar ├── bin ├── mysqltest ├── redispool_test └── redishelper_test ├── tests ├── table_test.cpp ├── mysqltest.cpp ├── redispool_test.cpp └── redishelper_test.cpp ├── CMakeLists.txt ├── MySQLTable.h ├── cmake_install.cmake ├── MySQLHelper.h ├── README.md ├── Makefile ├── CMakeCache.txt ├── RedisHelper.h └── SimConnPool.h /CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /hiredis.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/hiredis.tar -------------------------------------------------------------------------------- /bin/mysqltest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/bin/mysqltest -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | 4 | -------------------------------------------------------------------------------- /bin/redispool_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/bin/redispool_test -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 5 2 | CMAKE_PROGRESS_2 = 6 3 | 4 | -------------------------------------------------------------------------------- /bin/redishelper_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/bin/redishelper_test -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 3 2 | CMAKE_PROGRESS_2 = 4 3 | 4 | -------------------------------------------------------------------------------- /CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CompilerIdC/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.16.3/CompilerIdC/a.out -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CompilerIdCXX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.16.3/CompilerIdCXX/a.out -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CompilerIdC/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.18.6/CompilerIdC/a.out -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CompilerIdCXX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.18.6/CompilerIdCXX/a.out -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.18.6/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/3.18.6/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiaoZixun/ConnPool/HEAD/CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/depend.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o: tests/mysqltest.cpp 5 | 6 | -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/depend.internal: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o 5 | /home/jzx/StudyCpp/ConnPool/tests/mysqltest.cpp 6 | -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/c++ -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -rdynamic CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o -o bin/mysqltest -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpthread -lhiredis -lmysqlcppconn 2 | -------------------------------------------------------------------------------- /CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | /home/jzx/StudyCpp/ConnPool/CMakeFiles/edit_cache.dir 2 | /home/jzx/StudyCpp/ConnPool/CMakeFiles/mysqltest.dir 3 | /home/jzx/StudyCpp/ConnPool/CMakeFiles/rebuild_cache.dir 4 | /home/jzx/StudyCpp/ConnPool/CMakeFiles/redispool_test.dir 5 | /home/jzx/StudyCpp/ConnPool/CMakeFiles/redishelper_test.dir 6 | -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/c++ -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -rdynamic CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o -o bin/redispool_test -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpthread -lhiredis -lmysqlcppconn 2 | -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/c++ -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -rdynamic CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o -o bin/redishelper_test -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lpthread -lhiredis -lmysqlcppconn 2 | -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o" 3 | "bin/mysqltest" 4 | "bin/mysqltest.pdb" 5 | ) 6 | 7 | # Per-language clean rules from dependency scanning. 8 | foreach(lang CXX) 9 | include(CMakeFiles/mysqltest.dir/cmake_clean_${lang}.cmake OPTIONAL) 10 | endforeach() 11 | -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o" 3 | "bin/redispool_test" 4 | "bin/redispool_test.pdb" 5 | ) 6 | 7 | # Per-language clean rules from dependency scanning. 8 | foreach(lang CXX) 9 | include(CMakeFiles/redispool_test.dir/cmake_clean_${lang}.cmake OPTIONAL) 10 | endforeach() 11 | -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o" 3 | "bin/redishelper_test" 4 | "bin/redishelper_test.pdb" 5 | ) 6 | 7 | # Per-language clean rules from dependency scanning. 8 | foreach(lang CXX) 9 | include(CMakeFiles/redishelper_test.dir/cmake_clean_${lang}.cmake OPTIONAL) 10 | endforeach() 11 | -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # compile CXX with /usr/bin/c++ 5 | CXX_FLAGS = -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined 6 | 7 | CXX_DEFINES = 8 | 9 | CXX_INCLUDES = -I/home/jzx/StudyCpp/ConnPool/. 10 | 11 | -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # compile CXX with /usr/bin/c++ 5 | CXX_FLAGS = -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined 6 | 7 | CXX_DEFINES = 8 | 9 | CXX_INCLUDES = -I/home/jzx/StudyCpp/ConnPool/. 10 | 11 | -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # compile CXX with /usr/bin/c++ 5 | CXX_FLAGS = -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined 6 | 7 | CXX_DEFINES = 8 | 9 | CXX_INCLUDES = -I/home/jzx/StudyCpp/ConnPool/. 10 | 11 | -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/CXX.includecache: -------------------------------------------------------------------------------- 1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) 2 | 3 | #IncludeRegexScan: ^.*$ 4 | 5 | #IncludeRegexComplain: ^$ 6 | 7 | #IncludeRegexTransform: 8 | 9 | /home/jzx/StudyCpp/ConnPool/tests/mysqltest.cpp 10 | iostream 11 | - 12 | mysql_connection.h 13 | - 14 | mysql_driver.h 15 | - 16 | cppconn/driver.h 17 | - 18 | cppconn/resultset.h 19 | - 20 | cppconn/statement.h 21 | - 22 | 23 | -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/depend.internal: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o 5 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 6 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 7 | /home/jzx/StudyCpp/ConnPool/tests/redispool_test.cpp 8 | hiredis/alloc.h 9 | hiredis/hiredis.h 10 | hiredis/read.h 11 | hiredis/sds.h 12 | -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/depend.internal: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o 5 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 6 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 7 | /home/jzx/StudyCpp/ConnPool/tests/redishelper_test.cpp 8 | hiredis/alloc.h 9 | hiredis/hiredis.h 10 | hiredis/read.h 11 | hiredis/sds.h 12 | -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Linux-5.4.0-139-generic") 2 | set(CMAKE_HOST_SYSTEM_NAME "Linux") 3 | set(CMAKE_HOST_SYSTEM_VERSION "5.4.0-139-generic") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Linux-5.4.0-139-generic") 9 | set(CMAKE_SYSTEM_NAME "Linux") 10 | set(CMAKE_SYSTEM_VERSION "5.4.0-139-generic") 11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Linux-4.15.0-189-generic") 2 | set(CMAKE_HOST_SYSTEM_NAME "Linux") 3 | set(CMAKE_HOST_SYSTEM_VERSION "4.15.0-189-generic") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Linux-4.15.0-189-generic") 9 | set(CMAKE_SYSTEM_NAME "Linux") 10 | set(CMAKE_SYSTEM_VERSION "4.15.0-189-generic") 11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /tests/table_test.cpp: -------------------------------------------------------------------------------- 1 | #include "MySQLTable.h" 2 | 3 | 4 | 5 | struct per { 6 | int a; 7 | char b; 8 | double c; 9 | }; 10 | 11 | 12 | int main() { 13 | // SimpleConnPool::SET_MEMBER(per, a); 14 | // SimpleConnPool::SET_MEMBER(per, b); 15 | // SimpleConnPool::SET_MEMBER(per, c); 16 | auto t = SimpleConnPool::MyTable(); 17 | t.addMember(SimpleConnPool::SET_MEMBER(per, a)); 18 | t.addMember(SimpleConnPool::SET_MEMBER(per, b)); 19 | t.addMember(SimpleConnPool::SET_MEMBER(per, c)); 20 | 21 | auto x = t.getMembers(); 22 | 23 | for(auto i:x) { 24 | std::cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | 启动mysql:service mysql status 10 | */ 11 | 12 | using namespace std; 13 | using namespace sql; 14 | 15 | int main() { 16 | try { 17 | // 创建MySQL连接 18 | Driver* driver = get_driver_instance(); 19 | Connection* con = driver->connect("tcp://127.0.0.1:3306", "root", "1999223zxc"); 20 | 21 | // 连接到test数据库 22 | con->setSchema("test"); 23 | 24 | // 执行一条查询语句 25 | Statement* stmt = con->createStatement(); 26 | ResultSet* res = stmt->executeQuery("SELECT * FROM user"); 27 | while (res->next()) { 28 | cout << res->getString("name") << endl; 29 | } 30 | 31 | // 清理连接资源 32 | delete res; 33 | delete stmt; 34 | delete con; 35 | } catch (SQLException& e) { 36 | cout << "SQLException: " << e.getErrorCode() << " " << e.what() << endl; 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/CXX.includecache: -------------------------------------------------------------------------------- 1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) 2 | 3 | #IncludeRegexScan: ^.*$ 4 | 5 | #IncludeRegexComplain: ^$ 6 | 7 | #IncludeRegexTransform: 8 | 9 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 10 | hiredis/hiredis.h 11 | - 12 | iostream 13 | - 14 | string 15 | - 16 | cstring 17 | - 18 | memory 19 | - 20 | vector 21 | - 22 | list 23 | - 24 | sstream 25 | - 26 | atomic 27 | - 28 | SimConnPool.h 29 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 30 | 31 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 32 | hiredis/hiredis.h 33 | - 34 | iostream 35 | - 36 | string 37 | - 38 | cstring 39 | - 40 | memory 41 | - 42 | vector 43 | - 44 | list 45 | - 46 | sstream 47 | - 48 | atomic 49 | - 50 | 51 | /home/jzx/StudyCpp/ConnPool/tests/redishelper_test.cpp 52 | ../RedisHelper.h 53 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 54 | iostream 55 | - 56 | memory 57 | - 58 | unistd.h 59 | - 60 | thread 61 | - 62 | 63 | hiredis/alloc.h 64 | stddef.h 65 | - 66 | stdint.h 67 | - 68 | 69 | hiredis/hiredis.h 70 | read.h 71 | hiredis/read.h 72 | stdarg.h 73 | - 74 | sys/time.h 75 | - 76 | stdint.h 77 | - 78 | sds.h 79 | hiredis/sds.h 80 | alloc.h 81 | hiredis/alloc.h 82 | 83 | hiredis/read.h 84 | stdio.h 85 | - 86 | 87 | hiredis/sds.h 88 | sys/types.h 89 | - 90 | stdarg.h 91 | - 92 | stdint.h 93 | - 94 | 95 | -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/CXX.includecache: -------------------------------------------------------------------------------- 1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) 2 | 3 | #IncludeRegexScan: ^.*$ 4 | 5 | #IncludeRegexComplain: ^$ 6 | 7 | #IncludeRegexTransform: 8 | 9 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 10 | hiredis/hiredis.h 11 | - 12 | iostream 13 | - 14 | string 15 | - 16 | cstring 17 | - 18 | memory 19 | - 20 | vector 21 | - 22 | list 23 | - 24 | sstream 25 | - 26 | atomic 27 | - 28 | SimConnPool.h 29 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 30 | 31 | /home/jzx/StudyCpp/ConnPool/SimConnPool.h 32 | hiredis/hiredis.h 33 | - 34 | iostream 35 | - 36 | string 37 | - 38 | cstring 39 | - 40 | memory 41 | - 42 | vector 43 | - 44 | list 45 | - 46 | sstream 47 | - 48 | atomic 49 | - 50 | 51 | /home/jzx/StudyCpp/ConnPool/tests/redispool_test.cpp 52 | ../RedisHelper.h 53 | /home/jzx/StudyCpp/ConnPool/RedisHelper.h 54 | iostream 55 | - 56 | memory 57 | - 58 | unistd.h 59 | - 60 | thread 61 | - 62 | 63 | hiredis/alloc.h 64 | stddef.h 65 | - 66 | stdint.h 67 | - 68 | 69 | hiredis/hiredis.h 70 | read.h 71 | hiredis/read.h 72 | stdarg.h 73 | - 74 | sys/time.h 75 | - 76 | stdint.h 77 | - 78 | sds.h 79 | hiredis/sds.h 80 | alloc.h 81 | hiredis/alloc.h 82 | 83 | hiredis/read.h 84 | stdio.h 85 | - 86 | 87 | hiredis/sds.h 88 | sys/types.h 89 | - 90 | stdarg.h 91 | - 92 | stdint.h 93 | - 94 | 95 | -------------------------------------------------------------------------------- /MySQLTable.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYLAR_MYSQLTABLE_H_ 2 | #define _SYLAR_MYSQLTABLE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | 15 | namespace SimpleConnPool { 16 | 17 | class MyTable; 18 | // 宏来访问结构体成员 19 | #define SET_MEMBER(structType, memberName) \ 20 | MyTable::setMember(#memberName, &structType::memberName) 21 | 22 | 23 | 24 | class MyTable { 25 | public: 26 | MyTable() {} 27 | ~MyTable() {} 28 | 29 | template 30 | static std::pair setMember(const char* memberName, MemberType StructType::*memberPtr) { 31 | //std::cout<(memberName, abi::__cxa_demangle(typeid(MemberType).name(),0,0,0 )); 33 | } 34 | 35 | void addMember(std::pair&& member) { 36 | m_table.emplace_back(member); 37 | } 38 | 39 | std::vector>& getMembers() { 40 | return m_table; 41 | } 42 | 43 | private: 44 | std::vector> m_table; 45 | }; 46 | 47 | 48 | 49 | } 50 | 51 | 52 | #endif -------------------------------------------------------------------------------- /cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /home/jzx/StudyCpp/ConnPool 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "/usr/local") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Install shared libraries without execute permission? 31 | if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) 32 | set(CMAKE_INSTALL_SO_NO_EXE "1") 33 | endif() 34 | 35 | # Is this installation the result of a crosscompile? 36 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 37 | set(CMAKE_CROSSCOMPILING "FALSE") 38 | endif() 39 | 40 | if(CMAKE_INSTALL_COMPONENT) 41 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 42 | else() 43 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 44 | endif() 45 | 46 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT 47 | "${CMAKE_INSTALL_MANIFEST_FILES}") 48 | file(WRITE "/home/jzx/StudyCpp/ConnPool/${CMAKE_INSTALL_MANIFEST}" 49 | "${CMAKE_INSTALL_MANIFEST_CONTENT}") 50 | -------------------------------------------------------------------------------- /CMakeFiles/Makefile.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # The generator used is: 5 | set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") 6 | 7 | # The top level Makefile was generated from the following files: 8 | set(CMAKE_MAKEFILE_DEPENDS 9 | "CMakeCache.txt" 10 | "CMakeFiles/3.16.3/CMakeCCompiler.cmake" 11 | "CMakeFiles/3.16.3/CMakeCXXCompiler.cmake" 12 | "CMakeFiles/3.16.3/CMakeSystem.cmake" 13 | "CMakeLists.txt" 14 | "/usr/share/cmake-3.16/Modules/CMakeCInformation.cmake" 15 | "/usr/share/cmake-3.16/Modules/CMakeCXXInformation.cmake" 16 | "/usr/share/cmake-3.16/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake" 17 | "/usr/share/cmake-3.16/Modules/CMakeCommonLanguageInclude.cmake" 18 | "/usr/share/cmake-3.16/Modules/CMakeGenericSystem.cmake" 19 | "/usr/share/cmake-3.16/Modules/CMakeInitializeConfigs.cmake" 20 | "/usr/share/cmake-3.16/Modules/CMakeLanguageInformation.cmake" 21 | "/usr/share/cmake-3.16/Modules/CMakeSystemSpecificInformation.cmake" 22 | "/usr/share/cmake-3.16/Modules/CMakeSystemSpecificInitialize.cmake" 23 | "/usr/share/cmake-3.16/Modules/Compiler/CMakeCommonCompilerMacros.cmake" 24 | "/usr/share/cmake-3.16/Modules/Compiler/GNU-C.cmake" 25 | "/usr/share/cmake-3.16/Modules/Compiler/GNU-CXX.cmake" 26 | "/usr/share/cmake-3.16/Modules/Compiler/GNU.cmake" 27 | "/usr/share/cmake-3.16/Modules/Internal/CMakeCheckCompilerFlag.cmake" 28 | "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU-C.cmake" 29 | "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU-CXX.cmake" 30 | "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU.cmake" 31 | "/usr/share/cmake-3.16/Modules/Platform/Linux.cmake" 32 | "/usr/share/cmake-3.16/Modules/Platform/UnixPaths.cmake" 33 | ) 34 | 35 | # The corresponding makefile is: 36 | set(CMAKE_MAKEFILE_OUTPUTS 37 | "Makefile" 38 | "CMakeFiles/cmake.check_cache" 39 | ) 40 | 41 | # Byproducts of CMake generate step: 42 | set(CMAKE_MAKEFILE_PRODUCTS 43 | "CMakeFiles/CMakeDirectoryInformation.cmake" 44 | ) 45 | 46 | # Dependency information for all targets: 47 | set(CMAKE_DEPEND_INFO_FILES 48 | "CMakeFiles/mysqltest.dir/DependInfo.cmake" 49 | "CMakeFiles/redispool_test.dir/DependInfo.cmake" 50 | "CMakeFiles/redishelper_test.dir/DependInfo.cmake" 51 | ) 52 | -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "/usr/bin/cc") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "GNU") 4 | set(CMAKE_C_COMPILER_VERSION "9.4.0") 5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_C_COMPILER_WRAPPER "") 7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11") 8 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert") 9 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") 10 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") 11 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") 12 | 13 | set(CMAKE_C_PLATFORM_ID "Linux") 14 | set(CMAKE_C_SIMULATE_ID "") 15 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") 16 | set(CMAKE_C_SIMULATE_VERSION "") 17 | 18 | 19 | 20 | set(CMAKE_AR "/usr/bin/ar") 21 | set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar-9") 22 | set(CMAKE_RANLIB "/usr/bin/ranlib") 23 | set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9") 24 | set(CMAKE_LINKER "/usr/bin/ld") 25 | set(CMAKE_MT "") 26 | set(CMAKE_COMPILER_IS_GNUCC 1) 27 | set(CMAKE_C_COMPILER_LOADED 1) 28 | set(CMAKE_C_COMPILER_WORKS TRUE) 29 | set(CMAKE_C_ABI_COMPILED TRUE) 30 | set(CMAKE_COMPILER_IS_MINGW ) 31 | set(CMAKE_COMPILER_IS_CYGWIN ) 32 | if(CMAKE_COMPILER_IS_CYGWIN) 33 | set(CYGWIN 1) 34 | set(UNIX 1) 35 | endif() 36 | 37 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 38 | 39 | if(CMAKE_COMPILER_IS_MINGW) 40 | set(MINGW 1) 41 | endif() 42 | set(CMAKE_C_COMPILER_ID_RUN 1) 43 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 44 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 45 | set(CMAKE_C_LINKER_PREFERENCE 10) 46 | 47 | # Save compiler ABI information. 48 | set(CMAKE_C_SIZEOF_DATA_PTR "8") 49 | set(CMAKE_C_COMPILER_ABI "ELF") 50 | set(CMAKE_C_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 51 | 52 | if(CMAKE_C_SIZEOF_DATA_PTR) 53 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 54 | endif() 55 | 56 | if(CMAKE_C_COMPILER_ABI) 57 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 58 | endif() 59 | 60 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 61 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 62 | endif() 63 | 64 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 65 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 66 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 67 | endif() 68 | 69 | 70 | 71 | 72 | 73 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") 74 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s") 75 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") 76 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 77 | -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "/usr/bin/cc") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "GNU") 4 | set(CMAKE_C_COMPILER_VERSION "11.1.0") 5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_C_COMPILER_WRAPPER "") 7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11") 8 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert") 9 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") 10 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") 11 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") 12 | 13 | set(CMAKE_C_PLATFORM_ID "Linux") 14 | set(CMAKE_C_SIMULATE_ID "") 15 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") 16 | set(CMAKE_C_SIMULATE_VERSION "") 17 | 18 | 19 | 20 | 21 | set(CMAKE_AR "/usr/bin/ar") 22 | set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar-11") 23 | set(CMAKE_RANLIB "/usr/bin/ranlib") 24 | set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib-11") 25 | set(CMAKE_LINKER "/usr/bin/ld") 26 | set(CMAKE_MT "") 27 | set(CMAKE_COMPILER_IS_GNUCC 1) 28 | set(CMAKE_C_COMPILER_LOADED 1) 29 | set(CMAKE_C_COMPILER_WORKS TRUE) 30 | set(CMAKE_C_ABI_COMPILED TRUE) 31 | set(CMAKE_COMPILER_IS_MINGW ) 32 | set(CMAKE_COMPILER_IS_CYGWIN ) 33 | if(CMAKE_COMPILER_IS_CYGWIN) 34 | set(CYGWIN 1) 35 | set(UNIX 1) 36 | endif() 37 | 38 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 39 | 40 | if(CMAKE_COMPILER_IS_MINGW) 41 | set(MINGW 1) 42 | endif() 43 | set(CMAKE_C_COMPILER_ID_RUN 1) 44 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 45 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 46 | set(CMAKE_C_LINKER_PREFERENCE 10) 47 | 48 | # Save compiler ABI information. 49 | set(CMAKE_C_SIZEOF_DATA_PTR "8") 50 | set(CMAKE_C_COMPILER_ABI "ELF") 51 | set(CMAKE_C_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 52 | 53 | if(CMAKE_C_SIZEOF_DATA_PTR) 54 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 55 | endif() 56 | 57 | if(CMAKE_C_COMPILER_ABI) 58 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 59 | endif() 60 | 61 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 62 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 63 | endif() 64 | 65 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 66 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 67 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 68 | endif() 69 | 70 | 71 | 72 | 73 | 74 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/11/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") 75 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s") 76 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/11;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") 77 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 78 | -------------------------------------------------------------------------------- /MySQLHelper.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYLAR_MYSQLHELPER_H_ 2 | #define _SYLAR_MYSQLHELPER_H_ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "SimConnPool.h" 11 | 12 | 13 | namespace SimpleConnPool { 14 | 15 | 16 | class MysqlHelper; 17 | //mysql连接池 单例 18 | typedef ConnPool MysqlPool; 19 | typedef Singleton MysqlConnPoolMgr; 20 | 21 | /* 22 | mysql相关操作 23 | */ 24 | class MysqlHelper : public std::enable_shared_from_this, public MysqlPool{ 25 | public: 26 | typedef std::shared_ptr ptr; 27 | typedef Mutex MutexType; 28 | 29 | MysqlHelper() 30 | : m_host("") 31 | , m_pwd("") 32 | , m_user("") { 33 | m_con = NULL; 34 | m_pool = MysqlConnPoolMgr::GetInstance(); 35 | std::cout << "初始化完成!" << std::endl; 36 | } 37 | ~MysqlHelper() { 38 | std::cout << "destory MysqlHelper::~MysqlHelper()" << std::endl; 39 | simRelease(); 40 | } 41 | 42 | // 放回连接 43 | void connBack() { 44 | //std::cout << "1111" << std::endl; 45 | std::shared_ptr x = shared_from_this(); 46 | //std::cout << "connBack use_count:" << x.use_count() << std::endl; 47 | m_pool->back(x); 48 | } 49 | 50 | // 连接mysql数据库 51 | bool simpleConn(const std::string& host, const std::string& user, const std::string& pwd) { 52 | m_host = host; 53 | m_user = user; 54 | m_pwd = pwd; 55 | sql::Driver* driver = get_driver_instance(); 56 | m_con = driver->connect(m_host.c_str(), m_user.c_str(), m_pwd.c_str()); 57 | if(!m_con) { 58 | m_error_msg = "m_con is null"; 59 | std::cout << "connection error! errstr:" << m_error_msg << std::endl; 60 | return false; 61 | } 62 | m_error_msg = "ok"; 63 | std::cout << "redis connection is ok!" << std::endl; 64 | return true; 65 | } 66 | 67 | void setDatabase(const std::string& database) { 68 | m_con->setSchema(database.c_str()); 69 | } 70 | 71 | // 通过模板T推导出 T对象包含的成员变量名字, 72 | // 然后根据这个名字拿到mysql结果的值,再转为原本的型别 73 | // 反射 74 | 75 | 76 | 77 | 78 | private: 79 | // 释放单条连接 80 | void simRelease() { 81 | delete m_con; 82 | delete m_pool; 83 | m_pool = NULL; 84 | } 85 | 86 | private: 87 | std::string m_host; 88 | std::string m_pwd; 89 | std::string m_user; 90 | 91 | sql::Connection* m_con; 92 | 93 | std::string m_error_msg; 94 | 95 | MysqlPool* m_pool; 96 | MutexType m_mutex; 97 | 98 | 99 | }; 100 | 101 | 102 | } 103 | #endif -------------------------------------------------------------------------------- /CMakeFiles/mysqltest.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | 15 | # Remove some rules from gmake that .SUFFIXES does not remove. 16 | SUFFIXES = 17 | 18 | .SUFFIXES: .hpux_make_needs_suffix_list 19 | 20 | 21 | # Produce verbose output by default. 22 | VERBOSE = 1 23 | 24 | # Suppress display of executed commands. 25 | $(VERBOSE).SILENT: 26 | 27 | 28 | # A target that is always out of date. 29 | cmake_force: 30 | 31 | .PHONY : cmake_force 32 | 33 | #============================================================================= 34 | # Set environment variables for the build. 35 | 36 | # The shell in which to execute make rules. 37 | SHELL = /bin/sh 38 | 39 | # The CMake executable. 40 | CMAKE_COMMAND = /usr/bin/cmake 41 | 42 | # The command to remove a file. 43 | RM = /usr/bin/cmake -E remove -f 44 | 45 | # Escaping for special characters. 46 | EQUALS = = 47 | 48 | # The top-level source directory on which CMake was run. 49 | CMAKE_SOURCE_DIR = /home/jzx/StudyCpp/ConnPool 50 | 51 | # The top-level build directory on which CMake was run. 52 | CMAKE_BINARY_DIR = /home/jzx/StudyCpp/ConnPool 53 | 54 | # Include any dependencies generated for this target. 55 | include CMakeFiles/mysqltest.dir/depend.make 56 | 57 | # Include the progress variables for this target. 58 | include CMakeFiles/mysqltest.dir/progress.make 59 | 60 | # Include the compile flags for this target's objects. 61 | include CMakeFiles/mysqltest.dir/flags.make 62 | 63 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o: CMakeFiles/mysqltest.dir/flags.make 64 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o: tests/mysqltest.cpp 65 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o" 66 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o -c /home/jzx/StudyCpp/ConnPool/tests/mysqltest.cpp 67 | 68 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.i: cmake_force 69 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.i" 70 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/jzx/StudyCpp/ConnPool/tests/mysqltest.cpp > CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.i 71 | 72 | CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.s: cmake_force 73 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.s" 74 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/jzx/StudyCpp/ConnPool/tests/mysqltest.cpp -o CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.s 75 | 76 | # Object files for target mysqltest 77 | mysqltest_OBJECTS = \ 78 | "CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o" 79 | 80 | # External object files for target mysqltest 81 | mysqltest_EXTERNAL_OBJECTS = 82 | 83 | bin/mysqltest: CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o 84 | bin/mysqltest: CMakeFiles/mysqltest.dir/build.make 85 | bin/mysqltest: CMakeFiles/mysqltest.dir/link.txt 86 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable bin/mysqltest" 87 | $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/mysqltest.dir/link.txt --verbose=$(VERBOSE) 88 | 89 | # Rule to build all files generated by this target. 90 | CMakeFiles/mysqltest.dir/build: bin/mysqltest 91 | 92 | .PHONY : CMakeFiles/mysqltest.dir/build 93 | 94 | CMakeFiles/mysqltest.dir/clean: 95 | $(CMAKE_COMMAND) -P CMakeFiles/mysqltest.dir/cmake_clean.cmake 96 | .PHONY : CMakeFiles/mysqltest.dir/clean 97 | 98 | CMakeFiles/mysqltest.dir/depend: 99 | cd /home/jzx/StudyCpp/ConnPool && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool/CMakeFiles/mysqltest.dir/DependInfo.cmake --color=$(COLOR) 100 | .PHONY : CMakeFiles/mysqltest.dir/depend 101 | 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redis连接池 2 | 3 | 4 | 5 | > 封装hiredis的一些基本操作,redishelper类提供包含连接,放回,存取键,push,pop,执行redis语句和执行lua脚本的函数,连接池是类模板,传入相应helper类即可实现多种连接池,后续实现mysql连接池。 6 | 7 | ## 编译项目 8 | 9 | 1. 安装hiredis,解压文件中hiredis.tar(后续对源码进行了改动,文件中是改后的) 10 | 11 | ```shell 12 | tar -xvf hiredis.tar 13 | cd hiredis/ 14 | make 15 | make install # 权限不足加上sudo 16 | ``` 17 | 18 | 2. 删除之前的CMakeCache.txt 19 | 20 | ```shell 21 | cd ConnPool/ 22 | rm CMakeCache.txt 23 | ``` 24 | 25 | 3. 重新cmake和make 26 | 27 | ```shell 28 | cmake . 29 | make -j4 30 | ``` 31 | 32 | 4. 后续引入头文件SimConnPool.h即可使用,简单应用见tests文件 33 | 34 | ## 整体架构 35 | 1. RedisHelper:redis相关操作,创建一个连接时构造函数不做任何事,在connection函数时才真正建立一条连接,每条连接都包含一个指向连接池的指针,为了实现放回操作,基础实现依赖hiredis库中的redisCommand函数 36 | 2. ConnPool :连接池模板,初始化时构造函数不做任何操作,在连接池connection时才执行init函数完成每一个连接的初始化,并且依次调用每条连接的connection函数 37 | 3. Singleton:单例模板,包装ConnPool类,变成单例对象 38 | 39 | 40 | ## 使用 41 | 42 | ```c++ 43 | static SimpleConnPool::redisPool* pool = SimpleConnPool::redisConnPoolMgr::GetInstance(); // 获取一个连接池单例对象,默认5个连接 44 | pool->connection("127.0.0.1", 6000); // 连接池内连接上redis,入参:ip、端口号、密码默认为空 45 | SimpleConnPool::redisPool::connPtr conn = pool->get(); // 取出一条连接 46 | // TODO 47 | conn->connBack(); // 放回连接 48 | 49 | ``` 50 | 51 | ## 分布式锁 52 | 53 | > 当多线程并发访问数据库中某个资源时,可能同一时间返回都取到了旧值,并且对旧值进行变更,这样会造成逻辑上的混淆。比如在电商场景,库存这个变量,当多个用户进行抢购的时候,首先判断库存然后库存减一,若不加锁,库存为1的时候,可能多个用户获取库存判断时都拿到了1,最后都进行库存减一,可能就出现负数了。 54 | 55 | 在分布式系统环境下,一个方法在同一时间只能被一个机器的一个线程执行 56 | 57 | 高可用的获取锁与释放锁 58 | 59 | 具备可重入特性(可理解为重新进入,由多于一个任务并发使用,而不必担心数据错误) 60 | 61 | 具备锁失效机制,即自动解锁,防止死锁 62 | 63 | 64 | 65 | 加锁: 66 | 67 | 实际是,对一个键进行赋值,借助set key val NX PX timeout 语句实现,NX表示若键存在返回nil,不存在则赋值,当多线程运行到lock时,只有第一个执行语句的线程可以跳出,继续执行,其余线程都需要阻塞在lock内部。 68 | 69 | 设置超时时间为了保证不会因为加锁线程挂掉而导致死锁的情况。 70 | 71 | ```c++ 72 | /* 73 | 加锁逻辑: 74 | 在不存在键时设置键 并同时设置超时时间 保证原子性 75 | set key value NX PX timeout 76 | 默认10秒 77 | 返回该线程拿到锁生成的值,后续解锁比较,不能因为挂机或网络原因解锁别的线程锁 78 | 分布式锁的键为:redis.lock 值为:当前时间戳 nsec 79 | */ 80 | std::string lock(uint64_t timeout = 30000) { 81 | while(1) { 82 | struct timespec time = {0, 0}; 83 | clock_gettime(CLOCK_REALTIME, &time); 84 | std::string uuid = std::to_string(time.tv_nsec); 85 | std::string cmd = "set redis.lock " + uuid + " NX PX " + std::to_string(timeout); 86 | std::string flag; 87 | RedisState sta; 88 | { 89 | MutexType::Lock lock(m_mutex); 90 | sta = execute(cmd, &flag); 91 | } 92 | if(sta == RedisState::M_REDIS_OK) { 93 | std::cout << "get redis.lock!" << std::endl; 94 | return uuid; 95 | } 96 | } 97 | } 98 | ``` 99 | 100 | 解锁: 101 | 102 | 需要取值、判断、删除三个操作,因此使用lua脚本来保证原子性,判断是为了保证不会删除其余线程所创建的锁。 103 | 104 | ```c++ 105 | /* 106 | 解锁逻辑: 107 | 获取锁,判断锁,删除锁 108 | 为了保证原子性,使用lua脚本来完成三个操作 109 | redis使用eval "xxxx" keys数量 key1 key2 num1 num2 110 | */ 111 | void unlock(const std::string& uuid) { 112 | std::string cmd = "eval \"if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end\" 1 redis.lock " + uuid; 113 | int flag; 114 | RedisState sta = executeLua(cmd.c_str(), &flag); 115 | if(sta == RedisState::M_REDIS_OK && flag > 0) { 116 | std::cout << "获取到锁并解锁" << std::endl; 117 | } 118 | else { 119 | std::cout << "未获取到锁 errstr: " << m_error_msg << std::endl; 120 | } 121 | return ; 122 | } 123 | ``` 124 | 125 | 126 | 127 | ## 总结 128 | 129 | 基于hiredis,只需要引入头文件即可使用,简单方便,复杂语句使用execute函数直接执行,但是需要根据redis客户端返回值,传入该函数第二个参数(set,get返回ok就传string,del返回1或0就传int) 130 | 131 | 为了可以执行lua脚本,对hiredis中源码进行了改动,原先是以空格来分割命令的,但是lua脚本需要return时肯定包含空格,需要更改分割规则,增加以双引号分割,详见([hiredis中lua脚本调用_hiredis lua_suhiymof的博客-CSDN博客](https://blog.csdn.net/suhiymof/article/details/54847818)) 132 | 133 | ```c++ 134 | std::string cmd = "EVAL \"redis.call('SET', KEYS[1], ARGV[1]) local result = redis.call('get',KEYS[1]) return result\" 1 foo1 bar1"; 135 | std::string flag; // set get为string类型,del为int类型,看redis客户端返回的类型设置 136 | conn->executeLua(cmd.c_str(), &flag); 137 | std::cout << "lua执行结果:" << flag << std::endl; 138 | ``` 139 | 140 | 141 | 142 | 帮助大家熟悉C++和redis的基本操作,使用lua脚本实现了简单的分布式锁,可以多线程的访问数据库中某个变量 143 | 144 | 还缺少健康检测,自动扩缩容等实现,大家有需要可以继续开发 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /tests/redispool_test.cpp: -------------------------------------------------------------------------------- 1 | #include "../RedisHelper.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | static SimpleConnPool::redisPool* pool = SimpleConnPool::redisConnPoolMgr::GetInstance(); 9 | 10 | void init() { 11 | pool->connection("127.0.0.1", 6000); 12 | } 13 | 14 | void test_set() { 15 | std::cout << "test_set begin!" << std::endl; 16 | SimpleConnPool::redisPool::connPtr conn = pool->get(); 17 | while(conn == nullptr) { 18 | conn = pool->get(); 19 | } 20 | conn->setSimple("kkk", "100"); 21 | conn->connBack(); // 需要显示放回链接 22 | std::cout << "test_set end!" << std::endl; 23 | } 24 | 25 | // 测试获取连接向队列插入元素 26 | void test_list() { 27 | std::cout << "test_list begin!" << std::endl; 28 | SimpleConnPool::redisPool::connPtr conn = pool->get(); 29 | while(conn == nullptr) { 30 | conn = pool->get(); 31 | } 32 | conn->push("list", "1"); 33 | conn->push("list", {"a", "b", "c", "d"}); 34 | std::string res; 35 | conn->pop("list", res); 36 | std::cout << "取出的元素:" << res << std::endl; 37 | conn->connBack(); // 需要显示放回链接 38 | std::cout << "test_list end!" << std::endl; 39 | } 40 | 41 | //测试分布式锁 42 | void test_mutex() { 43 | std::cout << "test_mutex begin!" << std::endl; 44 | SimpleConnPool::redisPool::connPtr conn = pool->get(); 45 | while(conn == nullptr) { 46 | conn = pool->get(); 47 | } 48 | { 49 | std::string lockres = conn->lock(); 50 | std::string res = ""; 51 | conn->getSimple("kkk", res); 52 | std::cout << "结果: " << res << std::endl; 53 | //conn->pop("list2", res); 54 | std::string newval = std::to_string(std::stoi(res) - 1); 55 | conn->setSimple("kkk", newval); 56 | conn->unlock(lockres); 57 | } 58 | conn->connBack(); 59 | std::cout << "test_mutex end!" << std::endl; 60 | } 61 | 62 | // 测试执行lua脚本 63 | void test_exeLua() { 64 | std::cout << "test_exeLua begin!" << std::endl; 65 | SimpleConnPool::redisPool::connPtr conn = pool->get(); 66 | while(conn == nullptr) { 67 | conn = pool->get(); 68 | } 69 | std::string cmd = "EVAL \"redis.call('SET', KEYS[1], ARGV[1]) local result = redis.call('get',KEYS[1]) return result\" 1 foo1 bar1"; 70 | std::string flag; // set get为string类型,del为int类型,看redis客户端返回的类型设置 71 | conn->executeLua(cmd.c_str(), &flag); 72 | std::cout << "lua执行结果:" << flag << std::endl; 73 | conn->connBack(); 74 | std::cout << "test_exeLua end!" << std::endl; 75 | } 76 | 77 | int run() { 78 | std::cout << "run begin!" << std::endl; 79 | { 80 | SimpleConnPool::redisPool::connPtr conn = pool->get(); 81 | //std::cout << "after get use_count:" << conn.use_count() << std::endl; 82 | while(conn == nullptr) { 83 | //std::cout << "too many connection!" <get(); 86 | } 87 | //conn->push("list2", "1"); 88 | // 使用分布式锁 89 | { 90 | std::string lockres = conn->lock(); 91 | std::string res = ""; 92 | conn->getSimple("kkk", res); 93 | std::cout << "结果: " << res << std::endl; 94 | //conn->pop("list2", res); 95 | std::string newval = std::to_string(std::stoi(res) - 1); 96 | conn->setSimple("kkk", newval); 97 | conn->unlock(lockres); 98 | } 99 | /* 100 | // 测试执行lua脚本 101 | std::string flag; 102 | conn->executeLua("eval \"if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end\" 1 redis.lock 980848849", &flag); 103 | std::cout << conn->getError() << std::endl; 104 | std::cout << flag << std::endl; 105 | */ 106 | conn->connBack(); 107 | //std::cout << "end! " << pool->getFreeNum() << std::endl; 108 | } 109 | // 提前结束:必须等待工作连接全部转为空闲时才能停止 110 | /* 111 | if(pool->getFreeNum() == 5) 112 | pool->stop(); 113 | */ 114 | std::cout << "run end!" << std::endl; 115 | return 0; 116 | } 117 | 118 | int main() { 119 | /*单线程*/ 120 | init(); 121 | // 测试set 122 | test_set(); 123 | // 测试list 124 | test_list(); 125 | // 测试分布式锁 126 | test_mutex(); 127 | // 测试lua脚本 128 | test_exeLua(); 129 | 130 | /*多线程测试*/ 131 | int threadnum = 50; 132 | std::vector threads(threadnum); 133 | for(int i = 0; i < threadnum; ++i) { 134 | threads[i] = std::thread(run); 135 | } 136 | for(int i = 0; i < threadnum; ++i) { 137 | threads[i].join(); 138 | } 139 | return 0; 140 | } -------------------------------------------------------------------------------- /CMakeFiles/redispool_test.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | 15 | # Remove some rules from gmake that .SUFFIXES does not remove. 16 | SUFFIXES = 17 | 18 | .SUFFIXES: .hpux_make_needs_suffix_list 19 | 20 | 21 | # Produce verbose output by default. 22 | VERBOSE = 1 23 | 24 | # Suppress display of executed commands. 25 | $(VERBOSE).SILENT: 26 | 27 | 28 | # A target that is always out of date. 29 | cmake_force: 30 | 31 | .PHONY : cmake_force 32 | 33 | #============================================================================= 34 | # Set environment variables for the build. 35 | 36 | # The shell in which to execute make rules. 37 | SHELL = /bin/sh 38 | 39 | # The CMake executable. 40 | CMAKE_COMMAND = /usr/bin/cmake 41 | 42 | # The command to remove a file. 43 | RM = /usr/bin/cmake -E remove -f 44 | 45 | # Escaping for special characters. 46 | EQUALS = = 47 | 48 | # The top-level source directory on which CMake was run. 49 | CMAKE_SOURCE_DIR = /home/jzx/StudyCpp/ConnPool 50 | 51 | # The top-level build directory on which CMake was run. 52 | CMAKE_BINARY_DIR = /home/jzx/StudyCpp/ConnPool 53 | 54 | # Include any dependencies generated for this target. 55 | include CMakeFiles/redispool_test.dir/depend.make 56 | 57 | # Include the progress variables for this target. 58 | include CMakeFiles/redispool_test.dir/progress.make 59 | 60 | # Include the compile flags for this target's objects. 61 | include CMakeFiles/redispool_test.dir/flags.make 62 | 63 | CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o: CMakeFiles/redispool_test.dir/flags.make 64 | CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o: tests/redispool_test.cpp 65 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o" 66 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o -c /home/jzx/StudyCpp/ConnPool/tests/redispool_test.cpp 67 | 68 | CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.i: cmake_force 69 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.i" 70 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/jzx/StudyCpp/ConnPool/tests/redispool_test.cpp > CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.i 71 | 72 | CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.s: cmake_force 73 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.s" 74 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/jzx/StudyCpp/ConnPool/tests/redispool_test.cpp -o CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.s 75 | 76 | # Object files for target redispool_test 77 | redispool_test_OBJECTS = \ 78 | "CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o" 79 | 80 | # External object files for target redispool_test 81 | redispool_test_EXTERNAL_OBJECTS = 82 | 83 | bin/redispool_test: CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o 84 | bin/redispool_test: CMakeFiles/redispool_test.dir/build.make 85 | bin/redispool_test: CMakeFiles/redispool_test.dir/link.txt 86 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable bin/redispool_test" 87 | $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/redispool_test.dir/link.txt --verbose=$(VERBOSE) 88 | 89 | # Rule to build all files generated by this target. 90 | CMakeFiles/redispool_test.dir/build: bin/redispool_test 91 | 92 | .PHONY : CMakeFiles/redispool_test.dir/build 93 | 94 | CMakeFiles/redispool_test.dir/clean: 95 | $(CMAKE_COMMAND) -P CMakeFiles/redispool_test.dir/cmake_clean.cmake 96 | .PHONY : CMakeFiles/redispool_test.dir/clean 97 | 98 | CMakeFiles/redispool_test.dir/depend: 99 | cd /home/jzx/StudyCpp/ConnPool && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool/CMakeFiles/redispool_test.dir/DependInfo.cmake --color=$(COLOR) 100 | .PHONY : CMakeFiles/redispool_test.dir/depend 101 | 102 | -------------------------------------------------------------------------------- /CMakeFiles/redishelper_test.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | 15 | # Remove some rules from gmake that .SUFFIXES does not remove. 16 | SUFFIXES = 17 | 18 | .SUFFIXES: .hpux_make_needs_suffix_list 19 | 20 | 21 | # Produce verbose output by default. 22 | VERBOSE = 1 23 | 24 | # Suppress display of executed commands. 25 | $(VERBOSE).SILENT: 26 | 27 | 28 | # A target that is always out of date. 29 | cmake_force: 30 | 31 | .PHONY : cmake_force 32 | 33 | #============================================================================= 34 | # Set environment variables for the build. 35 | 36 | # The shell in which to execute make rules. 37 | SHELL = /bin/sh 38 | 39 | # The CMake executable. 40 | CMAKE_COMMAND = /usr/bin/cmake 41 | 42 | # The command to remove a file. 43 | RM = /usr/bin/cmake -E remove -f 44 | 45 | # Escaping for special characters. 46 | EQUALS = = 47 | 48 | # The top-level source directory on which CMake was run. 49 | CMAKE_SOURCE_DIR = /home/jzx/StudyCpp/ConnPool 50 | 51 | # The top-level build directory on which CMake was run. 52 | CMAKE_BINARY_DIR = /home/jzx/StudyCpp/ConnPool 53 | 54 | # Include any dependencies generated for this target. 55 | include CMakeFiles/redishelper_test.dir/depend.make 56 | 57 | # Include the progress variables for this target. 58 | include CMakeFiles/redishelper_test.dir/progress.make 59 | 60 | # Include the compile flags for this target's objects. 61 | include CMakeFiles/redishelper_test.dir/flags.make 62 | 63 | CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o: CMakeFiles/redishelper_test.dir/flags.make 64 | CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o: tests/redishelper_test.cpp 65 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o" 66 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o -c /home/jzx/StudyCpp/ConnPool/tests/redishelper_test.cpp 67 | 68 | CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.i: cmake_force 69 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.i" 70 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/jzx/StudyCpp/ConnPool/tests/redishelper_test.cpp > CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.i 71 | 72 | CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.s: cmake_force 73 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.s" 74 | /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/jzx/StudyCpp/ConnPool/tests/redishelper_test.cpp -o CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.s 75 | 76 | # Object files for target redishelper_test 77 | redishelper_test_OBJECTS = \ 78 | "CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o" 79 | 80 | # External object files for target redishelper_test 81 | redishelper_test_EXTERNAL_OBJECTS = 82 | 83 | bin/redishelper_test: CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o 84 | bin/redishelper_test: CMakeFiles/redishelper_test.dir/build.make 85 | bin/redishelper_test: CMakeFiles/redishelper_test.dir/link.txt 86 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable bin/redishelper_test" 87 | $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/redishelper_test.dir/link.txt --verbose=$(VERBOSE) 88 | 89 | # Rule to build all files generated by this target. 90 | CMakeFiles/redishelper_test.dir/build: bin/redishelper_test 91 | 92 | .PHONY : CMakeFiles/redishelper_test.dir/build 93 | 94 | CMakeFiles/redishelper_test.dir/clean: 95 | $(CMAKE_COMMAND) -P CMakeFiles/redishelper_test.dir/cmake_clean.cmake 96 | .PHONY : CMakeFiles/redishelper_test.dir/clean 97 | 98 | CMakeFiles/redishelper_test.dir/depend: 99 | cd /home/jzx/StudyCpp/ConnPool && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool /home/jzx/StudyCpp/ConnPool/CMakeFiles/redishelper_test.dir/DependInfo.cmake --color=$(COLOR) 100 | .PHONY : CMakeFiles/redishelper_test.dir/depend 101 | 102 | -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CMakeCXXCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_COMPILER "/usr/bin/c++") 2 | set(CMAKE_CXX_COMPILER_ARG1 "") 3 | set(CMAKE_CXX_COMPILER_ID "GNU") 4 | set(CMAKE_CXX_COMPILER_VERSION "9.4.0") 5 | set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_CXX_COMPILER_WRAPPER "") 7 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14") 8 | set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") 9 | set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") 10 | set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") 11 | set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") 12 | set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") 13 | set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") 14 | 15 | set(CMAKE_CXX_PLATFORM_ID "Linux") 16 | set(CMAKE_CXX_SIMULATE_ID "") 17 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") 18 | set(CMAKE_CXX_SIMULATE_VERSION "") 19 | 20 | 21 | 22 | set(CMAKE_AR "/usr/bin/ar") 23 | set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar-9") 24 | set(CMAKE_RANLIB "/usr/bin/ranlib") 25 | set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9") 26 | set(CMAKE_LINKER "/usr/bin/ld") 27 | set(CMAKE_MT "") 28 | set(CMAKE_COMPILER_IS_GNUCXX 1) 29 | set(CMAKE_CXX_COMPILER_LOADED 1) 30 | set(CMAKE_CXX_COMPILER_WORKS TRUE) 31 | set(CMAKE_CXX_ABI_COMPILED TRUE) 32 | set(CMAKE_COMPILER_IS_MINGW ) 33 | set(CMAKE_COMPILER_IS_CYGWIN ) 34 | if(CMAKE_COMPILER_IS_CYGWIN) 35 | set(CYGWIN 1) 36 | set(UNIX 1) 37 | endif() 38 | 39 | set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") 40 | 41 | if(CMAKE_COMPILER_IS_MINGW) 42 | set(MINGW 1) 43 | endif() 44 | set(CMAKE_CXX_COMPILER_ID_RUN 1) 45 | set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP) 46 | set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) 47 | 48 | foreach (lang C OBJC OBJCXX) 49 | if (CMAKE_${lang}_COMPILER_ID_RUN) 50 | foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) 51 | list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) 52 | endforeach() 53 | endif() 54 | endforeach() 55 | 56 | set(CMAKE_CXX_LINKER_PREFERENCE 30) 57 | set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) 58 | 59 | # Save compiler ABI information. 60 | set(CMAKE_CXX_SIZEOF_DATA_PTR "8") 61 | set(CMAKE_CXX_COMPILER_ABI "ELF") 62 | set(CMAKE_CXX_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 63 | 64 | if(CMAKE_CXX_SIZEOF_DATA_PTR) 65 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") 66 | endif() 67 | 68 | if(CMAKE_CXX_COMPILER_ABI) 69 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") 70 | endif() 71 | 72 | if(CMAKE_CXX_LIBRARY_ARCHITECTURE) 73 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 74 | endif() 75 | 76 | set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "") 77 | if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) 78 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") 79 | endif() 80 | 81 | 82 | 83 | 84 | 85 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/9;/usr/include/x86_64-linux-gnu/c++/9;/usr/include/c++/9/backward;/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") 86 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc") 87 | set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") 88 | set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 89 | -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CMakeCXXCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_COMPILER "/usr/bin/c++") 2 | set(CMAKE_CXX_COMPILER_ARG1 "") 3 | set(CMAKE_CXX_COMPILER_ID "GNU") 4 | set(CMAKE_CXX_COMPILER_VERSION "11.1.0") 5 | set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_CXX_COMPILER_WRAPPER "") 7 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "17") 8 | set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") 9 | set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") 10 | set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") 11 | set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") 12 | set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") 13 | set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") 14 | 15 | set(CMAKE_CXX_PLATFORM_ID "Linux") 16 | set(CMAKE_CXX_SIMULATE_ID "") 17 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") 18 | set(CMAKE_CXX_SIMULATE_VERSION "") 19 | 20 | 21 | 22 | 23 | set(CMAKE_AR "/usr/bin/ar") 24 | set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar-11") 25 | set(CMAKE_RANLIB "/usr/bin/ranlib") 26 | set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib-11") 27 | set(CMAKE_LINKER "/usr/bin/ld") 28 | set(CMAKE_MT "") 29 | set(CMAKE_COMPILER_IS_GNUCXX 1) 30 | set(CMAKE_CXX_COMPILER_LOADED 1) 31 | set(CMAKE_CXX_COMPILER_WORKS TRUE) 32 | set(CMAKE_CXX_ABI_COMPILED TRUE) 33 | set(CMAKE_COMPILER_IS_MINGW ) 34 | set(CMAKE_COMPILER_IS_CYGWIN ) 35 | if(CMAKE_COMPILER_IS_CYGWIN) 36 | set(CYGWIN 1) 37 | set(UNIX 1) 38 | endif() 39 | 40 | set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") 41 | 42 | if(CMAKE_COMPILER_IS_MINGW) 43 | set(MINGW 1) 44 | endif() 45 | set(CMAKE_CXX_COMPILER_ID_RUN 1) 46 | set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP) 47 | set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) 48 | 49 | foreach (lang C OBJC OBJCXX) 50 | if (CMAKE_${lang}_COMPILER_ID_RUN) 51 | foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) 52 | list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) 53 | endforeach() 54 | endif() 55 | endforeach() 56 | 57 | set(CMAKE_CXX_LINKER_PREFERENCE 30) 58 | set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) 59 | 60 | # Save compiler ABI information. 61 | set(CMAKE_CXX_SIZEOF_DATA_PTR "8") 62 | set(CMAKE_CXX_COMPILER_ABI "ELF") 63 | set(CMAKE_CXX_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 64 | 65 | if(CMAKE_CXX_SIZEOF_DATA_PTR) 66 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") 67 | endif() 68 | 69 | if(CMAKE_CXX_COMPILER_ABI) 70 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") 71 | endif() 72 | 73 | if(CMAKE_CXX_LIBRARY_ARCHITECTURE) 74 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 75 | endif() 76 | 77 | set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "") 78 | if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) 79 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") 80 | endif() 81 | 82 | 83 | 84 | 85 | 86 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/11;/usr/include/x86_64-linux-gnu/c++/11;/usr/include/c++/11/backward;/usr/lib/gcc/x86_64-linux-gnu/11/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") 87 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc") 88 | set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/11;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") 89 | set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 90 | -------------------------------------------------------------------------------- /tests/redishelper_test.cpp: -------------------------------------------------------------------------------- 1 | #include "../RedisHelper.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | int run(const std::string& threadname = "") { 9 | std::cout << "进入线程: " << threadname << std::endl; 10 | // conn 11 | // sylar::RedisHelper::ptr rediscon = std::make_shared(); 12 | auto rediscon = SimpleConnPool::RedisHelper::ptr(new SimpleConnPool::RedisHelper()); 13 | if(!rediscon->simpleConn("127.0.0.1", 6000)) { 14 | std::cout << "redis connection error! errstr:" << rediscon->getError() << std::endl; 15 | return 0; 16 | } 17 | 18 | /* 19 | // set 20 | sylar::RedisState replystate = rediscon->setSimple("test", "edf"); 21 | if(replystate != sylar::RedisState::M_REDIS_OK) { 22 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 23 | return 0; 24 | } 25 | replystate = rediscon->setSimple("test1", "abc"); 26 | if(replystate != sylar::RedisState::M_REDIS_OK) { 27 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 28 | return 0; 29 | } 30 | replystate = rediscon->setSimple("test2", "abc"); 31 | if(replystate != sylar::RedisState::M_REDIS_OK) { 32 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 33 | return 0; 34 | } 35 | 36 | replystate = rediscon->setSimple("test3", "111"); 37 | if(replystate != sylar::RedisState::M_REDIS_OK) { 38 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 39 | return 0; 40 | } 41 | 42 | 43 | 44 | // get 45 | std::string result; 46 | replystate = rediscon->getSimple("test", result); 47 | if(replystate != sylar::RedisState::M_REDIS_OK) { 48 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 49 | return 0; 50 | } 51 | std::cout << "test: " << result << std::endl; 52 | 53 | std::string result1; 54 | replystate = rediscon->getSimple("test1", result1); 55 | if(replystate != sylar::RedisState::M_REDIS_OK) { 56 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 57 | return 0; 58 | } 59 | std::cout << "test1: " << result1 << std::endl; 60 | 61 | std::string result2; 62 | replystate = rediscon->getSimple("test2", result2); 63 | if(replystate != sylar::RedisState::M_REDIS_OK) { 64 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 65 | return 0; 66 | } 67 | std::cout << "test2: " << result2 << std::endl; 68 | 69 | std::string result3; 70 | replystate = rediscon->getSimple("test3", result3); 71 | if(replystate != sylar::RedisState::M_REDIS_OK) { 72 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 73 | return 0; 74 | } 75 | std::cout << "test3: " << result3 << std::endl; 76 | 77 | 78 | std::string result4; 79 | replystate = rediscon->getSimple("test4", result4); 80 | if(replystate != sylar::RedisState::M_REDIS_OK) { 81 | std::cout << "redis reple error! errstr:" << rediscon->getError() << std::endl; 82 | return 0; 83 | } 84 | std::cout << "test4: " << result4 << std::endl; 85 | 86 | std::cout << "之前:" << std::endl; 87 | std::vector res = rediscon->getAllKeys(); 88 | for(auto x:res) { 89 | std::cout << x << " "; 90 | } 91 | std::cout << std::endl; 92 | 93 | 94 | // 设置超时时间 95 | if(rediscon->setKeyTimeout("test", 100)) { 96 | std::cout << "设置超时时间" << std::endl; 97 | sleep(10); 98 | // 获取超时时间 99 | int64_t timeout = rediscon->getKeyTimeout("test"); 100 | std::cout << "剩余超时时间:" << timeout << std::endl; 101 | 102 | if(rediscon->delKeyTimeout("test")) { 103 | std::cout << "移除超时时间" << std::endl; 104 | } 105 | } 106 | 107 | // 是否存在键 108 | if(rediscon->isExists("test")) { 109 | std::cout << "存在" << std::endl; 110 | } 111 | else { 112 | std::cout << "不存在" << std::endl; 113 | } 114 | 115 | // 改名 116 | if(rediscon->reName("test", "test")) { 117 | std::cout << "test -> test 成功" << std::endl; 118 | } 119 | else { 120 | std::cout << "test -> test 失败" << std::endl; 121 | } 122 | 123 | if(rediscon->reName("test", "test5")) { 124 | std::cout << "test -> test5 成功" << std::endl; 125 | } 126 | else { 127 | std::cout << "test -> test5 失败" << std::endl; 128 | } 129 | 130 | rediscon->delSimple("test1"); 131 | 132 | std::cout << "之前:" << std::endl; 133 | res = rediscon->getAllKeys(); 134 | for(auto x:res) { 135 | std::cout << x << " "; 136 | } 137 | std::cout << std::endl; 138 | */ 139 | 140 | rediscon->push("list1", "a"); 141 | rediscon->push("list1", "b"); 142 | rediscon->push("list1", "c"); 143 | rediscon->push("list1", "d"); 144 | 145 | rediscon->push("list2", {"1", "2", "3", "4", "5"}); 146 | /* 147 | while(1) { 148 | std::string res = ""; 149 | rediscon->pop("list1", res); 150 | if(res != "") { 151 | std::cout << threadname << " 存在数据:" << res << std::endl; 152 | } 153 | } 154 | */ 155 | /* 156 | auto func = [](sylar::RedisHelper::ptr rediscon, const std::string& thread_name){ 157 | while(1) { 158 | std::string res = ""; 159 | rediscon->pop("list1", res); 160 | if(res != "") { 161 | std::cout << thread_name << "中存在数据:" << res << std::endl; 162 | } 163 | } 164 | }; 165 | std::thread t1(func, rediscon, "t1"); 166 | std::thread t2(func, rediscon, "t2"); 167 | t1.join(); 168 | t2.join(); 169 | */ 170 | std::cout << "finish!" << std::endl; 171 | std::cout << "rediscon引用计数: " << rediscon.use_count() << std::endl; 172 | rediscon->connBack(); 173 | std::cout << "离开线程" << threadname << std::endl; 174 | return 0; 175 | } 176 | 177 | int main() { 178 | std::cout << "start!" << std::endl; 179 | /* 180 | std::thread t1(run, "t1"); 181 | std::thread t2(run, "t2"); 182 | t1.join(); 183 | t2.join(); 184 | */ 185 | run(); 186 | std::cout << "end" << std::endl; 187 | return 0; 188 | } -------------------------------------------------------------------------------- /CMakeFiles/Makefile2: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | 7 | .PHONY : default_target 8 | 9 | #============================================================================= 10 | # Special targets provided by cmake. 11 | 12 | # Disable implicit rules so canonical targets will work. 13 | .SUFFIXES: 14 | 15 | 16 | # Remove some rules from gmake that .SUFFIXES does not remove. 17 | SUFFIXES = 18 | 19 | .SUFFIXES: .hpux_make_needs_suffix_list 20 | 21 | 22 | # Produce verbose output by default. 23 | VERBOSE = 1 24 | 25 | # Suppress display of executed commands. 26 | $(VERBOSE).SILENT: 27 | 28 | 29 | # A target that is always out of date. 30 | cmake_force: 31 | 32 | .PHONY : cmake_force 33 | 34 | #============================================================================= 35 | # Set environment variables for the build. 36 | 37 | # The shell in which to execute make rules. 38 | SHELL = /bin/sh 39 | 40 | # The CMake executable. 41 | CMAKE_COMMAND = /usr/bin/cmake 42 | 43 | # The command to remove a file. 44 | RM = /usr/bin/cmake -E remove -f 45 | 46 | # Escaping for special characters. 47 | EQUALS = = 48 | 49 | # The top-level source directory on which CMake was run. 50 | CMAKE_SOURCE_DIR = /home/jzx/StudyCpp/ConnPool 51 | 52 | # The top-level build directory on which CMake was run. 53 | CMAKE_BINARY_DIR = /home/jzx/StudyCpp/ConnPool 54 | 55 | #============================================================================= 56 | # Directory level rules for the build root directory 57 | 58 | # The main recursive "all" target. 59 | all: CMakeFiles/mysqltest.dir/all 60 | all: CMakeFiles/redispool_test.dir/all 61 | all: CMakeFiles/redishelper_test.dir/all 62 | 63 | .PHONY : all 64 | 65 | # The main recursive "preinstall" target. 66 | preinstall: 67 | 68 | .PHONY : preinstall 69 | 70 | # The main recursive "clean" target. 71 | clean: CMakeFiles/mysqltest.dir/clean 72 | clean: CMakeFiles/redispool_test.dir/clean 73 | clean: CMakeFiles/redishelper_test.dir/clean 74 | 75 | .PHONY : clean 76 | 77 | #============================================================================= 78 | # Target rules for target CMakeFiles/mysqltest.dir 79 | 80 | # All Build rule for target. 81 | CMakeFiles/mysqltest.dir/all: 82 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/depend 83 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/build 84 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=1,2 "Built target mysqltest" 85 | .PHONY : CMakeFiles/mysqltest.dir/all 86 | 87 | # Build rule for subdir invocation for target. 88 | CMakeFiles/mysqltest.dir/rule: cmake_check_build_system 89 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 2 90 | $(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/mysqltest.dir/all 91 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 0 92 | .PHONY : CMakeFiles/mysqltest.dir/rule 93 | 94 | # Convenience name for target. 95 | mysqltest: CMakeFiles/mysqltest.dir/rule 96 | 97 | .PHONY : mysqltest 98 | 99 | # clean rule for target. 100 | CMakeFiles/mysqltest.dir/clean: 101 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/clean 102 | .PHONY : CMakeFiles/mysqltest.dir/clean 103 | 104 | #============================================================================= 105 | # Target rules for target CMakeFiles/redispool_test.dir 106 | 107 | # All Build rule for target. 108 | CMakeFiles/redispool_test.dir/all: 109 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/depend 110 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/build 111 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=5,6 "Built target redispool_test" 112 | .PHONY : CMakeFiles/redispool_test.dir/all 113 | 114 | # Build rule for subdir invocation for target. 115 | CMakeFiles/redispool_test.dir/rule: cmake_check_build_system 116 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 2 117 | $(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/redispool_test.dir/all 118 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 0 119 | .PHONY : CMakeFiles/redispool_test.dir/rule 120 | 121 | # Convenience name for target. 122 | redispool_test: CMakeFiles/redispool_test.dir/rule 123 | 124 | .PHONY : redispool_test 125 | 126 | # clean rule for target. 127 | CMakeFiles/redispool_test.dir/clean: 128 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/clean 129 | .PHONY : CMakeFiles/redispool_test.dir/clean 130 | 131 | #============================================================================= 132 | # Target rules for target CMakeFiles/redishelper_test.dir 133 | 134 | # All Build rule for target. 135 | CMakeFiles/redishelper_test.dir/all: 136 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/depend 137 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/build 138 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/jzx/StudyCpp/ConnPool/CMakeFiles --progress-num=3,4 "Built target redishelper_test" 139 | .PHONY : CMakeFiles/redishelper_test.dir/all 140 | 141 | # Build rule for subdir invocation for target. 142 | CMakeFiles/redishelper_test.dir/rule: cmake_check_build_system 143 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 2 144 | $(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/redishelper_test.dir/all 145 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 0 146 | .PHONY : CMakeFiles/redishelper_test.dir/rule 147 | 148 | # Convenience name for target. 149 | redishelper_test: CMakeFiles/redishelper_test.dir/rule 150 | 151 | .PHONY : redishelper_test 152 | 153 | # clean rule for target. 154 | CMakeFiles/redishelper_test.dir/clean: 155 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/clean 156 | .PHONY : CMakeFiles/redishelper_test.dir/clean 157 | 158 | #============================================================================= 159 | # Special targets to cleanup operation of make. 160 | 161 | # Special rule to run CMake to check the build system integrity. 162 | # No rule that depends on this can have commands that come from listfiles 163 | # because they might be regenerated. 164 | cmake_check_build_system: 165 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 166 | .PHONY : cmake_check_build_system 167 | 168 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.16 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | 7 | .PHONY : default_target 8 | 9 | # Allow only one "make -f Makefile2" at a time, but pass parallelism. 10 | .NOTPARALLEL: 11 | 12 | 13 | #============================================================================= 14 | # Special targets provided by cmake. 15 | 16 | # Disable implicit rules so canonical targets will work. 17 | .SUFFIXES: 18 | 19 | 20 | # Remove some rules from gmake that .SUFFIXES does not remove. 21 | SUFFIXES = 22 | 23 | .SUFFIXES: .hpux_make_needs_suffix_list 24 | 25 | 26 | # Produce verbose output by default. 27 | VERBOSE = 1 28 | 29 | # Suppress display of executed commands. 30 | $(VERBOSE).SILENT: 31 | 32 | 33 | # A target that is always out of date. 34 | cmake_force: 35 | 36 | .PHONY : cmake_force 37 | 38 | #============================================================================= 39 | # Set environment variables for the build. 40 | 41 | # The shell in which to execute make rules. 42 | SHELL = /bin/sh 43 | 44 | # The CMake executable. 45 | CMAKE_COMMAND = /usr/bin/cmake 46 | 47 | # The command to remove a file. 48 | RM = /usr/bin/cmake -E remove -f 49 | 50 | # Escaping for special characters. 51 | EQUALS = = 52 | 53 | # The top-level source directory on which CMake was run. 54 | CMAKE_SOURCE_DIR = /home/jzx/StudyCpp/ConnPool 55 | 56 | # The top-level build directory on which CMake was run. 57 | CMAKE_BINARY_DIR = /home/jzx/StudyCpp/ConnPool 58 | 59 | #============================================================================= 60 | # Targets provided globally by CMake. 61 | 62 | # Special rule for the target edit_cache 63 | edit_cache: 64 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." 65 | /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. 66 | .PHONY : edit_cache 67 | 68 | # Special rule for the target edit_cache 69 | edit_cache/fast: edit_cache 70 | 71 | .PHONY : edit_cache/fast 72 | 73 | # Special rule for the target rebuild_cache 74 | rebuild_cache: 75 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." 76 | /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 77 | .PHONY : rebuild_cache 78 | 79 | # Special rule for the target rebuild_cache 80 | rebuild_cache/fast: rebuild_cache 81 | 82 | .PHONY : rebuild_cache/fast 83 | 84 | # The main all target 85 | all: cmake_check_build_system 86 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles /home/jzx/StudyCpp/ConnPool/CMakeFiles/progress.marks 87 | $(MAKE) -f CMakeFiles/Makefile2 all 88 | $(CMAKE_COMMAND) -E cmake_progress_start /home/jzx/StudyCpp/ConnPool/CMakeFiles 0 89 | .PHONY : all 90 | 91 | # The main clean target 92 | clean: 93 | $(MAKE) -f CMakeFiles/Makefile2 clean 94 | .PHONY : clean 95 | 96 | # The main clean target 97 | clean/fast: clean 98 | 99 | .PHONY : clean/fast 100 | 101 | # Prepare targets for installation. 102 | preinstall: all 103 | $(MAKE) -f CMakeFiles/Makefile2 preinstall 104 | .PHONY : preinstall 105 | 106 | # Prepare targets for installation. 107 | preinstall/fast: 108 | $(MAKE) -f CMakeFiles/Makefile2 preinstall 109 | .PHONY : preinstall/fast 110 | 111 | # clear depends 112 | depend: 113 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 114 | .PHONY : depend 115 | 116 | #============================================================================= 117 | # Target rules for targets named mysqltest 118 | 119 | # Build rule for target. 120 | mysqltest: cmake_check_build_system 121 | $(MAKE) -f CMakeFiles/Makefile2 mysqltest 122 | .PHONY : mysqltest 123 | 124 | # fast build rule for target. 125 | mysqltest/fast: 126 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/build 127 | .PHONY : mysqltest/fast 128 | 129 | #============================================================================= 130 | # Target rules for targets named redispool_test 131 | 132 | # Build rule for target. 133 | redispool_test: cmake_check_build_system 134 | $(MAKE) -f CMakeFiles/Makefile2 redispool_test 135 | .PHONY : redispool_test 136 | 137 | # fast build rule for target. 138 | redispool_test/fast: 139 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/build 140 | .PHONY : redispool_test/fast 141 | 142 | #============================================================================= 143 | # Target rules for targets named redishelper_test 144 | 145 | # Build rule for target. 146 | redishelper_test: cmake_check_build_system 147 | $(MAKE) -f CMakeFiles/Makefile2 redishelper_test 148 | .PHONY : redishelper_test 149 | 150 | # fast build rule for target. 151 | redishelper_test/fast: 152 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/build 153 | .PHONY : redishelper_test/fast 154 | 155 | tests/mysqltest.o: tests/mysqltest.cpp.o 156 | 157 | .PHONY : tests/mysqltest.o 158 | 159 | # target to build an object file 160 | tests/mysqltest.cpp.o: 161 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.o 162 | .PHONY : tests/mysqltest.cpp.o 163 | 164 | tests/mysqltest.i: tests/mysqltest.cpp.i 165 | 166 | .PHONY : tests/mysqltest.i 167 | 168 | # target to preprocess a source file 169 | tests/mysqltest.cpp.i: 170 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.i 171 | .PHONY : tests/mysqltest.cpp.i 172 | 173 | tests/mysqltest.s: tests/mysqltest.cpp.s 174 | 175 | .PHONY : tests/mysqltest.s 176 | 177 | # target to generate assembly for a file 178 | tests/mysqltest.cpp.s: 179 | $(MAKE) -f CMakeFiles/mysqltest.dir/build.make CMakeFiles/mysqltest.dir/tests/mysqltest.cpp.s 180 | .PHONY : tests/mysqltest.cpp.s 181 | 182 | tests/redishelper_test.o: tests/redishelper_test.cpp.o 183 | 184 | .PHONY : tests/redishelper_test.o 185 | 186 | # target to build an object file 187 | tests/redishelper_test.cpp.o: 188 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.o 189 | .PHONY : tests/redishelper_test.cpp.o 190 | 191 | tests/redishelper_test.i: tests/redishelper_test.cpp.i 192 | 193 | .PHONY : tests/redishelper_test.i 194 | 195 | # target to preprocess a source file 196 | tests/redishelper_test.cpp.i: 197 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.i 198 | .PHONY : tests/redishelper_test.cpp.i 199 | 200 | tests/redishelper_test.s: tests/redishelper_test.cpp.s 201 | 202 | .PHONY : tests/redishelper_test.s 203 | 204 | # target to generate assembly for a file 205 | tests/redishelper_test.cpp.s: 206 | $(MAKE) -f CMakeFiles/redishelper_test.dir/build.make CMakeFiles/redishelper_test.dir/tests/redishelper_test.cpp.s 207 | .PHONY : tests/redishelper_test.cpp.s 208 | 209 | tests/redispool_test.o: tests/redispool_test.cpp.o 210 | 211 | .PHONY : tests/redispool_test.o 212 | 213 | # target to build an object file 214 | tests/redispool_test.cpp.o: 215 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.o 216 | .PHONY : tests/redispool_test.cpp.o 217 | 218 | tests/redispool_test.i: tests/redispool_test.cpp.i 219 | 220 | .PHONY : tests/redispool_test.i 221 | 222 | # target to preprocess a source file 223 | tests/redispool_test.cpp.i: 224 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.i 225 | .PHONY : tests/redispool_test.cpp.i 226 | 227 | tests/redispool_test.s: tests/redispool_test.cpp.s 228 | 229 | .PHONY : tests/redispool_test.s 230 | 231 | # target to generate assembly for a file 232 | tests/redispool_test.cpp.s: 233 | $(MAKE) -f CMakeFiles/redispool_test.dir/build.make CMakeFiles/redispool_test.dir/tests/redispool_test.cpp.s 234 | .PHONY : tests/redispool_test.cpp.s 235 | 236 | # Help Target 237 | help: 238 | @echo "The following are some of the valid targets for this Makefile:" 239 | @echo "... all (the default if no target is provided)" 240 | @echo "... clean" 241 | @echo "... depend" 242 | @echo "... edit_cache" 243 | @echo "... mysqltest" 244 | @echo "... rebuild_cache" 245 | @echo "... redispool_test" 246 | @echo "... redishelper_test" 247 | @echo "... tests/mysqltest.o" 248 | @echo "... tests/mysqltest.i" 249 | @echo "... tests/mysqltest.s" 250 | @echo "... tests/redishelper_test.o" 251 | @echo "... tests/redishelper_test.i" 252 | @echo "... tests/redishelper_test.s" 253 | @echo "... tests/redispool_test.o" 254 | @echo "... tests/redispool_test.i" 255 | @echo "... tests/redispool_test.s" 256 | .PHONY : help 257 | 258 | 259 | 260 | #============================================================================= 261 | # Special targets to cleanup operation of make. 262 | 263 | # Special rule to run CMake to check the build system integrity. 264 | # No rule that depends on this can have commands that come from listfiles 265 | # because they might be regenerated. 266 | cmake_check_build_system: 267 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 268 | .PHONY : cmake_check_build_system 269 | 270 | -------------------------------------------------------------------------------- /CMakeCache.txt: -------------------------------------------------------------------------------- 1 | # This is the CMakeCache file. 2 | # For build in directory: /home/jzx/StudyCpp/ConnPool 3 | # It was generated by CMake: /usr/bin/cmake 4 | # You can edit this file to change values found and used by cmake. 5 | # If you do not want to change any of the values, simply exit the editor. 6 | # If you do want to change a value, simply edit, save, and exit the editor. 7 | # The syntax for the file is as follows: 8 | # KEY:TYPE=VALUE 9 | # KEY is the name of a variable in the cache. 10 | # TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. 11 | # VALUE is the current value for the KEY. 12 | 13 | ######################## 14 | # EXTERNAL cache entries 15 | ######################## 16 | 17 | //Path to a program. 18 | CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line 19 | 20 | //Path to a program. 21 | CMAKE_AR:FILEPATH=/usr/bin/ar 22 | 23 | //Choose the type of build, options are: None Debug Release RelWithDebInfo 24 | // MinSizeRel ... 25 | CMAKE_BUILD_TYPE:STRING= 26 | 27 | //Enable/Disable color output during build. 28 | CMAKE_COLOR_MAKEFILE:BOOL=ON 29 | 30 | //CXX compiler 31 | CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ 32 | 33 | //A wrapper around 'ar' adding the appropriate '--plugin' option 34 | // for the GCC compiler 35 | CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 36 | 37 | //A wrapper around 'ranlib' adding the appropriate '--plugin' option 38 | // for the GCC compiler 39 | CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 40 | 41 | //Flags used by the CXX compiler during all build types. 42 | CMAKE_CXX_FLAGS:STRING= 43 | 44 | //Flags used by the CXX compiler during DEBUG builds. 45 | CMAKE_CXX_FLAGS_DEBUG:STRING=-g 46 | 47 | //Flags used by the CXX compiler during MINSIZEREL builds. 48 | CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG 49 | 50 | //Flags used by the CXX compiler during RELEASE builds. 51 | CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG 52 | 53 | //Flags used by the CXX compiler during RELWITHDEBINFO builds. 54 | CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG 55 | 56 | //C compiler 57 | CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc 58 | 59 | //A wrapper around 'ar' adding the appropriate '--plugin' option 60 | // for the GCC compiler 61 | CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 62 | 63 | //A wrapper around 'ranlib' adding the appropriate '--plugin' option 64 | // for the GCC compiler 65 | CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 66 | 67 | //Flags used by the C compiler during all build types. 68 | CMAKE_C_FLAGS:STRING= 69 | 70 | //Flags used by the C compiler during DEBUG builds. 71 | CMAKE_C_FLAGS_DEBUG:STRING=-g 72 | 73 | //Flags used by the C compiler during MINSIZEREL builds. 74 | CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG 75 | 76 | //Flags used by the C compiler during RELEASE builds. 77 | CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG 78 | 79 | //Flags used by the C compiler during RELWITHDEBINFO builds. 80 | CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG 81 | 82 | //Path to a program. 83 | CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND 84 | 85 | //Flags used by the linker during all build types. 86 | CMAKE_EXE_LINKER_FLAGS:STRING= 87 | 88 | //Flags used by the linker during DEBUG builds. 89 | CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= 90 | 91 | //Flags used by the linker during MINSIZEREL builds. 92 | CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= 93 | 94 | //Flags used by the linker during RELEASE builds. 95 | CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= 96 | 97 | //Flags used by the linker during RELWITHDEBINFO builds. 98 | CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= 99 | 100 | //Enable/Disable output of compile commands during generation. 101 | CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF 102 | 103 | //Install path prefix, prepended onto install directories. 104 | CMAKE_INSTALL_PREFIX:PATH=/usr/local 105 | 106 | //Path to a program. 107 | CMAKE_LINKER:FILEPATH=/usr/bin/ld 108 | 109 | //Path to a program. 110 | CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make 111 | 112 | //Flags used by the linker during the creation of modules during 113 | // all build types. 114 | CMAKE_MODULE_LINKER_FLAGS:STRING= 115 | 116 | //Flags used by the linker during the creation of modules during 117 | // DEBUG builds. 118 | CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= 119 | 120 | //Flags used by the linker during the creation of modules during 121 | // MINSIZEREL builds. 122 | CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= 123 | 124 | //Flags used by the linker during the creation of modules during 125 | // RELEASE builds. 126 | CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= 127 | 128 | //Flags used by the linker during the creation of modules during 129 | // RELWITHDEBINFO builds. 130 | CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= 131 | 132 | //Path to a program. 133 | CMAKE_NM:FILEPATH=/usr/bin/nm 134 | 135 | //Path to a program. 136 | CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy 137 | 138 | //Path to a program. 139 | CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump 140 | 141 | //Value Computed by CMake 142 | CMAKE_PROJECT_DESCRIPTION:STATIC= 143 | 144 | //Value Computed by CMake 145 | CMAKE_PROJECT_HOMEPAGE_URL:STATIC= 146 | 147 | //Value Computed by CMake 148 | CMAKE_PROJECT_NAME:STATIC=ConnPool 149 | 150 | //Path to a program. 151 | CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib 152 | 153 | //Path to a program. 154 | CMAKE_READELF:FILEPATH=/usr/bin/readelf 155 | 156 | //Flags used by the linker during the creation of shared libraries 157 | // during all build types. 158 | CMAKE_SHARED_LINKER_FLAGS:STRING= 159 | 160 | //Flags used by the linker during the creation of shared libraries 161 | // during DEBUG builds. 162 | CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= 163 | 164 | //Flags used by the linker during the creation of shared libraries 165 | // during MINSIZEREL builds. 166 | CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= 167 | 168 | //Flags used by the linker during the creation of shared libraries 169 | // during RELEASE builds. 170 | CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= 171 | 172 | //Flags used by the linker during the creation of shared libraries 173 | // during RELWITHDEBINFO builds. 174 | CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= 175 | 176 | //If set, runtime paths are not added when installing shared libraries, 177 | // but are added when building. 178 | CMAKE_SKIP_INSTALL_RPATH:BOOL=NO 179 | 180 | //If set, runtime paths are not added when using shared libraries. 181 | CMAKE_SKIP_RPATH:BOOL=NO 182 | 183 | //Flags used by the linker during the creation of static libraries 184 | // during all build types. 185 | CMAKE_STATIC_LINKER_FLAGS:STRING= 186 | 187 | //Flags used by the linker during the creation of static libraries 188 | // during DEBUG builds. 189 | CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= 190 | 191 | //Flags used by the linker during the creation of static libraries 192 | // during MINSIZEREL builds. 193 | CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= 194 | 195 | //Flags used by the linker during the creation of static libraries 196 | // during RELEASE builds. 197 | CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= 198 | 199 | //Flags used by the linker during the creation of static libraries 200 | // during RELWITHDEBINFO builds. 201 | CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= 202 | 203 | //Path to a program. 204 | CMAKE_STRIP:FILEPATH=/usr/bin/strip 205 | 206 | //If this value is on, makefiles will be generated without the 207 | // .SILENT directive, and all commands will be echoed to the console 208 | // during the make. This is useful for debugging only. With Visual 209 | // Studio IDE projects all commands are done without /nologo. 210 | CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE 211 | 212 | //Value Computed by CMake 213 | ConnPool_BINARY_DIR:STATIC=/home/jzx/StudyCpp/ConnPool 214 | 215 | //Value Computed by CMake 216 | ConnPool_SOURCE_DIR:STATIC=/home/jzx/StudyCpp/ConnPool 217 | 218 | 219 | ######################## 220 | # INTERNAL cache entries 221 | ######################## 222 | 223 | //ADVANCED property for variable: CMAKE_ADDR2LINE 224 | CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1 225 | //ADVANCED property for variable: CMAKE_AR 226 | CMAKE_AR-ADVANCED:INTERNAL=1 227 | //This is the directory where this CMakeCache.txt was created 228 | CMAKE_CACHEFILE_DIR:INTERNAL=/home/jzx/StudyCpp/ConnPool 229 | //Major version of cmake used to create the current loaded cache 230 | CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 231 | //Minor version of cmake used to create the current loaded cache 232 | CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 233 | //Patch version of cmake used to create the current loaded cache 234 | CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 235 | //ADVANCED property for variable: CMAKE_COLOR_MAKEFILE 236 | CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 237 | //Path to CMake executable. 238 | CMAKE_COMMAND:INTERNAL=/usr/bin/cmake 239 | //Path to cpack program executable. 240 | CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack 241 | //Path to ctest program executable. 242 | CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest 243 | //ADVANCED property for variable: CMAKE_CXX_COMPILER 244 | CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 245 | //ADVANCED property for variable: CMAKE_CXX_COMPILER_AR 246 | CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 247 | //ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB 248 | CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 249 | //ADVANCED property for variable: CMAKE_CXX_FLAGS 250 | CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 251 | //ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG 252 | CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 253 | //ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL 254 | CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 255 | //ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE 256 | CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 257 | //ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO 258 | CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 259 | //ADVANCED property for variable: CMAKE_C_COMPILER 260 | CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 261 | //ADVANCED property for variable: CMAKE_C_COMPILER_AR 262 | CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 263 | //ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB 264 | CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 265 | //ADVANCED property for variable: CMAKE_C_FLAGS 266 | CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 267 | //ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG 268 | CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 269 | //ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL 270 | CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 271 | //ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE 272 | CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 273 | //ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO 274 | CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 275 | //ADVANCED property for variable: CMAKE_DLLTOOL 276 | CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 277 | //Executable file format 278 | CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF 279 | //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS 280 | CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 281 | //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG 282 | CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 283 | //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL 284 | CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 285 | //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE 286 | CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 287 | //ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO 288 | CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 289 | //ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS 290 | CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 291 | //Name of external makefile project generator. 292 | CMAKE_EXTRA_GENERATOR:INTERNAL= 293 | //Name of generator. 294 | CMAKE_GENERATOR:INTERNAL=Unix Makefiles 295 | //Generator instance identifier. 296 | CMAKE_GENERATOR_INSTANCE:INTERNAL= 297 | //Name of generator platform. 298 | CMAKE_GENERATOR_PLATFORM:INTERNAL= 299 | //Name of generator toolset. 300 | CMAKE_GENERATOR_TOOLSET:INTERNAL= 301 | //Source directory with the top level CMakeLists.txt file for this 302 | // project 303 | CMAKE_HOME_DIRECTORY:INTERNAL=/home/jzx/StudyCpp/ConnPool 304 | //Install .so files without execute permission. 305 | CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 306 | //ADVANCED property for variable: CMAKE_LINKER 307 | CMAKE_LINKER-ADVANCED:INTERNAL=1 308 | //ADVANCED property for variable: CMAKE_MAKE_PROGRAM 309 | CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 310 | //ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS 311 | CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 312 | //ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG 313 | CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 314 | //ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL 315 | CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 316 | //ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE 317 | CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 318 | //ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO 319 | CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 320 | //ADVANCED property for variable: CMAKE_NM 321 | CMAKE_NM-ADVANCED:INTERNAL=1 322 | //number of local generators 323 | CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 324 | //ADVANCED property for variable: CMAKE_OBJCOPY 325 | CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 326 | //ADVANCED property for variable: CMAKE_OBJDUMP 327 | CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 328 | //Platform information initialized 329 | CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 330 | //ADVANCED property for variable: CMAKE_RANLIB 331 | CMAKE_RANLIB-ADVANCED:INTERNAL=1 332 | //ADVANCED property for variable: CMAKE_READELF 333 | CMAKE_READELF-ADVANCED:INTERNAL=1 334 | //Path to CMake installation. 335 | CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16 336 | //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS 337 | CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 338 | //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG 339 | CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 340 | //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL 341 | CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 342 | //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE 343 | CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 344 | //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO 345 | CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 346 | //ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH 347 | CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 348 | //ADVANCED property for variable: CMAKE_SKIP_RPATH 349 | CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 350 | //ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS 351 | CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 352 | //ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG 353 | CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 354 | //ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL 355 | CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 356 | //ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE 357 | CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 358 | //ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO 359 | CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 360 | //ADVANCED property for variable: CMAKE_STRIP 361 | CMAKE_STRIP-ADVANCED:INTERNAL=1 362 | //uname command 363 | CMAKE_UNAME:INTERNAL=/usr/bin/uname 364 | //ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE 365 | CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 366 | 367 | -------------------------------------------------------------------------------- /RedisHelper.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYLAR__REDISHELPER_H_ 2 | #define _SYLAR__REDISHELPER_H_ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "SimConnPool.h" 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | namespace SimpleConnPool { 23 | 24 | // redis状态 25 | enum class RedisState { 26 | M_REDIS_OK = 0, //执行成功 27 | M_CONNECT_FAIL = -1, //连接redis失败 28 | M_CONTEXT_ERROR = -2, //RedisContext返回错误 29 | M_REPLY_ERROR = -3, //redisReply错误 30 | M_EXE_COMMAND_ERROR = -4, //redis命令执行错误 31 | M_EXECUTE_FAIL = -5, //执行失败 32 | M_RETURN_NULL = -6 //返回结果为空 33 | }; 34 | 35 | 36 | 37 | 38 | 39 | class RedisHelper; 40 | //redis连接池 单例 41 | typedef ConnPool redisPool; 42 | typedef Singleton redisConnPoolMgr; 43 | 44 | /* 45 | redis相关操作:对hiredis进行二次封装,每个连接包含指向连接池的指针 46 | */ 47 | class RedisHelper : public std::enable_shared_from_this, public redisPool { 48 | public: 49 | typedef std::shared_ptr ptr; 50 | typedef Mutex MutexType; 51 | 52 | RedisHelper() 53 | : m_host("") 54 | , m_port(0) 55 | , m_pwd("") { 56 | m_rdsctx = NULL; 57 | m_rdsrep = NULL; 58 | m_pool = redisConnPoolMgr::GetInstance(); 59 | std::cout << "初始化完成!" << std::endl; 60 | } 61 | 62 | ~RedisHelper() { 63 | std::cout << "destory RedisHelper::~RedisHelper()" << std::endl; 64 | simRelease(); 65 | } 66 | 67 | // 放回连接 68 | void connBack() { 69 | //std::cout << "1111" << std::endl; 70 | std::shared_ptr x = shared_from_this(); 71 | //std::cout << "connBack use_count:" << x.use_count() << std::endl; 72 | m_pool->back(x); 73 | } 74 | 75 | // 连接redis数据库,默认pwd为空 76 | bool simpleConn(const std::string& host, int port, const std::string& pwd="") { 77 | m_host = host; 78 | m_port = port; 79 | m_pwd = pwd; 80 | m_rdsctx = redisConnect(host.c_str(), m_port); 81 | if (m_rdsctx == NULL || m_rdsctx->err) { 82 | if (m_rdsctx) { 83 | m_error_msg = m_rdsctx->errstr; 84 | m_state = RedisState::M_CONNECT_FAIL; 85 | std::cout << "connection error! errstr:" << m_error_msg << std::endl; 86 | return m_state == RedisState::M_REDIS_OK; 87 | } 88 | else { 89 | m_error_msg = "context is null"; 90 | m_state = RedisState::M_CONTEXT_ERROR; 91 | std::cout << "context is null! errstr:" << m_error_msg << std::endl; 92 | return m_state == RedisState::M_REDIS_OK; 93 | } 94 | } 95 | m_error_msg = "ok"; 96 | m_state = RedisState::M_REDIS_OK; 97 | std::cout << "redis connection is ok!" << std::endl; 98 | return m_state == RedisState::M_REDIS_OK; 99 | } 100 | 101 | 102 | 103 | // 简单键的存取 104 | RedisState setSimple(const std::string& key, const std::string& value) { 105 | return setHandle(key, value); 106 | } 107 | RedisState getSimple(const std::string& key, std::string& value) { 108 | return getHandle(key, value); 109 | } 110 | RedisState delSimple(const std::string& key) { 111 | std::string cmd = "del " + key; 112 | int flag = 0; 113 | execute(cmd, &flag); 114 | if(!flag && m_state == RedisState::M_REDIS_OK) { 115 | m_state = RedisState::M_EXECUTE_FAIL; 116 | } 117 | return m_state; 118 | } 119 | 120 | // 获取全部key 121 | std::vector getAllKeys() { 122 | std::string cmd = "keys *"; 123 | int len = 0; 124 | redisReply **array; 125 | execute(cmd, &len, &array); 126 | if(!len && m_state == RedisState::M_REDIS_OK) { 127 | m_state = RedisState::M_EXECUTE_FAIL; 128 | } 129 | std::vector res; 130 | for (int i = 0; i < len; i++) { 131 | res.emplace_back(array[i]->str); 132 | } 133 | return res; 134 | } 135 | 136 | // 超时时间相关操作 137 | // 设置 138 | // type控制以秒为单位或以毫秒为单位,使用毫秒时type置为p即可 139 | bool setKeyTimeout(const std::string& key, uint64_t timeout, const std::string& type = "") { 140 | //expire 键名 时间 # 秒 141 | //pexpire 键名 时间 # 毫秒 142 | // redis返回数字1表示成功 143 | std::string cmd = type + "expire " + key + " " + std::to_string(timeout); 144 | int flag = 0; 145 | execute(cmd, &flag); 146 | if(!flag && m_state == RedisState::M_REDIS_OK) { 147 | m_state = RedisState::M_EXECUTE_FAIL; 148 | } 149 | return m_state == RedisState::M_REDIS_OK; 150 | } 151 | 152 | // 移除 153 | bool delKeyTimeout(const std::string& key) { 154 | // persist 键名 155 | // redis返回数字1表示成功 156 | std::string cmd = "persist " + key; 157 | int flag = 0; 158 | execute(cmd, &flag); 159 | if(!flag && m_state == RedisState::M_REDIS_OK) { 160 | m_state = RedisState::M_EXECUTE_FAIL; 161 | } 162 | return m_state == RedisState::M_REDIS_OK; 163 | } 164 | 165 | // 返回剩余 166 | uint64_t getKeyTimeout(const std::string& key, const std::string& type = "") { 167 | //ttl 键名 # 秒 168 | //pttl 键名 # 毫秒 169 | // redis返回剩余时间 170 | std::string cmd = type + "ttl " + key; 171 | int timeout; 172 | execute(cmd, &timeout); 173 | if(!timeout && m_state == RedisState::M_REDIS_OK) { 174 | //std::cout << "getKeyTimeout error" << std::endl; 175 | m_state = RedisState::M_EXECUTE_FAIL; 176 | //return timeout; 177 | } 178 | return timeout; 179 | } 180 | 181 | // 键是否存在 182 | bool isExists(const std::string& key) { 183 | // exists 键名 184 | // redis返回数字1表示成功 185 | std::string cmd = "exists " + key; 186 | int flag = 0; 187 | execute(cmd, &flag); 188 | if(!flag && m_state == RedisState::M_REDIS_OK) { 189 | m_state = RedisState::M_EXECUTE_FAIL; 190 | } 191 | return m_state == RedisState::M_REDIS_OK; 192 | } 193 | 194 | // 改名 195 | bool reName(const std::string& old_key, const std::string& new_key) { 196 | // rename 键名 新键名 197 | // 返回OK 198 | std::string cmd = "rename " + old_key + " " + new_key; 199 | return execute(cmd) == RedisState::M_REDIS_OK; 200 | } 201 | 202 | // 获取错误信息 203 | const std::string& getError() const { 204 | return m_error_msg; 205 | } 206 | 207 | 208 | 209 | // 队列操作 210 | public: 211 | RedisState pop(const std::string& key, std::string& value) { 212 | return lpop(key, value); 213 | } 214 | 215 | RedisState lpop(const std::string& key, std::string& value) { 216 | std::string cmd = "lpop " + key; 217 | return execute(cmd, &value); 218 | } 219 | 220 | RedisState rpop(const std::string& key, std::string& value) { 221 | std::string cmd = "rpop " + key; 222 | return execute(cmd, &value); 223 | } 224 | 225 | RedisState push(const std::string& key, const std::string& value) { 226 | return rpush(key, value); 227 | } 228 | 229 | RedisState push(const std::string& key, const std::vector& vec) { 230 | return rpush(key, vec); 231 | } 232 | 233 | RedisState lpush(const std::string& key, const std::string& value) { 234 | std::string cmd = "lpush " + key + " " + value; 235 | int len = 0; 236 | return execute(cmd, &len); 237 | } 238 | 239 | RedisState lpush(const std::string& key, const std::vector& vec) { 240 | std::string cmd = "lpush " + key; 241 | for(auto x:vec) { 242 | cmd += " " + x; 243 | } 244 | int len = 0; 245 | return execute(cmd, &len); 246 | } 247 | 248 | RedisState rpush(const std::string& key, const std::string& value) { 249 | std::string cmd = "rpush " + key + " " + value; 250 | int len = 0; 251 | return execute(cmd, &len); 252 | } 253 | 254 | RedisState rpush(const std::string& key, const std::vector& vec) { 255 | std::string cmd = "rpush " + key; 256 | for(auto x:vec) { 257 | cmd += " " + x; 258 | } 259 | int len = 0; 260 | return execute(cmd, &len); 261 | } 262 | 263 | public: 264 | RedisState parseRdsrep(void* result=NULL, redisReply*** array = NULL) { 265 | if (m_rdsctx->err) { 266 | m_error_msg = m_rdsctx->errstr; 267 | m_state = RedisState::M_CONTEXT_ERROR; 268 | return m_state; 269 | } 270 | 271 | if (m_rdsrep == NULL) { 272 | m_error_msg = "auth redisReply is NULL"; 273 | m_state = RedisState::M_REPLY_ERROR; 274 | return m_state; 275 | } 276 | //std::cout << "type: " << m_rdsrep->type << std::endl; 277 | switch (m_rdsrep->type){ 278 | case REDIS_REPLY_ERROR: 279 | m_error_msg = m_rdsrep->str; 280 | m_state = RedisState::M_EXE_COMMAND_ERROR; 281 | return m_state; 282 | case REDIS_REPLY_STATUS: 283 | if (strcmp(m_rdsrep->str, "OK") == 0) { 284 | m_state = RedisState::M_REDIS_OK; 285 | //*(std::string*)result = m_rdsrep->str; 286 | return m_state; 287 | } 288 | else { 289 | m_error_msg = m_rdsrep->str; 290 | m_state = RedisState::M_EXE_COMMAND_ERROR; 291 | return m_state; 292 | } 293 | case REDIS_REPLY_INTEGER: 294 | //std::cout<<"REDIS_REPLY_INTEGER " << m_rdsrep->type <integer; 296 | m_state = RedisState::M_REDIS_OK; 297 | return m_state; 298 | case REDIS_REPLY_STRING: 299 | *(std::string*)result = m_rdsrep->str; 300 | m_state = RedisState::M_REDIS_OK; 301 | return m_state; 302 | case REDIS_REPLY_NIL: 303 | *(std::string*)result = ""; 304 | m_state = RedisState::M_RETURN_NULL; 305 | return m_state; 306 | case REDIS_REPLY_ARRAY: 307 | *(int*)result = m_rdsrep->elements; 308 | *array = m_rdsrep->element; 309 | m_state = RedisState::M_REDIS_OK; 310 | return m_state; 311 | default: 312 | m_error_msg = "unknow reply type"; 313 | m_state = RedisState::M_EXE_COMMAND_ERROR; 314 | return m_state; 315 | } 316 | } 317 | // 执行语句 318 | RedisState execute(const std::string& cmd, void* result=NULL, redisReply*** array = NULL) { 319 | //std::cout << "lua:" << cmd << std::endl; 320 | m_rdsrep = (redisReply*)redisCommand(m_rdsctx, cmd.c_str()); 321 | return parseRdsrep(result, array); 322 | } 323 | 324 | RedisState executeLua(const std::string& cmd, void* result=NULL, redisReply*** array = NULL) { 325 | redisAppendCommand(m_rdsctx, cmd.c_str()); 326 | if (redisGetReply(m_rdsctx, (void**)&m_rdsrep) != REDIS_OK) 327 | return RedisState::M_EXE_COMMAND_ERROR; 328 | return parseRdsrep(result, array); 329 | } 330 | 331 | public: 332 | // 分布式锁 TODO 333 | /* 334 | 在分布式系统环境下,一个方法在同一时间只能被一个机器的一个线程执行 335 | 高可用的获取锁与释放锁 336 | 高性能的获取锁与释放锁 337 | 具备可重入特性(可理解为重新进入,由多于一个任务并发使用,而不必担心数据错误) 338 | 具备锁失效机制,即自动解锁,防止死锁 339 | 具备非阻塞锁特性,即没有获取到锁将直接返回获取锁失败 340 | */ 341 | 342 | /* 343 | 加锁逻辑: 344 | 在不存在键时设置键 并同时设置超时时间 保证原子性 345 | set key value NX PX timeout 346 | 默认10秒 347 | 返回该线程拿到锁生成的值,后续解锁比较,不能因为挂机或网络原因解锁别的线程锁 348 | 分布式锁的键为:redis.lock 值为:当前时间戳 nsec 349 | */ 350 | std::string lock(uint64_t timeout = 30000) { 351 | while(1) { 352 | struct timespec time = {0, 0}; 353 | clock_gettime(CLOCK_REALTIME, &time); 354 | std::string uuid = std::to_string(time.tv_nsec); 355 | std::string cmd = "set redis.lock " + uuid + " NX PX " + std::to_string(timeout); 356 | //std::cout << "lock cmd:" << cmd << std::endl; 357 | std::string flag; 358 | RedisState sta; 359 | { 360 | MutexType::Lock lock(m_mutex); 361 | sta = execute(cmd, &flag); 362 | } 363 | if(sta == RedisState::M_REDIS_OK) { 364 | std::cout << "get redis.lock!" << std::endl; 365 | return uuid; 366 | } 367 | } 368 | } 369 | 370 | /* 371 | 解锁逻辑: 372 | 获取锁,判断锁,删除锁 373 | 为了保证原子性,使用lua脚本来完成三个操作 374 | redis使用eval "xxxx" keys数量 key1 key2 num1 num2 375 | */ 376 | void unlock(const std::string& uuid) { 377 | std::string cmd = "eval \"if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end\" 1 redis.lock " + uuid; 378 | //std::cout << "unlock cmd " << cmd << std::endl; 379 | int flag; 380 | RedisState sta = executeLua(cmd.c_str(), &flag); 381 | if(sta == RedisState::M_REDIS_OK && flag > 0) { 382 | std::cout << "获取到锁并解锁" << std::endl; 383 | } 384 | else { 385 | std::cout << "未获取到锁 errstr: " << m_error_msg << std::endl; 386 | } 387 | return ; 388 | } 389 | 390 | 391 | private: 392 | // 释放单条连接 393 | void simRelease() { 394 | freeReplyObject(m_rdsrep); 395 | redisFree(m_rdsctx); 396 | m_rdsctx = NULL; 397 | m_rdsrep = NULL; 398 | m_pool = NULL; 399 | } 400 | // 存值操作 401 | RedisState setHandle(const std::string& key, const std::string& value) { 402 | std::string cmd = "set " + key + " " + value; 403 | return execute(cmd); 404 | } 405 | // 取值操作 406 | RedisState getHandle(const std::string& key, std::string& value) { 407 | std::string cmd = "get " + key; 408 | return execute(cmd, &value); 409 | } 410 | 411 | 412 | 413 | private: 414 | std::string m_host; //连接地址 415 | int m_port; //端口号 416 | std::string m_pwd; //密码 417 | /* 418 | typedef struct redisContext { 419 | int err; 420 | char errstr[128]; 421 | int fd; 422 | int flags; 423 | char *obuf; 424 | redisReader *reader; 425 | enum redisConnectionType connection_type; 426 | struct timeval *timeout; 427 | struct { 428 | char *host; 429 | char *source_addr; 430 | int port; 431 | } tcp; 432 | struct { 433 | char *path; 434 | } unix_sock; 435 | } redisContext; 436 | 437 | */ 438 | redisContext *m_rdsctx; //redis结构体 439 | /* 440 | typedef struct redisReply { 441 | //命令执行结果的返回类型 442 | int type; 443 | //存储执行结果返回为整数 444 | long long integer; 445 | //字符串值的长度 446 | size_t len; 447 | //存储命令执行结果返回是字符串 448 | char *str; 449 | //返回结果是数组的大小 450 | size_t elements; 451 | //存储执行结果返回是数组 452 | struct redisReply **element; 453 | } redisReply 454 | 455 | */ 456 | redisReply *m_rdsrep; //返回结果结构体 457 | 458 | std::string m_error_msg; //错误信息 459 | RedisState m_state; //状态码 460 | 461 | redisPool* m_pool; // 指向连接池 462 | MutexType m_mutex; // 互斥锁 463 | 464 | }; 465 | 466 | //mysql连接池 单例 467 | typedef ConnPool mysqlPool; 468 | typedef Singleton mysqlConnPoolMgr; 469 | 470 | /* 471 | mysql相关操作 472 | */ 473 | class MysqlHelper : public std::enable_shared_from_this { 474 | public: 475 | typedef std::shared_ptr ptr; 476 | 477 | //TODO 478 | 479 | }; 480 | 481 | 482 | 483 | } 484 | 485 | #endif -------------------------------------------------------------------------------- /SimConnPool.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYLAR_CONNPOOL_H_ 2 | #define _SYLAR_CONNPOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | 17 | 18 | namespace SimpleConnPool { 19 | 20 | 21 | // 单例模板 22 | template 23 | class Singleton{ 24 | public: 25 | static T* GetInstance() { 26 | static T v; 27 | //printf("T:xxxx"); 28 | return &v; 29 | } 30 | }; 31 | 32 | 33 | //通过加锁对象的构造和析构加检锁 34 | template 35 | struct ScopedLockImpl { 36 | public: 37 | ScopedLockImpl(T& mutex) 38 | :m_mutex(mutex) { 39 | m_mutex.lock(); 40 | m_locked = true; 41 | } 42 | ~ScopedLockImpl() { 43 | unlock(); 44 | } 45 | 46 | void lock() { 47 | if(!m_locked) { 48 | m_mutex.lock(); 49 | m_locked = true; 50 | } 51 | } 52 | 53 | void unlock() { 54 | if(m_locked) { 55 | m_mutex.unlock(); 56 | m_locked = false; 57 | } 58 | } 59 | private: 60 | T& m_mutex; 61 | bool m_locked; 62 | }; 63 | 64 | // 互斥锁 65 | class Mutex{ 66 | public: 67 | typedef ScopedLockImpl Lock; 68 | Mutex() { 69 | pthread_mutex_init(&m_mutex, nullptr); 70 | } 71 | ~Mutex() { 72 | pthread_mutex_destroy(&m_mutex); 73 | } 74 | 75 | void lock() { 76 | pthread_mutex_lock(&m_mutex); 77 | } 78 | 79 | void unlock() { 80 | pthread_mutex_unlock(&m_mutex); 81 | } 82 | private: 83 | pthread_mutex_t m_mutex; 84 | }; 85 | 86 | 87 | // class RedisHelper; 88 | class MysqlHelper; 89 | 90 | 91 | /* 92 | 连接池类模板:提供取出和放回操作 93 | 连接池在构造时不做操作,进行连接时初始化每个连接并连上redis服务器 94 | */ 95 | template 96 | class ConnPool { 97 | public: 98 | typedef std::shared_ptr> ptr; // 连接池的智能指针 99 | typedef std::shared_ptr connPtr; // 连接对象的智能指针 100 | typedef Mutex MutexType; 101 | 102 | ConnPool() { 103 | std::cout << "ConnPool()" << std::endl; 104 | } 105 | 106 | ~ConnPool() { 107 | destoryConnPool(); 108 | } 109 | 110 | void destoryConnPool() { 111 | MutexType::Lock lock(m_mutex); 112 | std::cout << "~ConnPool()" << std::endl; 113 | if(!is_stop) { 114 | while(!m_freeque.empty()) { 115 | connPtr x = m_freeque.front(); 116 | m_freeque.pop_front(); 117 | x.reset(); 118 | } 119 | } 120 | is_stop = true; 121 | m_freenum = 0; 122 | m_busynum = 0; 123 | } 124 | 125 | void init(int conn_size = 5) { 126 | MutexType::Lock lock(m_mutex); 127 | if(is_stop) { 128 | for(int i=0; i(); 130 | // 空闲队列放入连接对象的智能指针 131 | m_freeque.push_back(x); 132 | } 133 | is_stop = false; 134 | } 135 | } 136 | 137 | connPtr get() { 138 | // 加锁 139 | MutexType::Lock lock(m_mutex); 140 | if(m_freenum <= 0) { 141 | //std::cout << "no free connection!" << std::endl; 142 | return nullptr; 143 | } 144 | 145 | connPtr res = m_freeque.front(); 146 | m_freeque.pop_front(); 147 | --m_freenum; 148 | ++m_busynum; 149 | //std::cout << "get use_count:" << res.use_count() << std::endl; 150 | return res; 151 | } 152 | 153 | void back(connPtr& conn) { 154 | // 加锁 155 | MutexType::Lock lock(m_mutex); 156 | m_freeque.push_back(conn); 157 | ++m_freenum; 158 | } 159 | 160 | void stop() {destoryConnPool();} 161 | 162 | int getFreeNum() {return m_freenum;} 163 | 164 | void connection(const std::string& host, int port, const std::string& pwd="", int conn_size = 5) { 165 | init(conn_size); 166 | MutexType::Lock lock(m_mutex); 167 | if(!is_conn) { 168 | for(auto it = m_freeque.begin(); it != m_freeque.end(); ++it) { 169 | if((*it)->simpleConn(host, port, pwd)) { 170 | std::cout << "connection pool is error!" << std::endl; 171 | continue; 172 | } 173 | ++m_freenum; 174 | } 175 | is_conn = true; 176 | } 177 | } 178 | // void connection(const std::string& host, int port, const std::string& pwd="", int conn_size = 5) = 0; 179 | 180 | protected: 181 | std::list m_freeque; // 空闲队列 182 | std::atomic m_busynum{0}; // 工作数量 183 | std::atomic m_freenum{0}; // 空闲数量 184 | 185 | bool is_stop = true; // 停止标记 186 | bool is_conn = false; // 连接标记 187 | int m_capacity; // 连接池容量 188 | 189 | MutexType m_mutex; // 互斥锁 190 | 191 | }; 192 | 193 | 194 | 195 | 196 | 197 | # if 0 198 | /* 199 | redis相关操作:对hiredis进行二次封装,每个连接包含指向连接池的指针 200 | */ 201 | class RedisHelper : public std::enable_shared_from_this { 202 | public: 203 | typedef std::shared_ptr ptr; 204 | typedef Mutex MutexType; 205 | 206 | RedisHelper() 207 | : m_host("") 208 | , m_port(0) 209 | , m_pwd("") { 210 | m_rdsctx = NULL; 211 | m_rdsrep = NULL; 212 | m_pool = redisConnPoolMgr::GetInstance(); 213 | std::cout << "初始化完成!" << std::endl; 214 | } 215 | 216 | ~RedisHelper() { 217 | std::cout << "destory RedisHelper::~RedisHelper()" << std::endl; 218 | simRelease(); 219 | } 220 | 221 | // 放回连接 222 | void connBack() { 223 | //std::cout << "1111" << std::endl; 224 | std::shared_ptr x = shared_from_this(); 225 | //std::cout << "connBack use_count:" << x.use_count() << std::endl; 226 | m_pool->back(x); 227 | } 228 | 229 | // 连接redis数据库,默认pwd为空 230 | RedisState simpleConn(const std::string& host, int port, const std::string& pwd="") { 231 | m_host = host; 232 | m_port = port; 233 | m_pwd = pwd; 234 | m_rdsctx = redisConnect(host.c_str(), m_port); 235 | if (m_rdsctx == NULL || m_rdsctx->err) { 236 | if (m_rdsctx) { 237 | m_error_msg = m_rdsctx->errstr; 238 | m_state = RedisState::M_CONNECT_FAIL; 239 | std::cout << "connection error! errstr:" << m_error_msg << std::endl; 240 | return m_state; 241 | } 242 | else { 243 | m_error_msg = "context is null"; 244 | m_state = RedisState::M_CONTEXT_ERROR; 245 | std::cout << "context is null! errstr:" << m_error_msg << std::endl; 246 | return m_state; 247 | } 248 | } 249 | m_error_msg = "ok"; 250 | m_state = RedisState::M_REDIS_OK; 251 | std::cout << "redis connection is ok!" << std::endl; 252 | return m_state; 253 | } 254 | 255 | 256 | 257 | // 简单键的存取 258 | RedisState setSimple(const std::string& key, const std::string& value) { 259 | return setHandle(key, value); 260 | } 261 | RedisState getSimple(const std::string& key, std::string& value) { 262 | return getHandle(key, value); 263 | } 264 | RedisState delSimple(const std::string& key) { 265 | std::string cmd = "del " + key; 266 | int flag = 0; 267 | execute(cmd, &flag); 268 | if(!flag && m_state == RedisState::M_REDIS_OK) { 269 | m_state = RedisState::M_EXECUTE_FAIL; 270 | } 271 | return m_state; 272 | } 273 | 274 | // 获取全部key 275 | std::vector getAllKeys() { 276 | std::string cmd = "keys *"; 277 | int len = 0; 278 | redisReply **array; 279 | execute(cmd, &len, &array); 280 | if(!len && m_state == RedisState::M_REDIS_OK) { 281 | m_state = RedisState::M_EXECUTE_FAIL; 282 | } 283 | std::vector res; 284 | for (int i = 0; i < len; i++) { 285 | res.emplace_back(array[i]->str); 286 | } 287 | return res; 288 | } 289 | 290 | // 超时时间相关操作 291 | // 设置 292 | // type控制以秒为单位或以毫秒为单位,使用毫秒时type置为p即可 293 | bool setKeyTimeout(const std::string& key, uint64_t timeout, const std::string& type = "") { 294 | //expire 键名 时间 # 秒 295 | //pexpire 键名 时间 # 毫秒 296 | // redis返回数字1表示成功 297 | std::string cmd = type + "expire " + key + " " + std::to_string(timeout); 298 | int flag = 0; 299 | execute(cmd, &flag); 300 | if(!flag && m_state == RedisState::M_REDIS_OK) { 301 | m_state = RedisState::M_EXECUTE_FAIL; 302 | } 303 | return m_state == RedisState::M_REDIS_OK; 304 | } 305 | 306 | // 移除 307 | bool delKeyTimeout(const std::string& key) { 308 | // persist 键名 309 | // redis返回数字1表示成功 310 | std::string cmd = "persist " + key; 311 | int flag = 0; 312 | execute(cmd, &flag); 313 | if(!flag && m_state == RedisState::M_REDIS_OK) { 314 | m_state = RedisState::M_EXECUTE_FAIL; 315 | } 316 | return m_state == RedisState::M_REDIS_OK; 317 | } 318 | 319 | // 返回剩余 320 | uint64_t getKeyTimeout(const std::string& key, const std::string& type = "") { 321 | //ttl 键名 # 秒 322 | //pttl 键名 # 毫秒 323 | // redis返回剩余时间 324 | std::string cmd = type + "ttl " + key; 325 | int timeout; 326 | execute(cmd, &timeout); 327 | if(!timeout && m_state == RedisState::M_REDIS_OK) { 328 | //std::cout << "getKeyTimeout error" << std::endl; 329 | m_state = RedisState::M_EXECUTE_FAIL; 330 | //return timeout; 331 | } 332 | return timeout; 333 | } 334 | 335 | // 键是否存在 336 | bool isExists(const std::string& key) { 337 | // exists 键名 338 | // redis返回数字1表示成功 339 | std::string cmd = "exists " + key; 340 | int flag = 0; 341 | execute(cmd, &flag); 342 | if(!flag && m_state == RedisState::M_REDIS_OK) { 343 | m_state = RedisState::M_EXECUTE_FAIL; 344 | } 345 | return m_state == RedisState::M_REDIS_OK; 346 | } 347 | 348 | // 改名 349 | bool reName(const std::string& old_key, const std::string& new_key) { 350 | // rename 键名 新键名 351 | // 返回OK 352 | std::string cmd = "rename " + old_key + " " + new_key; 353 | return execute(cmd) == RedisState::M_REDIS_OK; 354 | } 355 | 356 | // 获取错误信息 357 | const std::string& getError() const { 358 | return m_error_msg; 359 | } 360 | 361 | 362 | 363 | // 队列操作 364 | public: 365 | RedisState pop(const std::string& key, std::string& value) { 366 | return lpop(key, value); 367 | } 368 | 369 | RedisState lpop(const std::string& key, std::string& value) { 370 | std::string cmd = "lpop " + key; 371 | return execute(cmd, &value); 372 | } 373 | 374 | RedisState rpop(const std::string& key, std::string& value) { 375 | std::string cmd = "rpop " + key; 376 | return execute(cmd, &value); 377 | } 378 | 379 | RedisState push(const std::string& key, const std::string& value) { 380 | return rpush(key, value); 381 | } 382 | 383 | RedisState push(const std::string& key, const std::vector& vec) { 384 | return rpush(key, vec); 385 | } 386 | 387 | RedisState lpush(const std::string& key, const std::string& value) { 388 | std::string cmd = "lpush " + key + " " + value; 389 | int len = 0; 390 | return execute(cmd, &len); 391 | } 392 | 393 | RedisState lpush(const std::string& key, const std::vector& vec) { 394 | std::string cmd = "lpush " + key; 395 | for(auto x:vec) { 396 | cmd += " " + x; 397 | } 398 | int len = 0; 399 | return execute(cmd, &len); 400 | } 401 | 402 | RedisState rpush(const std::string& key, const std::string& value) { 403 | std::string cmd = "rpush " + key + " " + value; 404 | int len = 0; 405 | return execute(cmd, &len); 406 | } 407 | 408 | RedisState rpush(const std::string& key, const std::vector& vec) { 409 | std::string cmd = "rpush " + key; 410 | for(auto x:vec) { 411 | cmd += " " + x; 412 | } 413 | int len = 0; 414 | return execute(cmd, &len); 415 | } 416 | 417 | public: 418 | RedisState parseRdsrep(void* result=NULL, redisReply*** array = NULL) { 419 | if (m_rdsctx->err) { 420 | m_error_msg = m_rdsctx->errstr; 421 | m_state = RedisState::M_CONTEXT_ERROR; 422 | return m_state; 423 | } 424 | 425 | if (m_rdsrep == NULL) { 426 | m_error_msg = "auth redisReply is NULL"; 427 | m_state = RedisState::M_REPLY_ERROR; 428 | return m_state; 429 | } 430 | //std::cout << "type: " << m_rdsrep->type << std::endl; 431 | switch (m_rdsrep->type){ 432 | case REDIS_REPLY_ERROR: 433 | m_error_msg = m_rdsrep->str; 434 | m_state = RedisState::M_EXE_COMMAND_ERROR; 435 | return m_state; 436 | case REDIS_REPLY_STATUS: 437 | if (strcmp(m_rdsrep->str, "OK") == 0) { 438 | m_state = RedisState::M_REDIS_OK; 439 | //*(std::string*)result = m_rdsrep->str; 440 | return m_state; 441 | } 442 | else { 443 | m_error_msg = m_rdsrep->str; 444 | m_state = RedisState::M_EXE_COMMAND_ERROR; 445 | return m_state; 446 | } 447 | case REDIS_REPLY_INTEGER: 448 | //std::cout<<"REDIS_REPLY_INTEGER " << m_rdsrep->type <integer; 450 | m_state = RedisState::M_REDIS_OK; 451 | return m_state; 452 | case REDIS_REPLY_STRING: 453 | *(std::string*)result = m_rdsrep->str; 454 | m_state = RedisState::M_REDIS_OK; 455 | return m_state; 456 | case REDIS_REPLY_NIL: 457 | *(std::string*)result = ""; 458 | m_state = RedisState::M_RETURN_NULL; 459 | return m_state; 460 | case REDIS_REPLY_ARRAY: 461 | *(int*)result = m_rdsrep->elements; 462 | *array = m_rdsrep->element; 463 | m_state = RedisState::M_REDIS_OK; 464 | return m_state; 465 | default: 466 | m_error_msg = "unknow reply type"; 467 | m_state = RedisState::M_EXE_COMMAND_ERROR; 468 | return m_state; 469 | } 470 | } 471 | // 执行语句 472 | RedisState execute(const std::string& cmd, void* result=NULL, redisReply*** array = NULL) { 473 | //std::cout << "lua:" << cmd << std::endl; 474 | m_rdsrep = (redisReply*)redisCommand(m_rdsctx, cmd.c_str()); 475 | return parseRdsrep(result, array); 476 | } 477 | 478 | RedisState executeLua(const std::string& cmd, void* result=NULL, redisReply*** array = NULL) { 479 | redisAppendCommand(m_rdsctx, cmd.c_str()); 480 | if (redisGetReply(m_rdsctx, (void**)&m_rdsrep) != REDIS_OK) 481 | return RedisState::M_EXE_COMMAND_ERROR; 482 | return parseRdsrep(result, array); 483 | } 484 | 485 | public: 486 | // 分布式锁 TODO 487 | /* 488 | 在分布式系统环境下,一个方法在同一时间只能被一个机器的一个线程执行 489 | 高可用的获取锁与释放锁 490 | 高性能的获取锁与释放锁 491 | 具备可重入特性(可理解为重新进入,由多于一个任务并发使用,而不必担心数据错误) 492 | 具备锁失效机制,即自动解锁,防止死锁 493 | 具备非阻塞锁特性,即没有获取到锁将直接返回获取锁失败 494 | */ 495 | 496 | /* 497 | 加锁逻辑: 498 | 在不存在键时设置键 并同时设置超时时间 保证原子性 499 | set key value NX PX timeout 500 | 默认10秒 501 | 返回该线程拿到锁生成的值,后续解锁比较,不能因为挂机或网络原因解锁别的线程锁 502 | 分布式锁的键为:redis.lock 值为:当前时间戳 nsec 503 | */ 504 | std::string lock(uint64_t timeout = 30000) { 505 | while(1) { 506 | struct timespec time = {0, 0}; 507 | clock_gettime(CLOCK_REALTIME, &time); 508 | std::string uuid = std::to_string(time.tv_nsec); 509 | std::string cmd = "set redis.lock " + uuid + " NX PX " + std::to_string(timeout); 510 | //std::cout << "lock cmd:" << cmd << std::endl; 511 | std::string flag; 512 | RedisState sta; 513 | { 514 | MutexType::Lock lock(m_mutex); 515 | sta = execute(cmd, &flag); 516 | } 517 | if(sta == RedisState::M_REDIS_OK) { 518 | std::cout << "get redis.lock!" << std::endl; 519 | return uuid; 520 | } 521 | } 522 | } 523 | 524 | /* 525 | 解锁逻辑: 526 | 获取锁,判断锁,删除锁 527 | 为了保证原子性,使用lua脚本来完成三个操作 528 | redis使用eval "xxxx" keys数量 key1 key2 num1 num2 529 | */ 530 | void unlock(const std::string& uuid) { 531 | std::string cmd = "eval \"if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end\" 1 redis.lock " + uuid; 532 | //std::cout << "unlock cmd " << cmd << std::endl; 533 | int flag; 534 | RedisState sta = executeLua(cmd.c_str(), &flag); 535 | if(sta == RedisState::M_REDIS_OK && flag > 0) { 536 | std::cout << "获取到锁并解锁" << std::endl; 537 | } 538 | else { 539 | std::cout << "未获取到锁 errstr: " << m_error_msg << std::endl; 540 | } 541 | return ; 542 | } 543 | 544 | 545 | private: 546 | // 释放单条连接 547 | void simRelease() { 548 | freeReplyObject(m_rdsrep); 549 | redisFree(m_rdsctx); 550 | m_rdsctx = NULL; 551 | m_rdsrep = NULL; 552 | m_pool = NULL; 553 | } 554 | // 存值操作 555 | RedisState setHandle(const std::string& key, const std::string& value) { 556 | std::string cmd = "set " + key + " " + value; 557 | return execute(cmd); 558 | } 559 | // 取值操作 560 | RedisState getHandle(const std::string& key, std::string& value) { 561 | std::string cmd = "get " + key; 562 | return execute(cmd, &value); 563 | } 564 | 565 | 566 | 567 | private: 568 | std::string m_host; //连接地址 569 | int m_port; //端口号 570 | std::string m_pwd; //密码 571 | /* 572 | typedef struct redisContext { 573 | int err; 574 | char errstr[128]; 575 | int fd; 576 | int flags; 577 | char *obuf; 578 | redisReader *reader; 579 | enum redisConnectionType connection_type; 580 | struct timeval *timeout; 581 | struct { 582 | char *host; 583 | char *source_addr; 584 | int port; 585 | } tcp; 586 | struct { 587 | char *path; 588 | } unix_sock; 589 | } redisContext; 590 | 591 | */ 592 | redisContext *m_rdsctx; //redis结构体 593 | /* 594 | typedef struct redisReply { 595 | //命令执行结果的返回类型 596 | int type; 597 | //存储执行结果返回为整数 598 | long long integer; 599 | //字符串值的长度 600 | size_t len; 601 | //存储命令执行结果返回是字符串 602 | char *str; 603 | //返回结果是数组的大小 604 | size_t elements; 605 | //存储执行结果返回是数组 606 | struct redisReply **element; 607 | } redisReply 608 | 609 | */ 610 | redisReply *m_rdsrep; //返回结果结构体 611 | 612 | std::string m_error_msg; //错误信息 613 | RedisState m_state; //状态码 614 | 615 | redisPool* m_pool; // 指向连接池 616 | MutexType m_mutex; // 互斥锁 617 | 618 | }; 619 | 620 | //mysql连接池 单例 621 | typedef ConnPool mysqlPool; 622 | typedef Singleton mysqlConnPoolMgr; 623 | 624 | /* 625 | mysql相关操作 626 | */ 627 | class MysqlHelper : public std::enable_shared_from_this { 628 | public: 629 | typedef std::shared_ptr ptr; 630 | 631 | //TODO 632 | 633 | }; 634 | 635 | #endif 636 | 637 | 638 | } 639 | 640 | 641 | 642 | 643 | #endif -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp: -------------------------------------------------------------------------------- 1 | /* This source file must have a .cpp extension so that all C++ compilers 2 | recognize the extension without flags. Borland does not know .cxx for 3 | example. */ 4 | #ifndef __cplusplus 5 | # error "A C compiler has been selected for C++." 6 | #endif 7 | 8 | 9 | /* Version number components: V=Version, R=Revision, P=Patch 10 | Version date components: YYYY=Year, MM=Month, DD=Day */ 11 | 12 | #if defined(__COMO__) 13 | # define COMPILER_ID "Comeau" 14 | /* __COMO_VERSION__ = VRR */ 15 | # define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) 16 | # define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) 17 | 18 | #elif defined(__INTEL_COMPILER) || defined(__ICC) 19 | # define COMPILER_ID "Intel" 20 | # if defined(_MSC_VER) 21 | # define SIMULATE_ID "MSVC" 22 | # endif 23 | # if defined(__GNUC__) 24 | # define SIMULATE_ID "GNU" 25 | # endif 26 | /* __INTEL_COMPILER = VRP */ 27 | # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) 28 | # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) 29 | # if defined(__INTEL_COMPILER_UPDATE) 30 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) 31 | # else 32 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) 33 | # endif 34 | # if defined(__INTEL_COMPILER_BUILD_DATE) 35 | /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ 36 | # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) 37 | # endif 38 | # if defined(_MSC_VER) 39 | /* _MSC_VER = VVRR */ 40 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 41 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 42 | # endif 43 | # if defined(__GNUC__) 44 | # define SIMULATE_VERSION_MAJOR DEC(__GNUC__) 45 | # elif defined(__GNUG__) 46 | # define SIMULATE_VERSION_MAJOR DEC(__GNUG__) 47 | # endif 48 | # if defined(__GNUC_MINOR__) 49 | # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) 50 | # endif 51 | # if defined(__GNUC_PATCHLEVEL__) 52 | # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 53 | # endif 54 | 55 | #elif defined(__PATHCC__) 56 | # define COMPILER_ID "PathScale" 57 | # define COMPILER_VERSION_MAJOR DEC(__PATHCC__) 58 | # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) 59 | # if defined(__PATHCC_PATCHLEVEL__) 60 | # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) 61 | # endif 62 | 63 | #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) 64 | # define COMPILER_ID "Embarcadero" 65 | # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) 66 | # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) 67 | # define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) 68 | 69 | #elif defined(__BORLANDC__) 70 | # define COMPILER_ID "Borland" 71 | /* __BORLANDC__ = 0xVRR */ 72 | # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) 73 | # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) 74 | 75 | #elif defined(__WATCOMC__) && __WATCOMC__ < 1200 76 | # define COMPILER_ID "Watcom" 77 | /* __WATCOMC__ = VVRR */ 78 | # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) 79 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 80 | # if (__WATCOMC__ % 10) > 0 81 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 82 | # endif 83 | 84 | #elif defined(__WATCOMC__) 85 | # define COMPILER_ID "OpenWatcom" 86 | /* __WATCOMC__ = VVRP + 1100 */ 87 | # define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) 88 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 89 | # if (__WATCOMC__ % 10) > 0 90 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 91 | # endif 92 | 93 | #elif defined(__SUNPRO_CC) 94 | # define COMPILER_ID "SunPro" 95 | # if __SUNPRO_CC >= 0x5100 96 | /* __SUNPRO_CC = 0xVRRP */ 97 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) 98 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) 99 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) 100 | # else 101 | /* __SUNPRO_CC = 0xVRP */ 102 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) 103 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) 104 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) 105 | # endif 106 | 107 | #elif defined(__HP_aCC) 108 | # define COMPILER_ID "HP" 109 | /* __HP_aCC = VVRRPP */ 110 | # define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) 111 | # define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) 112 | # define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) 113 | 114 | #elif defined(__DECCXX) 115 | # define COMPILER_ID "Compaq" 116 | /* __DECCXX_VER = VVRRTPPPP */ 117 | # define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) 118 | # define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) 119 | # define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) 120 | 121 | #elif defined(__IBMCPP__) && defined(__COMPILER_VER__) 122 | # define COMPILER_ID "zOS" 123 | /* __IBMCPP__ = VRP */ 124 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 125 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 126 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 127 | 128 | #elif defined(__ibmxl__) && defined(__clang__) 129 | # define COMPILER_ID "XLClang" 130 | # define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) 131 | # define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) 132 | # define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) 133 | # define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) 134 | 135 | 136 | #elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800 137 | # define COMPILER_ID "XL" 138 | /* __IBMCPP__ = VRP */ 139 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 140 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 141 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 142 | 143 | #elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800 144 | # define COMPILER_ID "VisualAge" 145 | /* __IBMCPP__ = VRP */ 146 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 147 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 148 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 149 | 150 | #elif defined(__PGI) 151 | # define COMPILER_ID "PGI" 152 | # define COMPILER_VERSION_MAJOR DEC(__PGIC__) 153 | # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) 154 | # if defined(__PGIC_PATCHLEVEL__) 155 | # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) 156 | # endif 157 | 158 | #elif defined(_CRAYC) 159 | # define COMPILER_ID "Cray" 160 | # define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) 161 | # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) 162 | 163 | #elif defined(__TI_COMPILER_VERSION__) 164 | # define COMPILER_ID "TI" 165 | /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ 166 | # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) 167 | # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) 168 | # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) 169 | 170 | #elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) 171 | # define COMPILER_ID "Fujitsu" 172 | 173 | #elif defined(__ghs__) 174 | # define COMPILER_ID "GHS" 175 | /* __GHS_VERSION_NUMBER = VVVVRP */ 176 | # ifdef __GHS_VERSION_NUMBER 177 | # define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) 178 | # define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) 179 | # define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) 180 | # endif 181 | 182 | #elif defined(__SCO_VERSION__) 183 | # define COMPILER_ID "SCO" 184 | 185 | #elif defined(__ARMCC_VERSION) && !defined(__clang__) 186 | # define COMPILER_ID "ARMCC" 187 | #if __ARMCC_VERSION >= 1000000 188 | /* __ARMCC_VERSION = VRRPPPP */ 189 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) 190 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) 191 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 192 | #else 193 | /* __ARMCC_VERSION = VRPPPP */ 194 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) 195 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) 196 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 197 | #endif 198 | 199 | 200 | #elif defined(__clang__) && defined(__apple_build_version__) 201 | # define COMPILER_ID "AppleClang" 202 | # if defined(_MSC_VER) 203 | # define SIMULATE_ID "MSVC" 204 | # endif 205 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 206 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 207 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 208 | # if defined(_MSC_VER) 209 | /* _MSC_VER = VVRR */ 210 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 211 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 212 | # endif 213 | # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) 214 | 215 | #elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) 216 | # define COMPILER_ID "ARMClang" 217 | # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) 218 | # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) 219 | # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) 220 | # define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) 221 | 222 | #elif defined(__clang__) 223 | # define COMPILER_ID "Clang" 224 | # if defined(_MSC_VER) 225 | # define SIMULATE_ID "MSVC" 226 | # endif 227 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 228 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 229 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 230 | # if defined(_MSC_VER) 231 | /* _MSC_VER = VVRR */ 232 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 233 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 234 | # endif 235 | 236 | #elif defined(__GNUC__) || defined(__GNUG__) 237 | # define COMPILER_ID "GNU" 238 | # if defined(__GNUC__) 239 | # define COMPILER_VERSION_MAJOR DEC(__GNUC__) 240 | # else 241 | # define COMPILER_VERSION_MAJOR DEC(__GNUG__) 242 | # endif 243 | # if defined(__GNUC_MINOR__) 244 | # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) 245 | # endif 246 | # if defined(__GNUC_PATCHLEVEL__) 247 | # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 248 | # endif 249 | 250 | #elif defined(_MSC_VER) 251 | # define COMPILER_ID "MSVC" 252 | /* _MSC_VER = VVRR */ 253 | # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) 254 | # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) 255 | # if defined(_MSC_FULL_VER) 256 | # if _MSC_VER >= 1400 257 | /* _MSC_FULL_VER = VVRRPPPPP */ 258 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) 259 | # else 260 | /* _MSC_FULL_VER = VVRRPPPP */ 261 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) 262 | # endif 263 | # endif 264 | # if defined(_MSC_BUILD) 265 | # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) 266 | # endif 267 | 268 | #elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) 269 | # define COMPILER_ID "ADSP" 270 | #if defined(__VISUALDSPVERSION__) 271 | /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ 272 | # define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) 273 | # define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) 274 | # define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) 275 | #endif 276 | 277 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 278 | # define COMPILER_ID "IAR" 279 | # if defined(__VER__) && defined(__ICCARM__) 280 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) 281 | # define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) 282 | # define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) 283 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 284 | # elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) 285 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) 286 | # define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) 287 | # define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) 288 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 289 | # endif 290 | 291 | 292 | /* These compilers are either not known or too old to define an 293 | identification macro. Try to identify the platform and guess that 294 | it is the native compiler. */ 295 | #elif defined(__hpux) || defined(__hpua) 296 | # define COMPILER_ID "HP" 297 | 298 | #else /* unknown compiler */ 299 | # define COMPILER_ID "" 300 | #endif 301 | 302 | /* Construct the string literal in pieces to prevent the source from 303 | getting matched. Store it in a pointer rather than an array 304 | because some compilers will just produce instructions to fill the 305 | array rather than assigning a pointer to a static array. */ 306 | char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; 307 | #ifdef SIMULATE_ID 308 | char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; 309 | #endif 310 | 311 | #ifdef __QNXNTO__ 312 | char const* qnxnto = "INFO" ":" "qnxnto[]"; 313 | #endif 314 | 315 | #if defined(__CRAYXE) || defined(__CRAYXC) 316 | char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; 317 | #endif 318 | 319 | #define STRINGIFY_HELPER(X) #X 320 | #define STRINGIFY(X) STRINGIFY_HELPER(X) 321 | 322 | /* Identify known platforms by name. */ 323 | #if defined(__linux) || defined(__linux__) || defined(linux) 324 | # define PLATFORM_ID "Linux" 325 | 326 | #elif defined(__CYGWIN__) 327 | # define PLATFORM_ID "Cygwin" 328 | 329 | #elif defined(__MINGW32__) 330 | # define PLATFORM_ID "MinGW" 331 | 332 | #elif defined(__APPLE__) 333 | # define PLATFORM_ID "Darwin" 334 | 335 | #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 336 | # define PLATFORM_ID "Windows" 337 | 338 | #elif defined(__FreeBSD__) || defined(__FreeBSD) 339 | # define PLATFORM_ID "FreeBSD" 340 | 341 | #elif defined(__NetBSD__) || defined(__NetBSD) 342 | # define PLATFORM_ID "NetBSD" 343 | 344 | #elif defined(__OpenBSD__) || defined(__OPENBSD) 345 | # define PLATFORM_ID "OpenBSD" 346 | 347 | #elif defined(__sun) || defined(sun) 348 | # define PLATFORM_ID "SunOS" 349 | 350 | #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) 351 | # define PLATFORM_ID "AIX" 352 | 353 | #elif defined(__hpux) || defined(__hpux__) 354 | # define PLATFORM_ID "HP-UX" 355 | 356 | #elif defined(__HAIKU__) 357 | # define PLATFORM_ID "Haiku" 358 | 359 | #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) 360 | # define PLATFORM_ID "BeOS" 361 | 362 | #elif defined(__QNX__) || defined(__QNXNTO__) 363 | # define PLATFORM_ID "QNX" 364 | 365 | #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) 366 | # define PLATFORM_ID "Tru64" 367 | 368 | #elif defined(__riscos) || defined(__riscos__) 369 | # define PLATFORM_ID "RISCos" 370 | 371 | #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) 372 | # define PLATFORM_ID "SINIX" 373 | 374 | #elif defined(__UNIX_SV__) 375 | # define PLATFORM_ID "UNIX_SV" 376 | 377 | #elif defined(__bsdos__) 378 | # define PLATFORM_ID "BSDOS" 379 | 380 | #elif defined(_MPRAS) || defined(MPRAS) 381 | # define PLATFORM_ID "MP-RAS" 382 | 383 | #elif defined(__osf) || defined(__osf__) 384 | # define PLATFORM_ID "OSF1" 385 | 386 | #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) 387 | # define PLATFORM_ID "SCO_SV" 388 | 389 | #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) 390 | # define PLATFORM_ID "ULTRIX" 391 | 392 | #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) 393 | # define PLATFORM_ID "Xenix" 394 | 395 | #elif defined(__WATCOMC__) 396 | # if defined(__LINUX__) 397 | # define PLATFORM_ID "Linux" 398 | 399 | # elif defined(__DOS__) 400 | # define PLATFORM_ID "DOS" 401 | 402 | # elif defined(__OS2__) 403 | # define PLATFORM_ID "OS2" 404 | 405 | # elif defined(__WINDOWS__) 406 | # define PLATFORM_ID "Windows3x" 407 | 408 | # else /* unknown platform */ 409 | # define PLATFORM_ID 410 | # endif 411 | 412 | #elif defined(__INTEGRITY) 413 | # if defined(INT_178B) 414 | # define PLATFORM_ID "Integrity178" 415 | 416 | # else /* regular Integrity */ 417 | # define PLATFORM_ID "Integrity" 418 | # endif 419 | 420 | #else /* unknown platform */ 421 | # define PLATFORM_ID 422 | 423 | #endif 424 | 425 | /* For windows compilers MSVC and Intel we can determine 426 | the architecture of the compiler being used. This is because 427 | the compilers do not have flags that can change the architecture, 428 | but rather depend on which compiler is being used 429 | */ 430 | #if defined(_WIN32) && defined(_MSC_VER) 431 | # if defined(_M_IA64) 432 | # define ARCHITECTURE_ID "IA64" 433 | 434 | # elif defined(_M_X64) || defined(_M_AMD64) 435 | # define ARCHITECTURE_ID "x64" 436 | 437 | # elif defined(_M_IX86) 438 | # define ARCHITECTURE_ID "X86" 439 | 440 | # elif defined(_M_ARM64) 441 | # define ARCHITECTURE_ID "ARM64" 442 | 443 | # elif defined(_M_ARM) 444 | # if _M_ARM == 4 445 | # define ARCHITECTURE_ID "ARMV4I" 446 | # elif _M_ARM == 5 447 | # define ARCHITECTURE_ID "ARMV5I" 448 | # else 449 | # define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) 450 | # endif 451 | 452 | # elif defined(_M_MIPS) 453 | # define ARCHITECTURE_ID "MIPS" 454 | 455 | # elif defined(_M_SH) 456 | # define ARCHITECTURE_ID "SHx" 457 | 458 | # else /* unknown architecture */ 459 | # define ARCHITECTURE_ID "" 460 | # endif 461 | 462 | #elif defined(__WATCOMC__) 463 | # if defined(_M_I86) 464 | # define ARCHITECTURE_ID "I86" 465 | 466 | # elif defined(_M_IX86) 467 | # define ARCHITECTURE_ID "X86" 468 | 469 | # else /* unknown architecture */ 470 | # define ARCHITECTURE_ID "" 471 | # endif 472 | 473 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 474 | # if defined(__ICCARM__) 475 | # define ARCHITECTURE_ID "ARM" 476 | 477 | # elif defined(__ICCRX__) 478 | # define ARCHITECTURE_ID "RX" 479 | 480 | # elif defined(__ICCRH850__) 481 | # define ARCHITECTURE_ID "RH850" 482 | 483 | # elif defined(__ICCRL78__) 484 | # define ARCHITECTURE_ID "RL78" 485 | 486 | # elif defined(__ICCRISCV__) 487 | # define ARCHITECTURE_ID "RISCV" 488 | 489 | # elif defined(__ICCAVR__) 490 | # define ARCHITECTURE_ID "AVR" 491 | 492 | # elif defined(__ICC430__) 493 | # define ARCHITECTURE_ID "MSP430" 494 | 495 | # elif defined(__ICCV850__) 496 | # define ARCHITECTURE_ID "V850" 497 | 498 | # elif defined(__ICC8051__) 499 | # define ARCHITECTURE_ID "8051" 500 | 501 | # else /* unknown architecture */ 502 | # define ARCHITECTURE_ID "" 503 | # endif 504 | 505 | #elif defined(__ghs__) 506 | # if defined(__PPC64__) 507 | # define ARCHITECTURE_ID "PPC64" 508 | 509 | # elif defined(__ppc__) 510 | # define ARCHITECTURE_ID "PPC" 511 | 512 | # elif defined(__ARM__) 513 | # define ARCHITECTURE_ID "ARM" 514 | 515 | # elif defined(__x86_64__) 516 | # define ARCHITECTURE_ID "x64" 517 | 518 | # elif defined(__i386__) 519 | # define ARCHITECTURE_ID "X86" 520 | 521 | # else /* unknown architecture */ 522 | # define ARCHITECTURE_ID "" 523 | # endif 524 | #else 525 | # define ARCHITECTURE_ID 526 | #endif 527 | 528 | /* Convert integer to decimal digit literals. */ 529 | #define DEC(n) \ 530 | ('0' + (((n) / 10000000)%10)), \ 531 | ('0' + (((n) / 1000000)%10)), \ 532 | ('0' + (((n) / 100000)%10)), \ 533 | ('0' + (((n) / 10000)%10)), \ 534 | ('0' + (((n) / 1000)%10)), \ 535 | ('0' + (((n) / 100)%10)), \ 536 | ('0' + (((n) / 10)%10)), \ 537 | ('0' + ((n) % 10)) 538 | 539 | /* Convert integer to hex digit literals. */ 540 | #define HEX(n) \ 541 | ('0' + ((n)>>28 & 0xF)), \ 542 | ('0' + ((n)>>24 & 0xF)), \ 543 | ('0' + ((n)>>20 & 0xF)), \ 544 | ('0' + ((n)>>16 & 0xF)), \ 545 | ('0' + ((n)>>12 & 0xF)), \ 546 | ('0' + ((n)>>8 & 0xF)), \ 547 | ('0' + ((n)>>4 & 0xF)), \ 548 | ('0' + ((n) & 0xF)) 549 | 550 | /* Construct a string literal encoding the version number components. */ 551 | #ifdef COMPILER_VERSION_MAJOR 552 | char const info_version[] = { 553 | 'I', 'N', 'F', 'O', ':', 554 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', 555 | COMPILER_VERSION_MAJOR, 556 | # ifdef COMPILER_VERSION_MINOR 557 | '.', COMPILER_VERSION_MINOR, 558 | # ifdef COMPILER_VERSION_PATCH 559 | '.', COMPILER_VERSION_PATCH, 560 | # ifdef COMPILER_VERSION_TWEAK 561 | '.', COMPILER_VERSION_TWEAK, 562 | # endif 563 | # endif 564 | # endif 565 | ']','\0'}; 566 | #endif 567 | 568 | /* Construct a string literal encoding the internal version number. */ 569 | #ifdef COMPILER_VERSION_INTERNAL 570 | char const info_version_internal[] = { 571 | 'I', 'N', 'F', 'O', ':', 572 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', 573 | 'i','n','t','e','r','n','a','l','[', 574 | COMPILER_VERSION_INTERNAL,']','\0'}; 575 | #endif 576 | 577 | /* Construct a string literal encoding the version number components. */ 578 | #ifdef SIMULATE_VERSION_MAJOR 579 | char const info_simulate_version[] = { 580 | 'I', 'N', 'F', 'O', ':', 581 | 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', 582 | SIMULATE_VERSION_MAJOR, 583 | # ifdef SIMULATE_VERSION_MINOR 584 | '.', SIMULATE_VERSION_MINOR, 585 | # ifdef SIMULATE_VERSION_PATCH 586 | '.', SIMULATE_VERSION_PATCH, 587 | # ifdef SIMULATE_VERSION_TWEAK 588 | '.', SIMULATE_VERSION_TWEAK, 589 | # endif 590 | # endif 591 | # endif 592 | ']','\0'}; 593 | #endif 594 | 595 | /* Construct the string literal in pieces to prevent the source from 596 | getting matched. Store it in a pointer rather than an array 597 | because some compilers will just produce instructions to fill the 598 | array rather than assigning a pointer to a static array. */ 599 | char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; 600 | char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; 601 | 602 | 603 | 604 | 605 | #if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L 606 | # if defined(__INTEL_CXX11_MODE__) 607 | # if defined(__cpp_aggregate_nsdmi) 608 | # define CXX_STD 201402L 609 | # else 610 | # define CXX_STD 201103L 611 | # endif 612 | # else 613 | # define CXX_STD 199711L 614 | # endif 615 | #elif defined(_MSC_VER) && defined(_MSVC_LANG) 616 | # define CXX_STD _MSVC_LANG 617 | #else 618 | # define CXX_STD __cplusplus 619 | #endif 620 | 621 | const char* info_language_dialect_default = "INFO" ":" "dialect_default[" 622 | #if CXX_STD > 201703L 623 | "20" 624 | #elif CXX_STD >= 201703L 625 | "17" 626 | #elif CXX_STD >= 201402L 627 | "14" 628 | #elif CXX_STD >= 201103L 629 | "11" 630 | #else 631 | "98" 632 | #endif 633 | "]"; 634 | 635 | /*--------------------------------------------------------------------------*/ 636 | 637 | int main(int argc, char* argv[]) 638 | { 639 | int require = 0; 640 | require += info_compiler[argc]; 641 | require += info_platform[argc]; 642 | #ifdef COMPILER_VERSION_MAJOR 643 | require += info_version[argc]; 644 | #endif 645 | #ifdef COMPILER_VERSION_INTERNAL 646 | require += info_version_internal[argc]; 647 | #endif 648 | #ifdef SIMULATE_ID 649 | require += info_simulate[argc]; 650 | #endif 651 | #ifdef SIMULATE_VERSION_MAJOR 652 | require += info_simulate_version[argc]; 653 | #endif 654 | #if defined(__CRAYXE) || defined(__CRAYXC) 655 | require += info_cray[argc]; 656 | #endif 657 | require += info_language_dialect_default[argc]; 658 | (void)argv; 659 | return require; 660 | } 661 | -------------------------------------------------------------------------------- /CMakeFiles/3.18.6/CompilerIdCXX/CMakeCXXCompilerId.cpp: -------------------------------------------------------------------------------- 1 | /* This source file must have a .cpp extension so that all C++ compilers 2 | recognize the extension without flags. Borland does not know .cxx for 3 | example. */ 4 | #ifndef __cplusplus 5 | # error "A C compiler has been selected for C++." 6 | #endif 7 | 8 | 9 | /* Version number components: V=Version, R=Revision, P=Patch 10 | Version date components: YYYY=Year, MM=Month, DD=Day */ 11 | 12 | #if defined(__COMO__) 13 | # define COMPILER_ID "Comeau" 14 | /* __COMO_VERSION__ = VRR */ 15 | # define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) 16 | # define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) 17 | 18 | #elif defined(__INTEL_COMPILER) || defined(__ICC) 19 | # define COMPILER_ID "Intel" 20 | # if defined(_MSC_VER) 21 | # define SIMULATE_ID "MSVC" 22 | # endif 23 | # if defined(__GNUC__) 24 | # define SIMULATE_ID "GNU" 25 | # endif 26 | /* __INTEL_COMPILER = VRP */ 27 | # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) 28 | # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) 29 | # if defined(__INTEL_COMPILER_UPDATE) 30 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) 31 | # else 32 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) 33 | # endif 34 | # if defined(__INTEL_COMPILER_BUILD_DATE) 35 | /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ 36 | # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) 37 | # endif 38 | # if defined(_MSC_VER) 39 | /* _MSC_VER = VVRR */ 40 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 41 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 42 | # endif 43 | # if defined(__GNUC__) 44 | # define SIMULATE_VERSION_MAJOR DEC(__GNUC__) 45 | # elif defined(__GNUG__) 46 | # define SIMULATE_VERSION_MAJOR DEC(__GNUG__) 47 | # endif 48 | # if defined(__GNUC_MINOR__) 49 | # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) 50 | # endif 51 | # if defined(__GNUC_PATCHLEVEL__) 52 | # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 53 | # endif 54 | 55 | #elif defined(__PATHCC__) 56 | # define COMPILER_ID "PathScale" 57 | # define COMPILER_VERSION_MAJOR DEC(__PATHCC__) 58 | # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) 59 | # if defined(__PATHCC_PATCHLEVEL__) 60 | # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) 61 | # endif 62 | 63 | #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) 64 | # define COMPILER_ID "Embarcadero" 65 | # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) 66 | # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) 67 | # define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) 68 | 69 | #elif defined(__BORLANDC__) 70 | # define COMPILER_ID "Borland" 71 | /* __BORLANDC__ = 0xVRR */ 72 | # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) 73 | # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) 74 | 75 | #elif defined(__WATCOMC__) && __WATCOMC__ < 1200 76 | # define COMPILER_ID "Watcom" 77 | /* __WATCOMC__ = VVRR */ 78 | # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) 79 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 80 | # if (__WATCOMC__ % 10) > 0 81 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 82 | # endif 83 | 84 | #elif defined(__WATCOMC__) 85 | # define COMPILER_ID "OpenWatcom" 86 | /* __WATCOMC__ = VVRP + 1100 */ 87 | # define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) 88 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 89 | # if (__WATCOMC__ % 10) > 0 90 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 91 | # endif 92 | 93 | #elif defined(__SUNPRO_CC) 94 | # define COMPILER_ID "SunPro" 95 | # if __SUNPRO_CC >= 0x5100 96 | /* __SUNPRO_CC = 0xVRRP */ 97 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) 98 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) 99 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) 100 | # else 101 | /* __SUNPRO_CC = 0xVRP */ 102 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) 103 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) 104 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) 105 | # endif 106 | 107 | #elif defined(__HP_aCC) 108 | # define COMPILER_ID "HP" 109 | /* __HP_aCC = VVRRPP */ 110 | # define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) 111 | # define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) 112 | # define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) 113 | 114 | #elif defined(__DECCXX) 115 | # define COMPILER_ID "Compaq" 116 | /* __DECCXX_VER = VVRRTPPPP */ 117 | # define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) 118 | # define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) 119 | # define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) 120 | 121 | #elif defined(__IBMCPP__) && defined(__COMPILER_VER__) 122 | # define COMPILER_ID "zOS" 123 | /* __IBMCPP__ = VRP */ 124 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 125 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 126 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 127 | 128 | #elif defined(__ibmxl__) && defined(__clang__) 129 | # define COMPILER_ID "XLClang" 130 | # define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) 131 | # define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) 132 | # define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) 133 | # define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) 134 | 135 | 136 | #elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800 137 | # define COMPILER_ID "XL" 138 | /* __IBMCPP__ = VRP */ 139 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 140 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 141 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 142 | 143 | #elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800 144 | # define COMPILER_ID "VisualAge" 145 | /* __IBMCPP__ = VRP */ 146 | # define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) 147 | # define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) 148 | # define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) 149 | 150 | #elif defined(__PGI) 151 | # define COMPILER_ID "PGI" 152 | # define COMPILER_VERSION_MAJOR DEC(__PGIC__) 153 | # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) 154 | # if defined(__PGIC_PATCHLEVEL__) 155 | # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) 156 | # endif 157 | 158 | #elif defined(_CRAYC) 159 | # define COMPILER_ID "Cray" 160 | # define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) 161 | # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) 162 | 163 | #elif defined(__TI_COMPILER_VERSION__) 164 | # define COMPILER_ID "TI" 165 | /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ 166 | # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) 167 | # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) 168 | # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) 169 | 170 | #elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) 171 | # define COMPILER_ID "Fujitsu" 172 | 173 | #elif defined(__ghs__) 174 | # define COMPILER_ID "GHS" 175 | /* __GHS_VERSION_NUMBER = VVVVRP */ 176 | # ifdef __GHS_VERSION_NUMBER 177 | # define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) 178 | # define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) 179 | # define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) 180 | # endif 181 | 182 | #elif defined(__SCO_VERSION__) 183 | # define COMPILER_ID "SCO" 184 | 185 | #elif defined(__ARMCC_VERSION) && !defined(__clang__) 186 | # define COMPILER_ID "ARMCC" 187 | #if __ARMCC_VERSION >= 1000000 188 | /* __ARMCC_VERSION = VRRPPPP */ 189 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) 190 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) 191 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 192 | #else 193 | /* __ARMCC_VERSION = VRPPPP */ 194 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) 195 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) 196 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 197 | #endif 198 | 199 | 200 | #elif defined(__clang__) && defined(__apple_build_version__) 201 | # define COMPILER_ID "AppleClang" 202 | # if defined(_MSC_VER) 203 | # define SIMULATE_ID "MSVC" 204 | # endif 205 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 206 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 207 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 208 | # if defined(_MSC_VER) 209 | /* _MSC_VER = VVRR */ 210 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 211 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 212 | # endif 213 | # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) 214 | 215 | #elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) 216 | # define COMPILER_ID "ARMClang" 217 | # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) 218 | # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) 219 | # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) 220 | # define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) 221 | 222 | #elif defined(__clang__) 223 | # define COMPILER_ID "Clang" 224 | # if defined(_MSC_VER) 225 | # define SIMULATE_ID "MSVC" 226 | # endif 227 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 228 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 229 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 230 | # if defined(_MSC_VER) 231 | /* _MSC_VER = VVRR */ 232 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 233 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 234 | # endif 235 | 236 | #elif defined(__GNUC__) || defined(__GNUG__) 237 | # define COMPILER_ID "GNU" 238 | # if defined(__GNUC__) 239 | # define COMPILER_VERSION_MAJOR DEC(__GNUC__) 240 | # else 241 | # define COMPILER_VERSION_MAJOR DEC(__GNUG__) 242 | # endif 243 | # if defined(__GNUC_MINOR__) 244 | # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) 245 | # endif 246 | # if defined(__GNUC_PATCHLEVEL__) 247 | # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 248 | # endif 249 | 250 | #elif defined(_MSC_VER) 251 | # define COMPILER_ID "MSVC" 252 | /* _MSC_VER = VVRR */ 253 | # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) 254 | # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) 255 | # if defined(_MSC_FULL_VER) 256 | # if _MSC_VER >= 1400 257 | /* _MSC_FULL_VER = VVRRPPPPP */ 258 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) 259 | # else 260 | /* _MSC_FULL_VER = VVRRPPPP */ 261 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) 262 | # endif 263 | # endif 264 | # if defined(_MSC_BUILD) 265 | # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) 266 | # endif 267 | 268 | #elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) 269 | # define COMPILER_ID "ADSP" 270 | #if defined(__VISUALDSPVERSION__) 271 | /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ 272 | # define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) 273 | # define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) 274 | # define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) 275 | #endif 276 | 277 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 278 | # define COMPILER_ID "IAR" 279 | # if defined(__VER__) && defined(__ICCARM__) 280 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) 281 | # define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) 282 | # define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) 283 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 284 | # elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) 285 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) 286 | # define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) 287 | # define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) 288 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 289 | # endif 290 | 291 | 292 | /* These compilers are either not known or too old to define an 293 | identification macro. Try to identify the platform and guess that 294 | it is the native compiler. */ 295 | #elif defined(__hpux) || defined(__hpua) 296 | # define COMPILER_ID "HP" 297 | 298 | #else /* unknown compiler */ 299 | # define COMPILER_ID "" 300 | #endif 301 | 302 | /* Construct the string literal in pieces to prevent the source from 303 | getting matched. Store it in a pointer rather than an array 304 | because some compilers will just produce instructions to fill the 305 | array rather than assigning a pointer to a static array. */ 306 | char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; 307 | #ifdef SIMULATE_ID 308 | char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; 309 | #endif 310 | 311 | #ifdef __QNXNTO__ 312 | char const* qnxnto = "INFO" ":" "qnxnto[]"; 313 | #endif 314 | 315 | #if defined(__CRAYXE) || defined(__CRAYXC) 316 | char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; 317 | #endif 318 | 319 | #define STRINGIFY_HELPER(X) #X 320 | #define STRINGIFY(X) STRINGIFY_HELPER(X) 321 | 322 | /* Identify known platforms by name. */ 323 | #if defined(__linux) || defined(__linux__) || defined(linux) 324 | # define PLATFORM_ID "Linux" 325 | 326 | #elif defined(__CYGWIN__) 327 | # define PLATFORM_ID "Cygwin" 328 | 329 | #elif defined(__MINGW32__) 330 | # define PLATFORM_ID "MinGW" 331 | 332 | #elif defined(__APPLE__) 333 | # define PLATFORM_ID "Darwin" 334 | 335 | #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 336 | # define PLATFORM_ID "Windows" 337 | 338 | #elif defined(__FreeBSD__) || defined(__FreeBSD) 339 | # define PLATFORM_ID "FreeBSD" 340 | 341 | #elif defined(__NetBSD__) || defined(__NetBSD) 342 | # define PLATFORM_ID "NetBSD" 343 | 344 | #elif defined(__OpenBSD__) || defined(__OPENBSD) 345 | # define PLATFORM_ID "OpenBSD" 346 | 347 | #elif defined(__sun) || defined(sun) 348 | # define PLATFORM_ID "SunOS" 349 | 350 | #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) 351 | # define PLATFORM_ID "AIX" 352 | 353 | #elif defined(__hpux) || defined(__hpux__) 354 | # define PLATFORM_ID "HP-UX" 355 | 356 | #elif defined(__HAIKU__) 357 | # define PLATFORM_ID "Haiku" 358 | 359 | #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) 360 | # define PLATFORM_ID "BeOS" 361 | 362 | #elif defined(__QNX__) || defined(__QNXNTO__) 363 | # define PLATFORM_ID "QNX" 364 | 365 | #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) 366 | # define PLATFORM_ID "Tru64" 367 | 368 | #elif defined(__riscos) || defined(__riscos__) 369 | # define PLATFORM_ID "RISCos" 370 | 371 | #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) 372 | # define PLATFORM_ID "SINIX" 373 | 374 | #elif defined(__UNIX_SV__) 375 | # define PLATFORM_ID "UNIX_SV" 376 | 377 | #elif defined(__bsdos__) 378 | # define PLATFORM_ID "BSDOS" 379 | 380 | #elif defined(_MPRAS) || defined(MPRAS) 381 | # define PLATFORM_ID "MP-RAS" 382 | 383 | #elif defined(__osf) || defined(__osf__) 384 | # define PLATFORM_ID "OSF1" 385 | 386 | #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) 387 | # define PLATFORM_ID "SCO_SV" 388 | 389 | #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) 390 | # define PLATFORM_ID "ULTRIX" 391 | 392 | #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) 393 | # define PLATFORM_ID "Xenix" 394 | 395 | #elif defined(__WATCOMC__) 396 | # if defined(__LINUX__) 397 | # define PLATFORM_ID "Linux" 398 | 399 | # elif defined(__DOS__) 400 | # define PLATFORM_ID "DOS" 401 | 402 | # elif defined(__OS2__) 403 | # define PLATFORM_ID "OS2" 404 | 405 | # elif defined(__WINDOWS__) 406 | # define PLATFORM_ID "Windows3x" 407 | 408 | # elif defined(__VXWORKS__) 409 | # define PLATFORM_ID "VxWorks" 410 | 411 | # else /* unknown platform */ 412 | # define PLATFORM_ID 413 | # endif 414 | 415 | #elif defined(__INTEGRITY) 416 | # if defined(INT_178B) 417 | # define PLATFORM_ID "Integrity178" 418 | 419 | # else /* regular Integrity */ 420 | # define PLATFORM_ID "Integrity" 421 | # endif 422 | 423 | #else /* unknown platform */ 424 | # define PLATFORM_ID 425 | 426 | #endif 427 | 428 | /* For windows compilers MSVC and Intel we can determine 429 | the architecture of the compiler being used. This is because 430 | the compilers do not have flags that can change the architecture, 431 | but rather depend on which compiler is being used 432 | */ 433 | #if defined(_WIN32) && defined(_MSC_VER) 434 | # if defined(_M_IA64) 435 | # define ARCHITECTURE_ID "IA64" 436 | 437 | # elif defined(_M_X64) || defined(_M_AMD64) 438 | # define ARCHITECTURE_ID "x64" 439 | 440 | # elif defined(_M_IX86) 441 | # define ARCHITECTURE_ID "X86" 442 | 443 | # elif defined(_M_ARM64) 444 | # define ARCHITECTURE_ID "ARM64" 445 | 446 | # elif defined(_M_ARM) 447 | # if _M_ARM == 4 448 | # define ARCHITECTURE_ID "ARMV4I" 449 | # elif _M_ARM == 5 450 | # define ARCHITECTURE_ID "ARMV5I" 451 | # else 452 | # define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) 453 | # endif 454 | 455 | # elif defined(_M_MIPS) 456 | # define ARCHITECTURE_ID "MIPS" 457 | 458 | # elif defined(_M_SH) 459 | # define ARCHITECTURE_ID "SHx" 460 | 461 | # else /* unknown architecture */ 462 | # define ARCHITECTURE_ID "" 463 | # endif 464 | 465 | #elif defined(__WATCOMC__) 466 | # if defined(_M_I86) 467 | # define ARCHITECTURE_ID "I86" 468 | 469 | # elif defined(_M_IX86) 470 | # define ARCHITECTURE_ID "X86" 471 | 472 | # else /* unknown architecture */ 473 | # define ARCHITECTURE_ID "" 474 | # endif 475 | 476 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 477 | # if defined(__ICCARM__) 478 | # define ARCHITECTURE_ID "ARM" 479 | 480 | # elif defined(__ICCRX__) 481 | # define ARCHITECTURE_ID "RX" 482 | 483 | # elif defined(__ICCRH850__) 484 | # define ARCHITECTURE_ID "RH850" 485 | 486 | # elif defined(__ICCRL78__) 487 | # define ARCHITECTURE_ID "RL78" 488 | 489 | # elif defined(__ICCRISCV__) 490 | # define ARCHITECTURE_ID "RISCV" 491 | 492 | # elif defined(__ICCAVR__) 493 | # define ARCHITECTURE_ID "AVR" 494 | 495 | # elif defined(__ICC430__) 496 | # define ARCHITECTURE_ID "MSP430" 497 | 498 | # elif defined(__ICCV850__) 499 | # define ARCHITECTURE_ID "V850" 500 | 501 | # elif defined(__ICC8051__) 502 | # define ARCHITECTURE_ID "8051" 503 | 504 | # else /* unknown architecture */ 505 | # define ARCHITECTURE_ID "" 506 | # endif 507 | 508 | #elif defined(__ghs__) 509 | # if defined(__PPC64__) 510 | # define ARCHITECTURE_ID "PPC64" 511 | 512 | # elif defined(__ppc__) 513 | # define ARCHITECTURE_ID "PPC" 514 | 515 | # elif defined(__ARM__) 516 | # define ARCHITECTURE_ID "ARM" 517 | 518 | # elif defined(__x86_64__) 519 | # define ARCHITECTURE_ID "x64" 520 | 521 | # elif defined(__i386__) 522 | # define ARCHITECTURE_ID "X86" 523 | 524 | # else /* unknown architecture */ 525 | # define ARCHITECTURE_ID "" 526 | # endif 527 | #else 528 | # define ARCHITECTURE_ID 529 | #endif 530 | 531 | /* Convert integer to decimal digit literals. */ 532 | #define DEC(n) \ 533 | ('0' + (((n) / 10000000)%10)), \ 534 | ('0' + (((n) / 1000000)%10)), \ 535 | ('0' + (((n) / 100000)%10)), \ 536 | ('0' + (((n) / 10000)%10)), \ 537 | ('0' + (((n) / 1000)%10)), \ 538 | ('0' + (((n) / 100)%10)), \ 539 | ('0' + (((n) / 10)%10)), \ 540 | ('0' + ((n) % 10)) 541 | 542 | /* Convert integer to hex digit literals. */ 543 | #define HEX(n) \ 544 | ('0' + ((n)>>28 & 0xF)), \ 545 | ('0' + ((n)>>24 & 0xF)), \ 546 | ('0' + ((n)>>20 & 0xF)), \ 547 | ('0' + ((n)>>16 & 0xF)), \ 548 | ('0' + ((n)>>12 & 0xF)), \ 549 | ('0' + ((n)>>8 & 0xF)), \ 550 | ('0' + ((n)>>4 & 0xF)), \ 551 | ('0' + ((n) & 0xF)) 552 | 553 | /* Construct a string literal encoding the version number components. */ 554 | #ifdef COMPILER_VERSION_MAJOR 555 | char const info_version[] = { 556 | 'I', 'N', 'F', 'O', ':', 557 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', 558 | COMPILER_VERSION_MAJOR, 559 | # ifdef COMPILER_VERSION_MINOR 560 | '.', COMPILER_VERSION_MINOR, 561 | # ifdef COMPILER_VERSION_PATCH 562 | '.', COMPILER_VERSION_PATCH, 563 | # ifdef COMPILER_VERSION_TWEAK 564 | '.', COMPILER_VERSION_TWEAK, 565 | # endif 566 | # endif 567 | # endif 568 | ']','\0'}; 569 | #endif 570 | 571 | /* Construct a string literal encoding the internal version number. */ 572 | #ifdef COMPILER_VERSION_INTERNAL 573 | char const info_version_internal[] = { 574 | 'I', 'N', 'F', 'O', ':', 575 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', 576 | 'i','n','t','e','r','n','a','l','[', 577 | COMPILER_VERSION_INTERNAL,']','\0'}; 578 | #endif 579 | 580 | /* Construct a string literal encoding the version number components. */ 581 | #ifdef SIMULATE_VERSION_MAJOR 582 | char const info_simulate_version[] = { 583 | 'I', 'N', 'F', 'O', ':', 584 | 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', 585 | SIMULATE_VERSION_MAJOR, 586 | # ifdef SIMULATE_VERSION_MINOR 587 | '.', SIMULATE_VERSION_MINOR, 588 | # ifdef SIMULATE_VERSION_PATCH 589 | '.', SIMULATE_VERSION_PATCH, 590 | # ifdef SIMULATE_VERSION_TWEAK 591 | '.', SIMULATE_VERSION_TWEAK, 592 | # endif 593 | # endif 594 | # endif 595 | ']','\0'}; 596 | #endif 597 | 598 | /* Construct the string literal in pieces to prevent the source from 599 | getting matched. Store it in a pointer rather than an array 600 | because some compilers will just produce instructions to fill the 601 | array rather than assigning a pointer to a static array. */ 602 | char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; 603 | char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; 604 | 605 | 606 | 607 | 608 | #if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L 609 | # if defined(__INTEL_CXX11_MODE__) 610 | # if defined(__cpp_aggregate_nsdmi) 611 | # define CXX_STD 201402L 612 | # else 613 | # define CXX_STD 201103L 614 | # endif 615 | # else 616 | # define CXX_STD 199711L 617 | # endif 618 | #elif defined(_MSC_VER) && defined(_MSVC_LANG) 619 | # define CXX_STD _MSVC_LANG 620 | #else 621 | # define CXX_STD __cplusplus 622 | #endif 623 | 624 | const char* info_language_dialect_default = "INFO" ":" "dialect_default[" 625 | #if CXX_STD > 201703L 626 | "20" 627 | #elif CXX_STD >= 201703L 628 | "17" 629 | #elif CXX_STD >= 201402L 630 | "14" 631 | #elif CXX_STD >= 201103L 632 | "11" 633 | #else 634 | "98" 635 | #endif 636 | "]"; 637 | 638 | /*--------------------------------------------------------------------------*/ 639 | 640 | int main(int argc, char* argv[]) 641 | { 642 | int require = 0; 643 | require += info_compiler[argc]; 644 | require += info_platform[argc]; 645 | #ifdef COMPILER_VERSION_MAJOR 646 | require += info_version[argc]; 647 | #endif 648 | #ifdef COMPILER_VERSION_INTERNAL 649 | require += info_version_internal[argc]; 650 | #endif 651 | #ifdef SIMULATE_ID 652 | require += info_simulate[argc]; 653 | #endif 654 | #ifdef SIMULATE_VERSION_MAJOR 655 | require += info_simulate_version[argc]; 656 | #endif 657 | #if defined(__CRAYXE) || defined(__CRAYXC) 658 | require += info_cray[argc]; 659 | #endif 660 | require += info_language_dialect_default[argc]; 661 | (void)argv; 662 | return require; 663 | } 664 | -------------------------------------------------------------------------------- /CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | # error "A C++ compiler has been selected for C." 3 | #endif 4 | 5 | #if defined(__18CXX) 6 | # define ID_VOID_MAIN 7 | #endif 8 | #if defined(__CLASSIC_C__) 9 | /* cv-qualifiers did not exist in K&R C */ 10 | # define const 11 | # define volatile 12 | #endif 13 | 14 | 15 | /* Version number components: V=Version, R=Revision, P=Patch 16 | Version date components: YYYY=Year, MM=Month, DD=Day */ 17 | 18 | #if defined(__INTEL_COMPILER) || defined(__ICC) 19 | # define COMPILER_ID "Intel" 20 | # if defined(_MSC_VER) 21 | # define SIMULATE_ID "MSVC" 22 | # endif 23 | # if defined(__GNUC__) 24 | # define SIMULATE_ID "GNU" 25 | # endif 26 | /* __INTEL_COMPILER = VRP */ 27 | # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) 28 | # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) 29 | # if defined(__INTEL_COMPILER_UPDATE) 30 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) 31 | # else 32 | # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) 33 | # endif 34 | # if defined(__INTEL_COMPILER_BUILD_DATE) 35 | /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ 36 | # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) 37 | # endif 38 | # if defined(_MSC_VER) 39 | /* _MSC_VER = VVRR */ 40 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 41 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 42 | # endif 43 | # if defined(__GNUC__) 44 | # define SIMULATE_VERSION_MAJOR DEC(__GNUC__) 45 | # elif defined(__GNUG__) 46 | # define SIMULATE_VERSION_MAJOR DEC(__GNUG__) 47 | # endif 48 | # if defined(__GNUC_MINOR__) 49 | # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) 50 | # endif 51 | # if defined(__GNUC_PATCHLEVEL__) 52 | # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 53 | # endif 54 | 55 | #elif defined(__PATHCC__) 56 | # define COMPILER_ID "PathScale" 57 | # define COMPILER_VERSION_MAJOR DEC(__PATHCC__) 58 | # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) 59 | # if defined(__PATHCC_PATCHLEVEL__) 60 | # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) 61 | # endif 62 | 63 | #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) 64 | # define COMPILER_ID "Embarcadero" 65 | # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) 66 | # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) 67 | # define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) 68 | 69 | #elif defined(__BORLANDC__) 70 | # define COMPILER_ID "Borland" 71 | /* __BORLANDC__ = 0xVRR */ 72 | # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) 73 | # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) 74 | 75 | #elif defined(__WATCOMC__) && __WATCOMC__ < 1200 76 | # define COMPILER_ID "Watcom" 77 | /* __WATCOMC__ = VVRR */ 78 | # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) 79 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 80 | # if (__WATCOMC__ % 10) > 0 81 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 82 | # endif 83 | 84 | #elif defined(__WATCOMC__) 85 | # define COMPILER_ID "OpenWatcom" 86 | /* __WATCOMC__ = VVRP + 1100 */ 87 | # define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) 88 | # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) 89 | # if (__WATCOMC__ % 10) > 0 90 | # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) 91 | # endif 92 | 93 | #elif defined(__SUNPRO_C) 94 | # define COMPILER_ID "SunPro" 95 | # if __SUNPRO_C >= 0x5100 96 | /* __SUNPRO_C = 0xVRRP */ 97 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) 98 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) 99 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) 100 | # else 101 | /* __SUNPRO_CC = 0xVRP */ 102 | # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) 103 | # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) 104 | # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) 105 | # endif 106 | 107 | #elif defined(__HP_cc) 108 | # define COMPILER_ID "HP" 109 | /* __HP_cc = VVRRPP */ 110 | # define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) 111 | # define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) 112 | # define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) 113 | 114 | #elif defined(__DECC) 115 | # define COMPILER_ID "Compaq" 116 | /* __DECC_VER = VVRRTPPPP */ 117 | # define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) 118 | # define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) 119 | # define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) 120 | 121 | #elif defined(__IBMC__) && defined(__COMPILER_VER__) 122 | # define COMPILER_ID "zOS" 123 | /* __IBMC__ = VRP */ 124 | # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) 125 | # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) 126 | # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) 127 | 128 | #elif defined(__ibmxl__) && defined(__clang__) 129 | # define COMPILER_ID "XLClang" 130 | # define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) 131 | # define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) 132 | # define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) 133 | # define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) 134 | 135 | 136 | #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800 137 | # define COMPILER_ID "XL" 138 | /* __IBMC__ = VRP */ 139 | # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) 140 | # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) 141 | # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) 142 | 143 | #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800 144 | # define COMPILER_ID "VisualAge" 145 | /* __IBMC__ = VRP */ 146 | # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) 147 | # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) 148 | # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) 149 | 150 | #elif defined(__PGI) 151 | # define COMPILER_ID "PGI" 152 | # define COMPILER_VERSION_MAJOR DEC(__PGIC__) 153 | # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) 154 | # if defined(__PGIC_PATCHLEVEL__) 155 | # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) 156 | # endif 157 | 158 | #elif defined(_CRAYC) 159 | # define COMPILER_ID "Cray" 160 | # define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) 161 | # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) 162 | 163 | #elif defined(__TI_COMPILER_VERSION__) 164 | # define COMPILER_ID "TI" 165 | /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ 166 | # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) 167 | # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) 168 | # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) 169 | 170 | #elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) 171 | # define COMPILER_ID "Fujitsu" 172 | 173 | #elif defined(__ghs__) 174 | # define COMPILER_ID "GHS" 175 | /* __GHS_VERSION_NUMBER = VVVVRP */ 176 | # ifdef __GHS_VERSION_NUMBER 177 | # define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) 178 | # define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) 179 | # define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) 180 | # endif 181 | 182 | #elif defined(__TINYC__) 183 | # define COMPILER_ID "TinyCC" 184 | 185 | #elif defined(__BCC__) 186 | # define COMPILER_ID "Bruce" 187 | 188 | #elif defined(__SCO_VERSION__) 189 | # define COMPILER_ID "SCO" 190 | 191 | #elif defined(__ARMCC_VERSION) && !defined(__clang__) 192 | # define COMPILER_ID "ARMCC" 193 | #if __ARMCC_VERSION >= 1000000 194 | /* __ARMCC_VERSION = VRRPPPP */ 195 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) 196 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) 197 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 198 | #else 199 | /* __ARMCC_VERSION = VRPPPP */ 200 | # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) 201 | # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) 202 | # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) 203 | #endif 204 | 205 | 206 | #elif defined(__clang__) && defined(__apple_build_version__) 207 | # define COMPILER_ID "AppleClang" 208 | # if defined(_MSC_VER) 209 | # define SIMULATE_ID "MSVC" 210 | # endif 211 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 212 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 213 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 214 | # if defined(_MSC_VER) 215 | /* _MSC_VER = VVRR */ 216 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 217 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 218 | # endif 219 | # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) 220 | 221 | #elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) 222 | # define COMPILER_ID "ARMClang" 223 | # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) 224 | # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) 225 | # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) 226 | # define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) 227 | 228 | #elif defined(__clang__) 229 | # define COMPILER_ID "Clang" 230 | # if defined(_MSC_VER) 231 | # define SIMULATE_ID "MSVC" 232 | # endif 233 | # define COMPILER_VERSION_MAJOR DEC(__clang_major__) 234 | # define COMPILER_VERSION_MINOR DEC(__clang_minor__) 235 | # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) 236 | # if defined(_MSC_VER) 237 | /* _MSC_VER = VVRR */ 238 | # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) 239 | # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) 240 | # endif 241 | 242 | #elif defined(__GNUC__) 243 | # define COMPILER_ID "GNU" 244 | # define COMPILER_VERSION_MAJOR DEC(__GNUC__) 245 | # if defined(__GNUC_MINOR__) 246 | # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) 247 | # endif 248 | # if defined(__GNUC_PATCHLEVEL__) 249 | # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) 250 | # endif 251 | 252 | #elif defined(_MSC_VER) 253 | # define COMPILER_ID "MSVC" 254 | /* _MSC_VER = VVRR */ 255 | # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) 256 | # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) 257 | # if defined(_MSC_FULL_VER) 258 | # if _MSC_VER >= 1400 259 | /* _MSC_FULL_VER = VVRRPPPPP */ 260 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) 261 | # else 262 | /* _MSC_FULL_VER = VVRRPPPP */ 263 | # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) 264 | # endif 265 | # endif 266 | # if defined(_MSC_BUILD) 267 | # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) 268 | # endif 269 | 270 | #elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) 271 | # define COMPILER_ID "ADSP" 272 | #if defined(__VISUALDSPVERSION__) 273 | /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ 274 | # define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) 275 | # define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) 276 | # define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) 277 | #endif 278 | 279 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 280 | # define COMPILER_ID "IAR" 281 | # if defined(__VER__) && defined(__ICCARM__) 282 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) 283 | # define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) 284 | # define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) 285 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 286 | # elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) 287 | # define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) 288 | # define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) 289 | # define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) 290 | # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) 291 | # endif 292 | 293 | #elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC) 294 | # define COMPILER_ID "SDCC" 295 | # if defined(__SDCC_VERSION_MAJOR) 296 | # define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR) 297 | # define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR) 298 | # define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH) 299 | # else 300 | /* SDCC = VRP */ 301 | # define COMPILER_VERSION_MAJOR DEC(SDCC/100) 302 | # define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) 303 | # define COMPILER_VERSION_PATCH DEC(SDCC % 10) 304 | # endif 305 | 306 | 307 | /* These compilers are either not known or too old to define an 308 | identification macro. Try to identify the platform and guess that 309 | it is the native compiler. */ 310 | #elif defined(__hpux) || defined(__hpua) 311 | # define COMPILER_ID "HP" 312 | 313 | #else /* unknown compiler */ 314 | # define COMPILER_ID "" 315 | #endif 316 | 317 | /* Construct the string literal in pieces to prevent the source from 318 | getting matched. Store it in a pointer rather than an array 319 | because some compilers will just produce instructions to fill the 320 | array rather than assigning a pointer to a static array. */ 321 | char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; 322 | #ifdef SIMULATE_ID 323 | char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; 324 | #endif 325 | 326 | #ifdef __QNXNTO__ 327 | char const* qnxnto = "INFO" ":" "qnxnto[]"; 328 | #endif 329 | 330 | #if defined(__CRAYXE) || defined(__CRAYXC) 331 | char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; 332 | #endif 333 | 334 | #define STRINGIFY_HELPER(X) #X 335 | #define STRINGIFY(X) STRINGIFY_HELPER(X) 336 | 337 | /* Identify known platforms by name. */ 338 | #if defined(__linux) || defined(__linux__) || defined(linux) 339 | # define PLATFORM_ID "Linux" 340 | 341 | #elif defined(__CYGWIN__) 342 | # define PLATFORM_ID "Cygwin" 343 | 344 | #elif defined(__MINGW32__) 345 | # define PLATFORM_ID "MinGW" 346 | 347 | #elif defined(__APPLE__) 348 | # define PLATFORM_ID "Darwin" 349 | 350 | #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 351 | # define PLATFORM_ID "Windows" 352 | 353 | #elif defined(__FreeBSD__) || defined(__FreeBSD) 354 | # define PLATFORM_ID "FreeBSD" 355 | 356 | #elif defined(__NetBSD__) || defined(__NetBSD) 357 | # define PLATFORM_ID "NetBSD" 358 | 359 | #elif defined(__OpenBSD__) || defined(__OPENBSD) 360 | # define PLATFORM_ID "OpenBSD" 361 | 362 | #elif defined(__sun) || defined(sun) 363 | # define PLATFORM_ID "SunOS" 364 | 365 | #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) 366 | # define PLATFORM_ID "AIX" 367 | 368 | #elif defined(__hpux) || defined(__hpux__) 369 | # define PLATFORM_ID "HP-UX" 370 | 371 | #elif defined(__HAIKU__) 372 | # define PLATFORM_ID "Haiku" 373 | 374 | #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) 375 | # define PLATFORM_ID "BeOS" 376 | 377 | #elif defined(__QNX__) || defined(__QNXNTO__) 378 | # define PLATFORM_ID "QNX" 379 | 380 | #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) 381 | # define PLATFORM_ID "Tru64" 382 | 383 | #elif defined(__riscos) || defined(__riscos__) 384 | # define PLATFORM_ID "RISCos" 385 | 386 | #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) 387 | # define PLATFORM_ID "SINIX" 388 | 389 | #elif defined(__UNIX_SV__) 390 | # define PLATFORM_ID "UNIX_SV" 391 | 392 | #elif defined(__bsdos__) 393 | # define PLATFORM_ID "BSDOS" 394 | 395 | #elif defined(_MPRAS) || defined(MPRAS) 396 | # define PLATFORM_ID "MP-RAS" 397 | 398 | #elif defined(__osf) || defined(__osf__) 399 | # define PLATFORM_ID "OSF1" 400 | 401 | #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) 402 | # define PLATFORM_ID "SCO_SV" 403 | 404 | #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) 405 | # define PLATFORM_ID "ULTRIX" 406 | 407 | #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) 408 | # define PLATFORM_ID "Xenix" 409 | 410 | #elif defined(__WATCOMC__) 411 | # if defined(__LINUX__) 412 | # define PLATFORM_ID "Linux" 413 | 414 | # elif defined(__DOS__) 415 | # define PLATFORM_ID "DOS" 416 | 417 | # elif defined(__OS2__) 418 | # define PLATFORM_ID "OS2" 419 | 420 | # elif defined(__WINDOWS__) 421 | # define PLATFORM_ID "Windows3x" 422 | 423 | # else /* unknown platform */ 424 | # define PLATFORM_ID 425 | # endif 426 | 427 | #elif defined(__INTEGRITY) 428 | # if defined(INT_178B) 429 | # define PLATFORM_ID "Integrity178" 430 | 431 | # else /* regular Integrity */ 432 | # define PLATFORM_ID "Integrity" 433 | # endif 434 | 435 | #else /* unknown platform */ 436 | # define PLATFORM_ID 437 | 438 | #endif 439 | 440 | /* For windows compilers MSVC and Intel we can determine 441 | the architecture of the compiler being used. This is because 442 | the compilers do not have flags that can change the architecture, 443 | but rather depend on which compiler is being used 444 | */ 445 | #if defined(_WIN32) && defined(_MSC_VER) 446 | # if defined(_M_IA64) 447 | # define ARCHITECTURE_ID "IA64" 448 | 449 | # elif defined(_M_X64) || defined(_M_AMD64) 450 | # define ARCHITECTURE_ID "x64" 451 | 452 | # elif defined(_M_IX86) 453 | # define ARCHITECTURE_ID "X86" 454 | 455 | # elif defined(_M_ARM64) 456 | # define ARCHITECTURE_ID "ARM64" 457 | 458 | # elif defined(_M_ARM) 459 | # if _M_ARM == 4 460 | # define ARCHITECTURE_ID "ARMV4I" 461 | # elif _M_ARM == 5 462 | # define ARCHITECTURE_ID "ARMV5I" 463 | # else 464 | # define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) 465 | # endif 466 | 467 | # elif defined(_M_MIPS) 468 | # define ARCHITECTURE_ID "MIPS" 469 | 470 | # elif defined(_M_SH) 471 | # define ARCHITECTURE_ID "SHx" 472 | 473 | # else /* unknown architecture */ 474 | # define ARCHITECTURE_ID "" 475 | # endif 476 | 477 | #elif defined(__WATCOMC__) 478 | # if defined(_M_I86) 479 | # define ARCHITECTURE_ID "I86" 480 | 481 | # elif defined(_M_IX86) 482 | # define ARCHITECTURE_ID "X86" 483 | 484 | # else /* unknown architecture */ 485 | # define ARCHITECTURE_ID "" 486 | # endif 487 | 488 | #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) 489 | # if defined(__ICCARM__) 490 | # define ARCHITECTURE_ID "ARM" 491 | 492 | # elif defined(__ICCRX__) 493 | # define ARCHITECTURE_ID "RX" 494 | 495 | # elif defined(__ICCRH850__) 496 | # define ARCHITECTURE_ID "RH850" 497 | 498 | # elif defined(__ICCRL78__) 499 | # define ARCHITECTURE_ID "RL78" 500 | 501 | # elif defined(__ICCRISCV__) 502 | # define ARCHITECTURE_ID "RISCV" 503 | 504 | # elif defined(__ICCAVR__) 505 | # define ARCHITECTURE_ID "AVR" 506 | 507 | # elif defined(__ICC430__) 508 | # define ARCHITECTURE_ID "MSP430" 509 | 510 | # elif defined(__ICCV850__) 511 | # define ARCHITECTURE_ID "V850" 512 | 513 | # elif defined(__ICC8051__) 514 | # define ARCHITECTURE_ID "8051" 515 | 516 | # else /* unknown architecture */ 517 | # define ARCHITECTURE_ID "" 518 | # endif 519 | 520 | #elif defined(__ghs__) 521 | # if defined(__PPC64__) 522 | # define ARCHITECTURE_ID "PPC64" 523 | 524 | # elif defined(__ppc__) 525 | # define ARCHITECTURE_ID "PPC" 526 | 527 | # elif defined(__ARM__) 528 | # define ARCHITECTURE_ID "ARM" 529 | 530 | # elif defined(__x86_64__) 531 | # define ARCHITECTURE_ID "x64" 532 | 533 | # elif defined(__i386__) 534 | # define ARCHITECTURE_ID "X86" 535 | 536 | # else /* unknown architecture */ 537 | # define ARCHITECTURE_ID "" 538 | # endif 539 | #else 540 | # define ARCHITECTURE_ID 541 | #endif 542 | 543 | /* Convert integer to decimal digit literals. */ 544 | #define DEC(n) \ 545 | ('0' + (((n) / 10000000)%10)), \ 546 | ('0' + (((n) / 1000000)%10)), \ 547 | ('0' + (((n) / 100000)%10)), \ 548 | ('0' + (((n) / 10000)%10)), \ 549 | ('0' + (((n) / 1000)%10)), \ 550 | ('0' + (((n) / 100)%10)), \ 551 | ('0' + (((n) / 10)%10)), \ 552 | ('0' + ((n) % 10)) 553 | 554 | /* Convert integer to hex digit literals. */ 555 | #define HEX(n) \ 556 | ('0' + ((n)>>28 & 0xF)), \ 557 | ('0' + ((n)>>24 & 0xF)), \ 558 | ('0' + ((n)>>20 & 0xF)), \ 559 | ('0' + ((n)>>16 & 0xF)), \ 560 | ('0' + ((n)>>12 & 0xF)), \ 561 | ('0' + ((n)>>8 & 0xF)), \ 562 | ('0' + ((n)>>4 & 0xF)), \ 563 | ('0' + ((n) & 0xF)) 564 | 565 | /* Construct a string literal encoding the version number components. */ 566 | #ifdef COMPILER_VERSION_MAJOR 567 | char const info_version[] = { 568 | 'I', 'N', 'F', 'O', ':', 569 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', 570 | COMPILER_VERSION_MAJOR, 571 | # ifdef COMPILER_VERSION_MINOR 572 | '.', COMPILER_VERSION_MINOR, 573 | # ifdef COMPILER_VERSION_PATCH 574 | '.', COMPILER_VERSION_PATCH, 575 | # ifdef COMPILER_VERSION_TWEAK 576 | '.', COMPILER_VERSION_TWEAK, 577 | # endif 578 | # endif 579 | # endif 580 | ']','\0'}; 581 | #endif 582 | 583 | /* Construct a string literal encoding the internal version number. */ 584 | #ifdef COMPILER_VERSION_INTERNAL 585 | char const info_version_internal[] = { 586 | 'I', 'N', 'F', 'O', ':', 587 | 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', 588 | 'i','n','t','e','r','n','a','l','[', 589 | COMPILER_VERSION_INTERNAL,']','\0'}; 590 | #endif 591 | 592 | /* Construct a string literal encoding the version number components. */ 593 | #ifdef SIMULATE_VERSION_MAJOR 594 | char const info_simulate_version[] = { 595 | 'I', 'N', 'F', 'O', ':', 596 | 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', 597 | SIMULATE_VERSION_MAJOR, 598 | # ifdef SIMULATE_VERSION_MINOR 599 | '.', SIMULATE_VERSION_MINOR, 600 | # ifdef SIMULATE_VERSION_PATCH 601 | '.', SIMULATE_VERSION_PATCH, 602 | # ifdef SIMULATE_VERSION_TWEAK 603 | '.', SIMULATE_VERSION_TWEAK, 604 | # endif 605 | # endif 606 | # endif 607 | ']','\0'}; 608 | #endif 609 | 610 | /* Construct the string literal in pieces to prevent the source from 611 | getting matched. Store it in a pointer rather than an array 612 | because some compilers will just produce instructions to fill the 613 | array rather than assigning a pointer to a static array. */ 614 | char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; 615 | char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; 616 | 617 | 618 | 619 | 620 | #if !defined(__STDC__) 621 | # if (defined(_MSC_VER) && !defined(__clang__)) \ 622 | || (defined(__ibmxl__) || defined(__IBMC__)) 623 | # define C_DIALECT "90" 624 | # else 625 | # define C_DIALECT 626 | # endif 627 | #elif __STDC_VERSION__ >= 201000L 628 | # define C_DIALECT "11" 629 | #elif __STDC_VERSION__ >= 199901L 630 | # define C_DIALECT "99" 631 | #else 632 | # define C_DIALECT "90" 633 | #endif 634 | const char* info_language_dialect_default = 635 | "INFO" ":" "dialect_default[" C_DIALECT "]"; 636 | 637 | /*--------------------------------------------------------------------------*/ 638 | 639 | #ifdef ID_VOID_MAIN 640 | void main() {} 641 | #else 642 | # if defined(__CLASSIC_C__) 643 | int main(argc, argv) int argc; char *argv[]; 644 | # else 645 | int main(int argc, char* argv[]) 646 | # endif 647 | { 648 | int require = 0; 649 | require += info_compiler[argc]; 650 | require += info_platform[argc]; 651 | require += info_arch[argc]; 652 | #ifdef COMPILER_VERSION_MAJOR 653 | require += info_version[argc]; 654 | #endif 655 | #ifdef COMPILER_VERSION_INTERNAL 656 | require += info_version_internal[argc]; 657 | #endif 658 | #ifdef SIMULATE_ID 659 | require += info_simulate[argc]; 660 | #endif 661 | #ifdef SIMULATE_VERSION_MAJOR 662 | require += info_simulate_version[argc]; 663 | #endif 664 | #if defined(__CRAYXE) || defined(__CRAYXC) 665 | require += info_cray[argc]; 666 | #endif 667 | require += info_language_dialect_default[argc]; 668 | (void)argv; 669 | return require; 670 | } 671 | #endif 672 | --------------------------------------------------------------------------------