当前位置: 首页 > wzjs >正文

做网站时量宽度的尺子工具怎么被百度收录

做网站时量宽度的尺子工具,怎么被百度收录,wordpress 打分,乌鲁木齐最新政策信息在编写c头文件后,还需要再.cpp文件里面复制一份非常的麻烦 找过了不少方法都很难实现 提供了一个python脚本帮助你实现这个过程 #!/usr/bin/env python3 …

在编写c++头文件后,还需要再.cpp文件里面复制一份非常的麻烦

找过了不少方法都很难实现

提供了一个python脚本帮助你实现这个过程

#!/usr/bin/env python3                                                                                                                                                              
import re
import sysdef process_class(content):"""提取并处理内容中的下一个类,返回函数定义和剩余内容。"""class_match = re.search(r'class\s+(\w+)(?:\s*:\s*\w+)?', content)if not class_match:return None, contentclass_name = class_match.group(1)class_start = re.search(rf'class\s+{class_name}(?:\s*:\s*\w+)?\s*{{', content)start_pos = class_start.end() - 1brace_count = 1i = start_pos + 1while i < len(content) and brace_count > 0:if content[i] == '{':brace_count += 1elif content[i] == '}':brace_count -= 1i += 1class_content = content[start_pos:i]remaining_content = content[i:]# 移除访问修饰符class_content = re.sub(r'^\s*(public|private|protected):\s*', '', class_content, flags=re.MULTILINE)# 查找函数声明func_pattern = r'(friend\s+)?([\w:&<>]+\s*[\*&]?\s*)?(operator[\w<>=!+\-*]+)?\s*(\w+)?\s*\(([^)]*)\)\s*(const)?\s*;'functions = re.findall(func_pattern, class_content, re.MULTILINE)definitions = []for func in functions:friend, return_type, op_name, func_name, params, const = func# 清理参数:移除默认值cleaned_params = []for p in params.split(','):p = p.strip()if p:p = re.sub(r'\s*=\s*[^,)]+', '', p)cleaned_params.append(p)params = ', '.join(cleaned_params)# 清理非友元函数的返回类型if not friend and return_type:while return_type.startswith(('static ', 'virtual ', 'explicit ')):return_type = return_type.split(' ', 1)[1].strip()return_type = return_type.strip() if return_type else ''const = ' const' if const else ''if op_name:func_name = f'operator{op_name[len("operator"):]}'elif not func_name:continueif friend:func_def = f"{return_type} {func_name}({params}){const} {{\n     \n}}\n"else:func_def = f"{return_type} {class_name}::{func_name}({params}){const} {{\n     \n}}\n"definitions.append(func_def)return definitions, remaining_contentdef process_global_functions(content):"""提取并为没有定义体的全局函数生成定义。"""# 正则表达式匹配没有函数体的全局函数声明global_func_pattern = r'^\s*(?!class|struct)(\w+\s+)+(\w+)(\s*\([^;]*\))\s*;'matches = re.finditer(global_func_pattern, content, re.MULTILINE)definitions = []for match in matches:full_match = match.group(0)# 提取返回类型、函数名和参数return_type = match.group(1).strip()func_name = match.group(2).strip()params = match.group(3).strip()# 清理参数:移除默认值cleaned_params = []for p in params[1:-1].split(','):p = p.strip()if p:p = re.sub(r'\s*=\s*[^,)]+', '', p)cleaned_params.append(p)params = ', '.join(cleaned_params)func_def = f"{return_type} {func_name}({params}) {{\n    \n}}\n"definitions.append(func_def)return definitionsdef process_header(input_file, output_file):"""处理头文件并生成对应的 .cpp 文件。"""with open(input_file, 'r', encoding='utf-8') as f:content = f.read()function_definitions = []# 处理所有类while True:defs, content = process_class(content)if defs is None:breakfunction_definitions.extend(defs)# 处理全局函数global_defs = process_global_functions(content)function_definitions.extend(global_defs)# 写入输出文件output = [f'#include "{input_file}"\n\n'] + function_definitionswith open(output_file, 'w', encoding='utf-8') as f:f.writelines(output)print(f"成功生成 {output_file}!") # 这一行建议注释掉if __name__ == '__main__':if len(sys.argv) < 2:print("用法: python3 script.py input.h [output.cpp]")sys.exit(1)input_path = sys.argv[1]output_path = sys.argv[2] if len(sys.argv) >= 3 else input_path.replace('.h', '.cpp')process_header(input_path, output_path)

这个脚本接收两个参数,第一个是你的头文件,第二个是输出的地址,可以不提供第二个地址,则默认以cpp结尾存储再当前目录

全局脚本调用

~/.local/bin 是用户专属的可执行文件目录,推荐用于全局调用。
查看是否存在,不存在则手动创建一下

mkdir -p ~/.local/bin

然后把python脚本放到这个目录下
在这里插入图片描述
注意看一下是否有执行权限
在这里插入图片描述
没有的话添加一下

chmod +x ~/.local/bin/generate_cpp.py

然后需要配置环境变量
查看当前环境

echo $PATH

查看这个目录是否在环境下
不在的话我们添加一下

vim ~/.bashrc

把下面这个添加到最后一行

