diff --git a/Makefile b/Makefile index aa37d1c..ee86b7e 100644 --- a/Makefile +++ b/Makefile @@ -45,13 +45,14 @@ shared: $(OBJ_SHARED) $(CC) -shared -o libztd.so $^ install: all - mv libztd.a libztd.so /usr/lib - mkdir -p /usr/include/ztd - cp -r include/* /usr/include/ztd + mkdir -p $(INSTALL)/usr/lib + mv libztd.a libztd.so $(INSTALL)/usr/lib + mkdir -p $(INSTALL)/usr/include/ztd + cp -r include/* $(INSTALL)/usr/include/ztd uninstall: - rm /usr/lib/libztd.* - rm -rd /usr/include/ztd + rm $(INSTALL)/usr/lib/libztd.* + rm -rd $(INSTALL)/usr/include/ztd clean: rm $(ODIR)/*.o $(ODIR_SHARED)/*.o diff --git a/include/complex.hpp b/include/complex.hpp new file mode 100644 index 0000000..8771583 --- /dev/null +++ b/include/complex.hpp @@ -0,0 +1,54 @@ +#ifndef COMPLEX_HPP +#define COMPLEX_HPP + +#include + +/*! @file complex.hpp +* @brief Complex numbers and related computation +*/ + +namespace ztd +{ + //! @brief Complex number + class complex + { + public: + //! @brief Contructor a+bi + complex(const double& a=0, const double& b=0); + //! @brief Contructor z + complex(const complex& z); + + //! @brief Complex Addition + complex& operator+=(const complex& z); + //! @brief Complex Substraction + complex& operator-=(const complex& z); + //! @brief Complex Multiplication + complex& operator*=(const complex& z); + //! @brief Complex Division + complex& operator/=(const complex& z); + + //! @brief Real part + double real; + //! @brief Imaginary part + double im; + + }; + + //! @brief Complex Addition + inline complex operator+(const complex& z1, const complex& z2) { complex z3(z1); return z3 += z1; } + //! @brief Complex Substraction + inline complex operator-(const complex& z1, const complex& z2) { complex z3(z1); return z3 -= z1; } + //! @brief Complex Multiplication + inline complex operator*(const complex& z1, const complex& z2) { complex z3(z1); return z3 *= z1; } + //! @brief Complex Division + inline complex operator/(const complex& z1, const complex& z2) { complex z3(z1); return z3 /= z1; } + + //! @brief Output a+bi + inline std::ostream& operator<<(std::ostream& stream, complex z) { stream << z.real << '+' << z.im << 'i'; return stream; } + + //! @brief Constant i definition + extern const complex i; + +} + +#endif //COMPLEX_HPP diff --git a/include/options.hpp b/include/options.hpp index b27fae3..12351e6 100644 --- a/include/options.hpp +++ b/include/options.hpp @@ -122,6 +122,7 @@ namespace ztd option* find(char c); //! @brief Find string option option* find(std::string const& str); + inline option* find(const char* str) { return this->find(std::string(str)); } /*PROCESSING FUNCTIONS*/ //! @brief Process arguments through the option set diff --git a/include/thread.hpp b/include/thread.hpp deleted file mode 100644 index 58b31c9..0000000 --- a/include/thread.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef THREAD_HPP -#define THREAD_HPP - -#include -#include - -/*! \file thread.hpp -* @brief Thread management -*/ - -namespace ztd -{ - //! @brief Coordinated thread pool - class thread_pool - { - public: - ~thread_pool(); - //! @brief Join and delete all threads of the pool - void join(); - - //! @brief Detach all threads of the pool - void detach(); - - //! @brief Delete all threads of the pool - void clear(); - - //! @brief Instanciate new thread - template - void thread(Fn&& fn, Args&&... args) - { - m_threads.push_back(new std::thread(fn, args...)); - } - - private: - std::vector m_threads; - }; -} - - -#endif //THREAD_HPP diff --git a/src/complex.cpp b/src/complex.cpp new file mode 100644 index 0000000..c55ca57 --- /dev/null +++ b/src/complex.cpp @@ -0,0 +1,42 @@ +#include "complex.hpp" + +const ztd::complex ztd::i(0,1); + +ztd::complex::complex(const double& a, const double& b) +{ + real=a; + im=b; +} +ztd::complex::complex(const ztd::complex& z) +{ + real=z.real; + im=z.im; +} + +ztd::complex& ztd::complex::operator+=(const ztd::complex& z) +{ + real += z.real; + im += z.im; + return *this; +} +ztd::complex& ztd::complex::operator-=(const ztd::complex& z) +{ + real -= z.real; + im -= z.im; + return *this; +} +ztd::complex& ztd::complex::operator*=(const ztd::complex& z) +{ + double r=real; + real = real*z.real - im*z.im; + im = r*z.im + im*z.real; + return *this; +} +ztd::complex& ztd::complex::operator/=(const ztd::complex& z) +{ + double r=real; + double div = z.real*z.real + z.im*z.im; + real = (real*z.real + im*z.im)/div; + im = (im*z.real - r*z.im)/div; + return *this; +} diff --git a/src/options.cpp b/src/options.cpp index e98afd4..5b7dd62 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -142,8 +142,8 @@ ztd::option* ztd::option_set::find(char c) { for( auto it=m_options.begin() ; it!=m_options.end() ; it++ ) { - if((*it).shortDef && (*it).charName == c) - return &(*it); + if(it->shortDef && it->charName == c) + return &*it; } return nullptr; } @@ -152,8 +152,8 @@ ztd::option* ztd::option_set::find(std::string const& str) { for( auto it=m_options.begin() ; it!=m_options.end() ; it++ ) { - if((*it).longDef && (*it).strName == str) - return &(*it); + if(it->longDef && it->strName == str) + return &*it; } return nullptr; } diff --git a/src/thread.cpp b/src/thread.cpp deleted file mode 100644 index af3c0c2..0000000 --- a/src/thread.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "thread.hpp" - -ztd::thread_pool::~thread_pool() -{ - for(auto it : m_threads) - { - delete it; - } -} - -void ztd::thread_pool::join() -{ - for(auto it : m_threads) - { - it->join(); - delete it; - } - m_threads.clear(); -} - -void ztd::thread_pool::detach() -{ - for(auto it : m_threads) - { - it->detach(); - } -} - -void ztd::thread_pool::clear() -{ - for(auto it : m_threads) - { - delete it; - } - m_threads.clear(); -}