From 92c7cd52579a0f446aec62241466519e28978727 Mon Sep 17 00:00:00 2001 From: caiyuzheng <290198252@qq.com> Date: Wed, 6 May 2020 13:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9cl.exe=E5=92=8Cgcc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 4 +- .idea/workspace.xml | 63 ++++++++++++++------------- cmake-build-debug/cmake_install.cmake | 2 +- general/CMakeLists.txt | 5 ++- general/inc/utils.h | 1 - general/src/math/BigInt.hpp | 54 +++++++++-------------- 6 files changed, 61 insertions(+), 68 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8822db8..4219e70 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,8 @@ - + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0981e65..5959262 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,7 @@ - - + @@ -20,7 +19,6 @@ - + + + + + + @@ -62,33 +68,12 @@ - - - - - + + - - - - - - - - @@ -141,23 +126,41 @@ + - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cmake-build-debug/cmake_install.cmake b/cmake-build-debug/cmake_install.cmake index 3c821bb..5aba855 100644 --- a/cmake-build-debug/cmake_install.cmake +++ b/cmake-build-debug/cmake_install.cmake @@ -2,7 +2,7 @@ # Set the install prefix if(NOT DEFINED CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/General") + set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/generallib") endif() string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") diff --git a/general/CMakeLists.txt b/general/CMakeLists.txt index 2e7137b..a8444ff 100644 --- a/general/CMakeLists.txt +++ b/general/CMakeLists.txt @@ -12,6 +12,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # using Intel C++ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + add_compile_options("/std:c++17") # using Visual Studio C++ endif() @@ -26,7 +27,7 @@ aux_source_directory(src DIRSRCS) aux_source_directory(src/pattern PaternSrc) -add_library(General OBJECT ${DIRSRCS} ${PaternSrc} src/pattern/signleton.h src/pattern/Observer.h src/pattern/stratergy.h src/pattern/adapter.h src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h src/encrypt/rsa.cpp +add_library(General OBJECT ${DIRSRCS} ${PaternSrc} src/pattern/signleton.hpp src/pattern/Observer.hpp src/pattern/stratergy.hpp src/pattern/adapter.hpp src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h src/encrypt/rsa.cpp src/math/BigInt.hpp src/net/TcpClient.cpp src/net/TcpClient.h src/net/PackageReceiver.cpp src/net/PackageReceiver.h) set(COPYITEM inc) @@ -58,7 +59,7 @@ file(GLOB NET ${PROJECT_SOURCE_DIR}/src/net/*.h) file(COPY ${NET} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) IF (WIN32) - +message("it is windows 32") ELSEIF (UNIX) add_custom_command( TARGET General PRE_BUILD diff --git a/general/inc/utils.h b/general/inc/utils.h index c02c7a9..fe4f36b 100644 --- a/general/inc/utils.h +++ b/general/inc/utils.h @@ -9,7 +9,6 @@ #include #include "debug.h" #include -#include using namespace std; diff --git a/general/src/math/BigInt.hpp b/general/src/math/BigInt.hpp index bc119a6..bc67e62 100644 --- a/general/src/math/BigInt.hpp +++ b/general/src/math/BigInt.hpp @@ -32,7 +32,6 @@ class BigInt { BigInt(const BigInt&); BigInt(const long long&); BigInt(const std::string&); - static BigInt& RandLength(int size,BigInt base); // Assignment operators: BigInt& operator=(const BigInt&); @@ -136,10 +135,12 @@ class BigInt { */ bool is_valid_number(const std::string& num) { - for (char digit : num) - if (digit < '0' or digit > '9') + const char *p; + for (uint16_t i = 0;i < num.size();i++){ + p = num.c_str(); + if ((p[i] < '0') && (p[i] > '9')) return false; - + } return true; } @@ -196,8 +197,8 @@ void add_trailing_zeroes(std::string& num, size_t num_zeroes) { std::tuple get_larger_and_smaller(const std::string& num1, const std::string& num2) { std::string larger, smaller; - if (num1.size() > num2.size() or - (num1.size() == num2.size() and num1 > num2)) { + if ((num1.size() > num2.size()) || + ((num1.size() == num2.size()) && ( num1 > num2))) { larger = num1; smaller = num2; } @@ -270,7 +271,7 @@ BigInt::BigInt(const long long& num) { */ BigInt::BigInt(const std::string& num) { - if (num[0] == '+' or num[0] == '-') { // check for sign + if ((num[0] == '+') || ( num[0] == '-')) { // check for sign std::string magnitude = num.substr(1); if (is_valid_number(magnitude)) { value = magnitude; @@ -395,20 +396,7 @@ BigInt& BigInt::operator=(const long long& num) { return *this; } -/* - range a data - ---------------- - return : base + rand -*/ -BigInt& BigInt::RandLength(int size,BigInt base){ - // biggest is 2048 - if(size > 2048) - size = 2048; - - BigInt ret(); - -} /* BigInt = String --------------- @@ -489,7 +477,7 @@ BigInt BigInt::operator-() const { */ bool BigInt::operator==(const BigInt& num) const { - return (sign == num.sign) and (value == num.value); + return ((sign == num.sign) && (value == num.value)); } @@ -530,7 +518,7 @@ bool BigInt::operator<(const BigInt& num) const { */ bool BigInt::operator>(const BigInt& num) const { - return !((*this < num) or (*this == num)); + return !((*this < num) || (*this == num)); } @@ -540,7 +528,7 @@ bool BigInt::operator>(const BigInt& num) const { */ bool BigInt::operator<=(const BigInt& num) const { - return (*this < num) or (*this == num); + return ((*this < num) || (*this == num)); } @@ -950,12 +938,12 @@ const long long FLOOR_SQRT_LLONG_MAX = 3037000499; BigInt BigInt::operator+(const BigInt& num) const { // if the operands are of opposite signs, perform subtraction - if (this->sign == '+' and num.sign == '-') { + if ((this->sign == '+') && (num.sign == '-')) { BigInt rhs = num; rhs.sign = '+'; return *this - rhs; } - else if (this->sign == '-' and num.sign == '+') { + else if ((this->sign == '-') && (num.sign == '+')) { BigInt lhs = *this; lhs.sign = '+'; return -(lhs - num); @@ -978,7 +966,7 @@ BigInt BigInt::operator+(const BigInt& num) const { result.value = std::to_string(carry) + result.value; // if the operands are negative, the result is negative - if (this->sign == '-' and result.value != "0") + if ((this->sign == '-') && (result.value != "0")) result.sign = '-'; return result; @@ -993,12 +981,12 @@ BigInt BigInt::operator+(const BigInt& num) const { BigInt BigInt::operator-(const BigInt& num) const { // if the operands are of opposite signs, perform addition - if (this->sign == '+' and num.sign == '-') { + if ((this->sign == '+') && (num.sign == '-')) { BigInt rhs = num; rhs.sign = '+'; return *this + rhs; } - else if (this->sign == '-' and num.sign == '+') { + else if ((this->sign == '-') && (num.sign == '+')) { BigInt lhs = *this; lhs.sign = '+'; return -(lhs + num); @@ -1064,7 +1052,7 @@ BigInt BigInt::operator-(const BigInt& num) const { */ BigInt BigInt::operator*(const BigInt& num) const { - if (*this == 0 or num == 0) + if ((*this == 0) || (num == 0)) return BigInt(0); if (*this == 1) return num; @@ -1072,7 +1060,7 @@ BigInt BigInt::operator*(const BigInt& num) const { return *this; BigInt product; - if (abs(*this) <= FLOOR_SQRT_LLONG_MAX and abs(num) <= FLOOR_SQRT_LLONG_MAX) + if ((abs(*this) <= FLOOR_SQRT_LLONG_MAX) && (abs(num) <= FLOOR_SQRT_LLONG_MAX)) product = std::stoll(this->value) * std::stoll(num.value); else { // identify the numbers as `larger` and `smaller` @@ -1167,7 +1155,7 @@ BigInt BigInt::operator/(const BigInt& num) const { return -(*this); BigInt quotient; - if (abs_dividend <= LLONG_MAX and abs_divisor <= LLONG_MAX) + if ((abs_dividend <= LLONG_MAX) && (abs_divisor <= LLONG_MAX)) quotient = std::stoll(abs_dividend.value) / std::stoll(abs_divisor.value); else if (abs_dividend == abs_divisor) quotient = 1; @@ -1224,11 +1212,11 @@ BigInt BigInt::operator%(const BigInt& num) const { if (abs_divisor == 0) throw std::logic_error("Attempted division by zero"); - if (abs_divisor == 1 or abs_divisor == abs_dividend) + if ((abs_divisor == 1) || (abs_divisor == abs_dividend)) return BigInt(0); BigInt remainder; - if (abs_dividend <= LLONG_MAX and abs_divisor <= LLONG_MAX) + if ((abs_dividend <= LLONG_MAX) && (abs_divisor <= LLONG_MAX)) remainder = std::stoll(abs_dividend.value) % std::stoll(abs_divisor.value); else if (abs_dividend < abs_divisor) remainder = abs_dividend;