From 97125eaf07ad1eb060eef6ad96a8d49bc6780ceb Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 18 Jul 2020 22:47:00 +0200 Subject: [PATCH] Added more operations and install statements --- .gitignore | 2 ++ CMakeLists.txt | 7 +++++-- include/gm3p.hpp | 1 - include/gm3p_int.hpp | 11 +++++++++++ src/gm3p_int.cpp | 39 +++++++++++++++++++++++++++++++++++++++ testapp/main.cpp | 2 +- 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index cf2580d..aa8a0be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .vs +.vscode out +build 3rdparty *.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 89d258b..70d2db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.8) -project ("GM3p") +project ("gm3p" CXX) set(GMP_INCLUDE_DIR "" CACHE PATH "Path to the directory containing 'gmp.h'") @@ -28,4 +28,7 @@ target_link_libraries(gm3p PUBLIC # Include sub-projects. if(ENABLE_TEST_PROJ) add_subdirectory(testapp) -endif() \ No newline at end of file +endif() + +install(TARGETS gm3p DESTINATION lib) +install(DIRECTORY include DESTINATION .) \ No newline at end of file diff --git a/include/gm3p.hpp b/include/gm3p.hpp index 48fb703..629eb65 100644 --- a/include/gm3p.hpp +++ b/include/gm3p.hpp @@ -1,4 +1,3 @@ #pragma once -#include #include "gm3p_int.hpp" \ No newline at end of file diff --git a/include/gm3p_int.hpp b/include/gm3p_int.hpp index d150fdc..6d4e14f 100644 --- a/include/gm3p_int.hpp +++ b/include/gm3p_int.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "gmp.h" namespace gm3p @@ -7,19 +9,28 @@ namespace gm3p class gInt { public: + // CONSTRUCTORS gInt(); gInt(mpz_t init); + gInt(unsigned long int init); gInt(long int init); gInt(const char* init, int base); ~gInt(); + // ASSIGNMENT OPERATORS gInt& operator=(const gInt& other); + // ARITHMETIC OPERATORS friend gInt operator+(const gInt& left, const gInt& right); friend gInt operator-(const gInt& left, const gInt& right); friend gInt operator*(const gInt& left, const gInt& right); friend gInt operator/(const gInt& left, const gInt& right); + gInt& operator+=(const gInt& right); + gInt& operator-=(const gInt& right); + gInt& operator*=(const gInt& right); + gInt& operator/=(const gInt& right); + friend std::ostream& operator<<(std::ostream& os, const gInt& value); private: diff --git a/src/gm3p_int.cpp b/src/gm3p_int.cpp index e8daff3..efd801a 100644 --- a/src/gm3p_int.cpp +++ b/src/gm3p_int.cpp @@ -13,6 +13,12 @@ namespace gm3p mpz_set(value, init); } + gInt::gInt(unsigned long int init) : + gInt::gInt() + { + mpz_set_ui(value, init); + } + gInt::gInt(long int init) : gInt::gInt() { @@ -30,11 +36,16 @@ namespace gm3p mpz_clear(value); } + + + gInt& gInt::operator=(const gInt& other) { mpz_set(this->value, other.value); } + + gInt operator+(const gInt& left, const gInt& right) { gInt ret; @@ -62,6 +73,34 @@ namespace gm3p mpz_div(ret.value, left.value, right.value); return ret; } + + + + gInt& gInt::operator+=(const gInt& right) + { + mpz_add(value, value, right.value); + return *this; + } + + gInt& gInt::operator-=(const gInt& right) + { + mpz_sub(value, value, right.value); + return *this; + } + + gInt& gInt::operator*=(const gInt& right) + { + mpz_mul(value, value, right.value); + return *this; + } + + gInt& gInt::operator/=(const gInt& right) + { + mpz_div(value, value, right.value); + return *this; + } + + std::ostream& operator<<(std::ostream& os, const gInt& value) { static char* buf; diff --git a/testapp/main.cpp b/testapp/main.cpp index 2f3cf9b..b41a5a9 100644 --- a/testapp/main.cpp +++ b/testapp/main.cpp @@ -1,6 +1,6 @@ #include "gm3p.hpp" -#include +//#include using namespace gm3p;