Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
qme
提交
13a27dbc
Q
qme
项目概览
youngwolf
/
qme
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
qme
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13a27dbc
编写于
2月 04, 2024
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code refactoring.
上级
31c3cbc4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
36 deletion
+14
-36
question_exp.h
question_exp.h
+14
-36
未找到文件。
question_exp.h
浏览文件 @
13a27dbc
...
@@ -518,7 +518,6 @@ template <typename T> class variable_data_exp : public data_exp<T>
...
@@ -518,7 +518,6 @@ template <typename T> class variable_data_exp : public data_exp<T>
public:
public:
variable_data_exp
(
const
std
::
string
&
_variable_name
)
:
variable_name
(
_variable_name
)
{}
variable_data_exp
(
const
std
::
string
&
_variable_name
)
:
variable_name
(
_variable_name
)
{}
virtual
const
std
::
string
&
get_variable_name
()
const
{
return
variable_name
;}
virtual
std
::
shared_ptr
<
data_exp
<
T
>>
to_negative
()
const
{
return
std
::
make_shared
<
negative_variable_data_exp
<
T
>>
(
variable_name
);}
virtual
std
::
shared_ptr
<
data_exp
<
T
>>
to_negative
()
const
{
return
std
::
make_shared
<
negative_variable_data_exp
<
T
>>
(
variable_name
);}
virtual
T
operator
()(
const
std
::
function
<
T
(
const
std
::
string
&
)
>&
cb
)
const
virtual
T
operator
()(
const
std
::
function
<
T
(
const
std
::
string
&
)
>&
cb
)
const
...
@@ -556,7 +555,6 @@ template <typename T> class exponent_data_exp : public data_exp<T>
...
@@ -556,7 +555,6 @@ template <typename T> class exponent_data_exp : public data_exp<T>
public:
public:
exponent_data_exp
(
const
std
::
string
&
_variable_name
,
int
_exponent
)
:
variable_name
(
_variable_name
),
exponent
(
_exponent
)
{}
exponent_data_exp
(
const
std
::
string
&
_variable_name
,
int
_exponent
)
:
variable_name
(
_variable_name
),
exponent
(
_exponent
)
{}
virtual
const
std
::
string
&
get_variable_name
()
const
{
return
variable_name
;}
virtual
void
show_immediate_value
()
const
{
std
::
cout
<<
' '
<<
exponent
;}
virtual
void
show_immediate_value
()
const
{
std
::
cout
<<
' '
<<
exponent
;}
virtual
std
::
shared_ptr
<
data_exp
<
T
>>
to_negative
()
const
virtual
std
::
shared_ptr
<
data_exp
<
T
>>
to_negative
()
const
...
@@ -952,26 +950,26 @@ template <typename T> inline T safe_execute(const std::shared_ptr<data_exp<T>>&
...
@@ -952,26 +950,26 @@ template <typename T> inline T safe_execute(const std::shared_ptr<data_exp<T>>&
{
{
std
::
list
<
immediate_data
<
T
>>
res
;
std
::
list
<
immediate_data
<
T
>>
res
;
travel_exp
<
std
::
shared_ptr
<
data_exp
<
T
>>>
(
dexp
,
travel_exp
<
std
::
shared_ptr
<
data_exp
<
T
>>>
(
dexp
,
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
res
.
emplace_back
(
data
->
safe_execute
(
cb
));},
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
left
)
{
res
.
emplace_back
(
left
->
safe_execute
(
cb
));},
[](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
)
{
return
false
;},
[](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
)
{
return
false
;},
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
res
.
emplace_back
(
data
->
safe_execute
(
cb
));},
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
right
)
{
res
.
emplace_back
(
right
->
safe_execute
(
cb
));},
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
[
&
](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
parent
)
{
T
re
=
res
.
back
();
T
re
=
res
.
back
();
res
.
pop_back
();
res
.
pop_back
();
res
.
back
().
merge_with
(
data
->
get_operator
(),
re
);
res
.
back
().
merge_with
(
parent
->
get_operator
(),
re
);
}
}
);
);
return
res
.
front
();
return
res
.
front
();
}
}
template
<
typename
T
>
inline
void
safe_delete
(
const
std
::
shared_ptr
<
data_exp
<
T
>>&
d
exp
)
template
<
typename
T
,
template
<
typename
>
class
Exp
>
inline
void
safe_delete
(
const
std
::
shared_ptr
<
Exp
<
T
>>&
exp
)
{
{
travel_exp
<
std
::
shared_ptr
<
data_exp
<
T
>>>
(
d
exp
,
travel_exp
<
std
::
shared_ptr
<
Exp
<
T
>>>
(
exp
,
[](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
data
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
Exp
<
T
>>&
left
)
{
left
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
data_e
xp
<
T
>>&
)
{
return
false
;},
[](
const
std
::
shared_ptr
<
E
xp
<
T
>>&
)
{
return
false
;},
[](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
data
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
Exp
<
T
>>&
right
)
{
right
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
data_exp
<
T
>>&
data
)
{
data
->
clear
();}
[](
const
std
::
shared_ptr
<
Exp
<
T
>>&
parent
)
{
parent
->
clear
();}
);
);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
...
@@ -997,36 +995,16 @@ template <typename T> inline bool safe_execute(const std::shared_ptr<judge_exp<T
...
@@ -997,36 +995,16 @@ template <typename T> inline bool safe_execute(const std::shared_ptr<judge_exp<T
{
{
auto
re
=
false
;
auto
re
=
false
;
travel_exp
<
std
::
shared_ptr
<
judge_exp
<
T
>>>
(
jexp
,
travel_exp
<
std
::
shared_ptr
<
judge_exp
<
T
>>>
(
jexp
,
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
re
=
judge
->
safe_execute
(
cb
);},
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
left
)
{
re
=
left
->
safe_execute
(
cb
);},
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
//this judgement will impact efficiency, but we have no choice, return false - continue, true - backtrack
auto
&
lop
=
judge
->
get_operator
();
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
parent
)
{
return
"&&"
==
parent
->
get_operator
()
?
!
re
:
re
;},
if
(
"&&"
==
lop
)
//this if statement will impact efficiency, but we have no choice
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
right
)
{
re
=
right
->
safe_execute
(
cb
);},
{
if
(
!
re
)
return
true
;
}
else
if
(
re
)
//"||" == lop
return
true
;
return
false
;
},
[
&
](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
re
=
judge
->
safe_execute
(
cb
);},
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
)
{}
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
)
{}
);
);
return
re
;
return
re
;
}
}
template
<
typename
T
>
inline
void
safe_delete
(
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
jexp
)
{
travel_exp
<
std
::
shared_ptr
<
judge_exp
<
T
>>>
(
jexp
,
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
judge
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
)
{
return
false
;},
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
judge
->
safe_delete
();},
[](
const
std
::
shared_ptr
<
judge_exp
<
T
>>&
judge
)
{
judge
->
clear
();}
);
}
template
<
typename
T
>
class
unitary_judge_exp
:
public
judge_exp
<
T
>
template
<
typename
T
>
class
unitary_judge_exp
:
public
judge_exp
<
T
>
{
{
protected:
protected:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录