diff options
author | Angelo Rossi <angelo.rossi.homelab@gmail.com> | 2023-06-21 12:04:16 +0000 |
---|---|---|
committer | Angelo Rossi <angelo.rossi.homelab@gmail.com> | 2023-06-21 12:04:16 +0000 |
commit | b18347ffc9db9641e215995edea1c04c363b2bdf (patch) | |
tree | f3908dc911399f1a21e17d950355ee56dc0919ee /sources/movecopy.cpp |
Initial commit.
Diffstat (limited to 'sources/movecopy.cpp')
-rw-r--r-- | sources/movecopy.cpp | 306 |
1 files changed, 306 insertions, 0 deletions
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<double>(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<int>(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<long int>(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<size_t>(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<std::string>(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<double>(const double &from, std::vector<double> &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<int>(const int &from, std::vector<int> &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<long int>(const long int &from, std::vector<long int> &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<size_t>(const size_t &from, std::vector<size_t> &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<std::string>(const std::string &from, std::vector<std::string> &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<double>(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<int>(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<long int>(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<std::string>(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>(double *to, const size_t &n) + { + return copy(0.0, to, n); + } + + template <> size_t move0<int>(int *to, const size_t &n) + { + return copy((int) 0, to, n); + } + + template <> size_t move0<long int>(long int *to, const size_t &n) + { + return copy((long int) 0, to, n); + } + + template <> size_t move0<size_t>(size_t *to, const size_t &n) + { + return copy((size_t) 0, to, n); + } + + template <> size_t move<double>(const std::vector<double> &from, std::vector<double> &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<int>(const std::vector<int> &from, std::vector<int> &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<long int>(const std::vector<long int> &from, std::vector<long int> &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<std::string>(const std::vector<std::string> &from, std::vector<std::string> &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<size_t>(const std::vector<size_t> &from, std::vector<size_t> &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<double>(std::vector<double> &to, const size_t &n) + { + return copy(0.0, to, n); + } + + template <> size_t move0<int>(std::vector<int> &to, const size_t &n) + { + return copy((int) 0, to, n); + } + + template <> size_t move0<long int>(std::vector<long int> &to, const size_t &n) + { + return copy((long int) 0, to, n); + } + + template <> size_t move0<size_t>(std::vector<size_t> &to, const size_t &n) + { + return copy((size_t) 0, to, n); + } + +} + +// end of file movecopy.cpp |