Added complex & removed thread
This commit is contained in:
parent
985612f42b
commit
5fda20a607
7 changed files with 107 additions and 85 deletions
11
Makefile
11
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
|
||||
|
|
|
|||
54
include/complex.hpp
Normal file
54
include/complex.hpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef COMPLEX_HPP
|
||||
#define COMPLEX_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*! @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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef THREAD_HPP
|
||||
#define THREAD_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
/*! \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 <class Fn, class... Args>
|
||||
void thread(Fn&& fn, Args&&... args)
|
||||
{
|
||||
m_threads.push_back(new std::thread(fn, args...));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::thread*> m_threads;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //THREAD_HPP
|
||||
42
src/complex.cpp
Normal file
42
src/complex.cpp
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
Loading…
Reference in a new issue