兼容cl.exe和gcc

master
caiyuzheng 2020-05-06 13:46:44 +08:00
parent 2fad5c8db7
commit 92c7cd5257
6 changed files with 61 additions and 68 deletions

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/general">
<contentRoot DIR="$PROJECT_DIR$" />
</component>
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>

View File

@ -2,8 +2,7 @@
<project version="4">
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true">
<generated>
<config projectName="generallib" targetName="General" />
<config projectName="generallib" targetName="generallib" />
<config projectName="General" targetName="General" />
</generated>
</component>
<component name="CMakeSettings" AUTO_RELOAD="true">
@ -20,7 +19,6 @@
<change beforePath="$PROJECT_DIR$/general/src/pattern/signleton.h" beforeDir="false" afterPath="$PROJECT_DIR$/general/src/pattern/signleton.hpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/general/src/pattern/stratergy.h" beforeDir="false" afterPath="$PROJECT_DIR$/general/src/pattern/stratergy.hpp" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -42,9 +40,17 @@
</component>
<component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
<component name="ProjectId" id="1UhntPy4Y6cJ81thpskTMk9Asng" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="cf.first.check.clang-format" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
@ -62,33 +68,12 @@
<recent name="D:\project\c++\generallib\src\encrypt" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="CMake Application.generallib">
<configuration name="General" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" PROJECT_NAME="generallib" TARGET_NAME="General" CONFIG_NAME="Debug">
<component name="RunManager">
<configuration name="General" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="General" TARGET_NAME="General" CONFIG_NAME="Debug">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="generallib" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" PROJECT_NAME="generallib" TARGET_NAME="generallib" CONFIG_NAME="Debug">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="CMake Application.generallib" />
<item itemvalue="CMake Application.General" />
</list>
</component>
<component name="SvnConfiguration">
<configuration />
@ -141,23 +126,41 @@
<workItem from="1587713244566" duration="10654000" />
<workItem from="1588607501663" duration="599000" />
<workItem from="1588685364145" duration="2436000" />
<workItem from="1588731711427" duration="7486000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
<option name="version" value="2" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="COLUMN_ORDER" />
</State>
<State />
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state x="651" y="314" width="409" height="388" key="#Notifications" timestamp="1588741195489">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="651" y="314" width="409" height="388" key="#Notifications/0.40.1536.824@0.40.1536.824" timestamp="1588741195489" />
<state x="223" y="107" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1588731831415">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="223" y="107" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.40.1536.824@0.40.1536.824" timestamp="1588731831415" />
<state x="549" y="206" key="FileChooserDialogImpl" timestamp="1588739069638">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="549" y="206" key="FileChooserDialogImpl/0.40.1536.824@0.40.1536.824" timestamp="1588739069638" />
<state x="270" y="96" key="SettingsEditor" timestamp="1588739395688">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="270" y="96" key="SettingsEditor/0.40.1536.824@0.40.1536.824" timestamp="1588739395688" />
</component>
</project>

View File

@ -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}")

View File

@ -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

View File

@ -9,7 +9,6 @@
#include <string>
#include "debug.h"
#include <sys/types.h>
#include <unistd.h>
using namespace std;

View File

@ -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<std::string, std::string> 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;