/******************************************************** * ██████╗ ██████╗████████╗██╗ * ██╔════╝ ██╔════╝╚══██╔══╝██║ * ██║ ███╗██║ ██║ ██║ * ██║ ██║██║ ██║ ██║ * ╚██████╔╝╚██████╗ ██║ ███████╗ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝ * Geophysical Computational Tools & Library (GCTL) * * Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn) * * GCTL is distributed under a dual licensing scheme. You can redistribute * it and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation, either version 2 * of the License, or (at your option) any later version. You should have * received a copy of the GNU Lesser General Public License along with this * program. If not, see . * * If the terms and conditions of the LGPL v.2. would prevent you from using * the GCTL, please consider the option to obtain a commercial license for a * fee. These licenses are offered by the GCTL's original author. As a rule, * licenses are provided "as-is", unlimited in time for a one time fee. Please * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget * to include some description of your company and the realm of its activities. * Also add information on how to contact you by electronic and paper mail. ******************************************************/ #ifndef _GCTL_VECTOR_TYPE_H #define _GCTL_VECTOR_TYPE_H #include "vector" #include "complex" #include "iostream" namespace gctl { /* * Here we define some commonly used vector types. */ typedef std::vector _1i_vector; ///< 1-D integer vector typedef std::vector _1f_vector; ///< 1-D single-precision floating-point vector typedef std::vector _1d_vector; ///< 1-D double-precision floating-point vector typedef std::vector _1s_vector; ///< 1-D string vector typedef std::vector > _1cf_vector; ///< 1-D complex float vector typedef std::vector > _1cd_vector; ///< 1-D complex double vector typedef std::vector > _2i_vector; ///< 2-D integer vector typedef std::vector > _2f_vector; ///< 2-D single-precision floating-point vector typedef std::vector > _2d_vector; ///< 2-D double-precision floating-point vector typedef std::vector > _2s_vector; ///< 2-D string vector typedef std::vector > > _2cf_vector; ///< 2-D complex float vector typedef std::vector > > _2cd_vector; ///< 2-D complex double vector /** * @brief Clear the memory space used by a 1-D vector * * @param[in] a 1-D vector object * * @tparam VecValType template type */ template void destroy_vector(std::vector a) { if (!a.empty()) { a.clear(); std::vector().swap(a); } return; } /** * @brief Clear the memory space used by a 2-D vector * * @param[in] a 2-D vector object * * @tparam VecValType template type */ template void destroy_vector(std::vector > a) { if (!a.empty()) { for (int i = 0; i < a.size(); i++) { a[i].clear(); std::vector().swap(a[i]); } a.clear(); std::vector >().swap(a); } return; } template void display_vector(const std::vector &a, std::ostream &os = std::cout, char sep = ' ') { if (!a.empty()) { os << a[0]; for (size_t i = 1; i < a.size(); i++) { os << sep << a[i]; } os << std::endl; } return; } template std::ostream &operator <<(std::ostream &os, const std::vector &a) { if (!a.empty()) { os << a[0]; for (size_t i = 1; i < a.size(); i++) { os << " " << a[i]; } } return os; } template std::istream &operator >>(std::istream &os, std::vector &a) { VecValType t; // 在 Windows 系统之下:输入 ctrl + z 后按下回车,就代表标准输入流的结束 // 在 Unix/Linux/MacOS 系统之下:输入 ctrl + D,就表示输入流结束了 while (os >> t){a.push_back(t);} return os; } }; #endif // _GCTL_VECTOR_TYPE_H