gctl/lib/utility/stream.h

202 lines
6.9 KiB
C
Raw Normal View History

2024-09-10 15:45:07 +08:00
/********************************************************
*
*
*
*
*
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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_STREAM_H
#define _GCTL_STREAM_H
// library's head files
#include "stream_t.h"
// system's head files
#include "cstring"
#include "iostream"
#include "fstream"
#include "iomanip"
#include "ctime"
#include "stdio.h"
#ifdef _WINDOWS
#include "windows.h"
#else
#include "sys/ioctl.h"
#endif
namespace gctl
{
/**
* @brief GCTL图标
*/
void display_logo(std::ostream &sout = std::cout);
/**
* @brief
*
* @param new_str
* @param old_str
* @param old_value
* @param new_value
*
* @return
*/
int replace_all(std::string& new_str, const std::string& old_str, const std::string& old_value,
const std::string& new_value);
/**
* @brief
*
* @param in_str
* @param patch_str
* @return
*/
std::string patch_string(std::string in_str, std::string patch_str);
/**
* @brief string对象为stringstream对象
*
* @param[in] in_str string字符串
* @param out_ss stringstreams对象
* @param[in] delimiter string对象时的分隔符
* delimiter转换为空格
*/
void str2ss(std::string in_str, std::stringstream &out_ss, std::string delimiter = "");
/**
* @brief string字符串为double类型的数值
*
* nan或者inf等表示无效值的符号
* >>
* fortran输出文件中以D标注的科学数字转换为浮点类型
*
* @param[in] instr
*
* @return double类型的数值
*/
double str2double(std::string instr);
/**
* @brief double类型数值为string类型字符串 to_string函数
*
* @param[in] in_d
*
* @return
*/
std::string double2str(double in_d);
/**
* @brief
*
* @param[in] length
* @param out
*/
void random_char(unsigned int length, char* out);
/**
* @brief
*
* @param[in] length
* @param out_str
*/
void random_str(unsigned int lenght, std::string &out_str);
/**
* @brief
*
* @param infile ifstream对象
* @param[in] filename
* @param[in] extension
* @param[in] mode
*/
void open_infile(std::ifstream &infile, std::string filename, std::string extension = "",
std::ios_base::openmode mode = std::ios_base::in);
/**
* @brief
*
* @param infile
* @param[in] filename
* @param[in] exten_pattern 使
* @param[in] mode
*/
void open_matched_infile(std::ifstream &infile, std::string filename, std::string exten_pattern,
std::ios_base::openmode mode = std::ios_base::in);
/**
* @brief
*
* @param outfile ofstream对象
* @param[in] filename
* @param[in] extension
* @param[in] mode
*/
void open_outfile(std::ofstream &outfile, std::string filename, std::string extension = "",
std::ios_base::openmode mode = std::ios_base::out);
/**
* @brief
*
* @param outfile
* @param[in] filename
* @param[in] exten_pattern 使
* @param[in] mode
*/
void open_matched_outfile(std::ofstream &outfile, std::string filename, std::string exten_pattern,
std::ios_base::openmode mode = std::ios_base::out);
/**
* @brief
*
* @return
*/
int terminal_width();
/**
* @brief
*
* @return
*/
int terminal_height();
/**
* @brief
*
* @note
*
* @param in_str
* @param str_vec
*/
void parse_string_with_quotes(std::string in_str, std::vector<std::string> &str_vec);
2024-12-15 19:15:12 +08:00
/**
* @brief
*
* @param in_str
* @param naked_name
* @param exten_name
*/
void parse_filename(std::string filename, std::string &naked_name, std::string &exten_name);
2024-09-10 15:45:07 +08:00
}
#endif // _GCTL_STREAM_H