Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c+;中每个函数定义的开头添加一个宏调用+;源文件 我想在我的C++ Visual Studio 2015项目的每个函数的开头添加一行代码。_C++_Python 3.x_Visual Studio 2015_Automation_Pypeg - Fatal编程技术网

在c+;中每个函数定义的开头添加一个宏调用+;源文件 我想在我的C++ Visual Studio 2015项目的每个函数的开头添加一行代码。

在c+;中每个函数定义的开头添加一个宏调用+;源文件 我想在我的C++ Visual Studio 2015项目的每个函数的开头添加一行代码。,c++,python-3.x,visual-studio-2015,automation,pypeg,C++,Python 3.x,Visual Studio 2015,Automation,Pypeg,在每个函数中手动添加一行需要几个月的时间。有没有快速的方法或工具来解决这个问题 功能示例包括: void Class::Func1(CATUnicodeString& Record ) const{ //some code } Class1::Class1():CATBaseUnknown() ,_usDrawingNumber( "" ){ //some code } Class1::~Class1() { //some code } 我需要处理所有这些函数定

在每个函数中手动添加一行需要几个月的时间。有没有快速的方法或工具来解决这个问题

功能示例包括:

void Class::Func1(CATUnicodeString& Record ) const{ //some code }

Class1::Class1():CATBaseUnknown() ,_usDrawingNumber( "" ){ //some code }

Class1::~Class1() { //some code }
我需要处理所有这些函数定义

样本:

void func1() 
{
    //code
}

int func2() 
{
    //code
}

char* func3() 
{
    //code
}

/* more functions */

bool func100()
{
    //code
}


//I want them to become:

void func1() 
{
    myMacro;
    //code
}

int func2() 
{
    myMacro;
    //code
}

char* func3() 
{
    myMacro;
    //code
}

/* more functions */

bool func100() 
{
    myMacro;
    //code
}
我发现类似的答案解释了regex、方面编程和pender。由于我是初学者,很难理解这些概念

期望是: 我想给工作区文件夹和工具的路径将获取所有的cpp文件,并在需要的地方添加宏

如果此工具不存在,请指导是否可以使用.net、java或python等任何技术构建类似的工具。

(^.*\(.*).*\n{\n(.*)
替换为
$1\nmyMacro\n$2


说明:

1st Capturing Group (^.*\(.*\).*\n{):
^ asserts position at start of a line
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\) matches the character ) literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
{ matches the character { literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)  

2nd Capturing Group (.*):
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed

回复:
我找到了类似的答案,解释了regex、方面编程和pender。由于我是初学者,很难理解这些概念。

在Visual Studio中使用查找替换;)

演示中链接的站点还提供了
C#/python
中的代码,可以稍加修改,并可以用作转换所需文件的“工具”

(^.*\(.*).*\n{)\n(.*)
替换为
$1\nmyMacro\n$2


说明:

1st Capturing Group (^.*\(.*\).*\n{):
^ asserts position at start of a line
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\) matches the character ) literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
{ matches the character { literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)  

2nd Capturing Group (.*):
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed

回复:
我找到了类似的答案,解释了regex、方面编程和pender。由于我是初学者,很难理解这些概念。

在Visual Studio中使用查找替换;)


演示中链接的站点还提供了
C#/python
中的代码,该代码可以稍加修改,可以用作转换所需文件的“工具”

我认为最合适的方法是使用clang refractor工具(您需要解析源文件):取决于您希望执行此操作的原因。如果您希望将其用作调试辅助工具,则最好使用调试器单步执行代码,而不是对其进行修改。函数示例包括:1.void Class::Func1(CATUnicodeString&Record)const{//some code}2.Class1::Class1():CATBaseUnknown(),_usDrawingNumber(“”{//some code}3.Class1::~Class1(){//some code}我需要处理所有这些函数定义。我认为最合适的方法是使用clang折射工具(您需要解析源文件):取决于您希望执行此操作的原因。如果您希望将其用作调试辅助工具,则最好使用调试器单步执行代码,而不是对其进行修改。函数示例包括:1.void Class::Func1(CATUnicodeString&Record)const{//some code}2.Class1::Class1():CATBaseUnknown(),_usDrawingNumber(“”{//some code}3.Class1::~Class1(){//一些代码}我需要处理所有这些函数定义。您假设每个函数都有一致的格式,并且函数的参数列表没有括号。包括对正则表达式的解释将有助于那些不使用正则表达式的人。演示是一个非现场资源,可以使用作为附加材料,但不可依赖。如果“需要几个月才能在每个功能中手动添加一行”这听起来好像有很多代码,可能是由许多不同的开发人员编写的。不能保证每个函数的格式都相同。特别是,lambda和类中声明的许多单行函数的格式通常不像全局函数那样。参数列表中有paren论文和它是由多人编写的。因此格式不一致。此正则表达式不起作用。它没有捕获单个函数定义。请建议一些更好的解决方案。@usmanharoon,如果它不起作用,我很抱歉:(我将尝试找到更好的解决方案。如果您愿意,您可以随意否决它:).另外,你确定你已经打开了find replace中的regex开关吗?因为它在我的visual studio(2019)中对我有效您假设每个函数都有一致的格式,并且函数的参数列表没有括号。包括对正则表达式的解释将有助于不使用正则表达式的人。演示是一个非现场资源,可以用作其他材料,但不能依赖。如果“手动在每个函数中添加一行需要几个月”这听起来好像有很多代码,可能是由许多不同的开发人员编写的。不能保证每个函数的格式都相同。特别是,lambda和类中声明的许多单行函数的格式通常不像全局函数那样。参数列表中有paren论文和它是由多人编写的。因此格式不一致。此正则表达式不起作用。它没有捕获单个函数定义。请建议一些更好的解决方案。@usmanharoon,如果它不起作用,我很抱歉:(我将尝试找到更好的解决方案。如果您愿意,您可以随意否决它:).另外,你确定你已经打开了find replace中的regex开关吗?因为它在我的visual studio(2019)中对我有效