export PATH="$HOME/.local/bin:$PATH"

再重启一下

source ~/.bashrc

你就可以看到了
在这里插入图片描述
然后我们就能全局调用这个脚本

测试示例

在这里插入图片描述

#pragma once
#include <iostream>class Stonewt
{
public:enum Mode { STONE, POUND, INT };private:enum { Lbs_per_stn = 14 };int stone;double pds_left;double pounds;Mode mode;public:Stonewt(double lbs, Mode form = STONE);Stonewt(int stn, double lbs, Mode form = STONE);Stonewt(){stone = pounds = pds_left = 0;mode = STONE;}void stoneMode() { mode = STONE; }void poundMode() { mode = POUND; }void intMode() { mode = INT; }~Stonewt(){};bool operator<(const Stonewt &s);bool operator>(const Stonewt &s);bool operator<=(const Stonewt &s);bool operator>=(const Stonewt &s);bool operator==(const Stonewt &s);bool operator!=(const Stonewt &s);Stonewt operator+(const Stonewt &s);Stonewt operator-(const Stonewt &s);Stonewt operator-();friend Stonewt operator*(const Stonewt &s1, const Stonewt &s2);friend std::ostream &operator<<(std::ostream &os, const Stonewt &);friend std::istream &operator>>(std::istream &os, Stonewt &);
};
class test:Stonewt{
public:void fun1();virtual void fun2() const;static void fun3();
};
void show(const Stonewt & st);
void func();

测试示例来自c++Primerplus编程练习第11章第6题

这是生成的stonewt.cpp文件

#include "stonewt.h"Stonewt::Stonewt(double lbs, Mode form) {}Stonewt::Stonewt(int stn, double lbs, Mode form) {}bool Stonewt::operator<(const Stonewt &s) {}bool Stonewt::operator>(const Stonewt &s) {}bool Stonewt::operator<=(const Stonewt &s) {}bool Stonewt::operator>=(const Stonewt &s) {}bool Stonewt::operator==(const Stonewt &s) {}bool Stonewt::operator!=(const Stonewt &s) {}
✹ Stonewt Stonewt::operator+(const Stonewt &s) {}
✹ Stonewt Stonewt::operator-(const Stonewt &s) {}Stonewt Stonewt::operator-() {}
✹ Stonewt operator*(const Stonewt &s1, const Stonewt &s2) {}
✹ std::ostream & operator<<(std::ostream &os, const Stonewt &) {}
✹ std::istream & operator>>(std::istream &os, Stonewt &) {}void test::fun1() {}void test::fun2() const {}void test::fun3() {}void show(const Stonewt & st) {}void func() {}

这些是vim的提示,实际上没有

vim中调用

注意要完成前面的全局配置
推荐安装vimplus,可以参考这里

:!generate_cpp.py % %.cpp 

可以直接用这个调用,可以省略%.cpp

配置快捷键

添加我们自己的配置

 vim ~/.vimrc.custom.config 

在其中添加这样的内容,你就可以使用,cpp来生成源文件了

function! GenerateCpp()writelet output = system('generate_cpp.py ' . expand('%') . ' ' . expand('%:r') . '.cpp')if v:shell_errorcopencaddexpr outputecho "Error generating " . expand('%:r') . ".cpp"elseecho "Generated " . expand('%:r') . ".cpp successfully!"endif
endfunctionautocmd FileType cpp,h nnoremap <silent> <leader>cpp :call GenerateCpp()<CR>  
http://www.dtcms.com/wzjs/100819.html

相关文章:

  • 如何进行主题网站的资源建设晋城网站seo
  • 亚马逊品牌备案的网站怎么做武汉网络推广seo
  • 中标查询win10优化大师
  • 做网站维护需要懂什么获客渠道有哪些
  • FileZilla做网站郑州关键词网站优化排名
  • 网站备份还原百度热搜榜排名今日
  • 电商网站建设运营协议如何创建公司网站
  • 网站建设 司法公开的需要seo排名优化培训怎样
  • 建设银行贵阳银行下载官方网站做网络推广一般是什么专业
  • 做公务员题的网站seo关键词排名软件流量词
  • 微信公众平台账号注册商丘seo外包
  • 网店设计师是干什么的武汉seo网站优化运营
  • 怎么管理网站的内容瑞昌网络推广
  • asp网站后台失效简述网站制作的步骤
  • 深圳做网站平台维护的公司怎么在百度上做公司网页
  • qq空间可以做网站吗b站推广是什么意思
  • 长沙机械网站建设搜索引擎优化与关键词的关系
  • 网站如何做秒杀活动网络营销策略名词解释
  • 网站css样式下载seo优化排名工具
  • 全国美容网站建设深圳债务优化公司
  • 有app怎么做网站百度客服24小时人工服务
  • 快站怎么搭建淘客链接服务营销的概念
  • 漳州网站建设免费域名
  • 网站优化 图片网站关键字优化技巧
  • 辽宁城乡建设网站seo资讯
  • 陆丰网站建设石家庄网络营销
  • 网站 移动app开发深圳谷歌推广公司
  • 商务网站建设期末考试今天中国新闻
  • 自己做的网站怎么实现结算功能百度网页版电脑版入口
  • 电商网站设计模板台州seo排名外包