From b18347ffc9db9641e215995edea1c04c363b2bdf Mon Sep 17 00:00:00 2001 From: Angelo Rossi Date: Wed, 21 Jun 2023 12:04:16 +0000 Subject: Initial commit. --- sources/movecopy.cpp | 306 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 306 insertions(+) create mode 100644 sources/movecopy.cpp (limited to 'sources/movecopy.cpp') diff --git a/sources/movecopy.cpp b/sources/movecopy.cpp new file mode 100644 index 0000000..470e815 --- /dev/null +++ b/sources/movecopy.cpp @@ -0,0 +1,306 @@ +//-*- mode: c++; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*- + +// file movecopy.cpp + +#include "movecopy.hpp" + +namespace movecopy { + + template <> size_t copy(const double &from, double *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to) { + for (i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const int &from, int *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to) { + for (i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const long int &from, long int *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to) { + for (i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const size_t &from, size_t *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to) { + for (i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const std::string &from, std::string *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + + if (to) { + for (i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const double &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to.size() >= n) { + for(i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const int &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to.size() >= n) { + for(i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const long int &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to.size() >= n) { + for(i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const size_t &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0L; + + if(to.size() >= n) { + for(i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t copy(const std::string &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(to.size() >= n) { + for(i = 0; i < n; i++) + to[ i ] = from; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move(const double from[], double *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + + if (from) { + if (to) { + for (i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + } + return nReturnValue; + } + + template <> size_t move(const int from[], int *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + + if (from) { + if (to) { + for (i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + } + return nReturnValue; + } + + template <> size_t move(const long int from[], long int *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + + if (from) { + if (to) { + for (i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + } + return nReturnValue; + } + + template <> size_t move(const std::string from[], std::string *to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + + if (from) { + if (to) { + for (i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + } + return nReturnValue; + } + + template <> size_t move0(double *to, const size_t &n) + { + return copy(0.0, to, n); + } + + template <> size_t move0(int *to, const size_t &n) + { + return copy((int) 0, to, n); + } + + template <> size_t move0(long int *to, const size_t &n) + { + return copy((long int) 0, to, n); + } + + template <> size_t move0(size_t *to, const size_t &n) + { + return copy((size_t) 0, to, n); + } + + template <> size_t move(const std::vector &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(from.size() == to.size()) { + for(i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move(const std::vector &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(from.size() == to.size()) { + for(i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move(const std::vector &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(from.size() == to.size()) { + for(i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move(const std::vector &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(from.size() == to.size()) { + for(i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move(const std::vector &from, std::vector &to, const size_t &n) + { + size_t i; + size_t nReturnValue = 0; + // + if(from.size() == to.size()) { + for(i = 0; i < n; i++) + to[ i ] = from[ i ]; + nReturnValue = n; + } + return nReturnValue; + } + + template <> size_t move0(std::vector &to, const size_t &n) + { + return copy(0.0, to, n); + } + + template <> size_t move0(std::vector &to, const size_t &n) + { + return copy((int) 0, to, n); + } + + template <> size_t move0(std::vector &to, const size_t &n) + { + return copy((long int) 0, to, n); + } + + template <> size_t move0(std::vector &to, const size_t &n) + { + return copy((size_t) 0, to, n); + } + +} + +// end of file movecopy.cpp -- cgit v1.2.3