Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
201e00b0
Commit
201e00b0
authored
Nov 10, 2010
by
Adam Wardyński
Browse files
Options
Downloads
Patches
Plain Diff
Some fiddling around to_string functino to use stringstream
parent
9531db83
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
libwccl/ops/conditional.h
+53
-36
53 additions, 36 deletions
libwccl/ops/conditional.h
libwccl/ops/formatters.cpp
+17
-24
17 additions, 24 deletions
libwccl/ops/formatters.cpp
libwccl/ops/logicalpredicate.cpp
+14
-12
14 additions, 12 deletions
libwccl/ops/logicalpredicate.cpp
with
84 additions
and
72 deletions
libwccl/ops/conditional.h
+
53
−
36
View file @
201e00b0
...
@@ -9,6 +9,9 @@
...
@@ -9,6 +9,9 @@
#include
<libwccl/ops/formatters.h>
#include
<libwccl/ops/formatters.h>
#include
<libwccl/ops/constant.h>
#include
<libwccl/ops/constant.h>
#include
<sstream>
#include
<boost/format.hpp>
namespace
Wccl
{
namespace
Wccl
{
/**
/**
...
@@ -37,16 +40,7 @@ public:
...
@@ -37,16 +40,7 @@ public:
* String representation of conditional operator in form of:
* String representation of conditional operator in form of:
* "if cond_expr_string then iftrue_expr_string else iffalse_expr_string"
* "if cond_expr_string then iftrue_expr_string else iffalse_expr_string"
*/
*/
virtual
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
virtual
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
std
::
string
s
(
this
->
operator_name
(
tagset
));
s
.
append
(
" "
);
s
.
append
(
cond_expr_
->
to_string
(
tagset
));
s
.
append
(
" then "
);
s
.
append
(
iftrue_expr_
->
to_string
(
tagset
));
s
.
append
(
" else "
);
s
.
append
(
iffalse_expr_
->
to_string
(
tagset
));
return
s
;
}
/**
/**
* String representation of conditional operator in form of:
* String representation of conditional operator in form of:
...
@@ -54,16 +48,7 @@ public:
...
@@ -54,16 +48,7 @@ public:
* This version does not require tagset, but may be inclomplete
* This version does not require tagset, but may be inclomplete
* and/or contain internal info.
* and/or contain internal info.
*/
*/
virtual
std
::
string
to_raw_string
()
const
{
virtual
std
::
string
to_raw_string
()
const
;
std
::
string
s
(
this
->
raw_operator_name
());
s
.
append
(
" "
);
s
.
append
(
cond_expr_
->
to_raw_string
());
s
.
append
(
" then "
);
s
.
append
(
iftrue_expr_
->
to_raw_string
());
s
.
append
(
" else "
);
s
.
append
(
iffalse_expr_
->
to_raw_string
());
return
s
;
}
virtual
const
std
::
string
raw_operator_name
()
const
{
virtual
const
std
::
string
raw_operator_name
()
const
{
return
"if"
;
return
"if"
;
...
@@ -118,14 +103,7 @@ public:
...
@@ -118,14 +103,7 @@ public:
* String representation of conditional operator in form of:
* String representation of conditional operator in form of:
* "? if_true_expr_string ? cond_expr_string"
* "? if_true_expr_string ? cond_expr_string"
*/
*/
virtual
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
virtual
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
std
::
string
s
(
this
->
operator_name
(
tagset
));
s
.
append
(
" "
);
s
.
append
(
this
->
iftrue_expr_
->
to_string
(
tagset
));
s
.
append
(
" ? "
);
s
.
append
(
this
->
cond_expr_
->
to_string
(
tagset
));
return
s
;
}
/**
/**
* String representation of conditional operator in form of:
* String representation of conditional operator in form of:
...
@@ -133,20 +111,59 @@ public:
...
@@ -133,20 +111,59 @@ public:
* This version does not require tagset, but may be inclomplete
* This version does not require tagset, but may be inclomplete
* and/or contain internal info.
* and/or contain internal info.
*/
*/
virtual
std
::
string
to_raw_string
()
const
{
virtual
std
::
string
to_raw_string
()
const
;
std
::
string
s
(
this
->
raw_operator_name
());
s
.
append
(
" "
);
s
.
append
(
this
->
iftrue_expr_
->
to_raw_string
());
s
.
append
(
" ? "
);
s
.
append
(
this
->
cond_expr_
->
to_raw_string
());
return
s
;
}
virtual
const
std
::
string
raw_operator_name
()
const
{
virtual
const
std
::
string
raw_operator_name
()
const
{
return
"?"
;
return
"?"
;
}
}
};
};
template
<
class
T
>
std
::
string
Conditional
<
T
>::
to_raw_string
()
const
{
std
::
stringstream
ss
;
ss
<<
boost
::
format
(
"%1% %2% then %3% else %4%"
)
%
this
->
raw_operator_name
()
%
this
->
cond_expr_
->
to_raw_string
()
%
this
->
iftrue_expr_
->
to_raw_string
()
%
this
->
iffalse_expr_
->
to_raw_string
();
return
ss
.
str
();
}
template
<
class
T
>
std
::
string
Conditional
<
T
>::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
std
::
stringstream
ss
;
ss
<<
boost
::
format
(
"%1% %2% then %3% else %4%"
)
%
this
->
operator_name
(
tagset
)
%
this
->
cond_expr_
->
to_string
(
tagset
)
%
this
->
iftrue_expr_
->
to_string
(
tagset
)
%
this
->
iffalse_expr_
->
to_string
(
tagset
);
return
ss
.
str
();
}
template
<
class
T
>
std
::
string
ConditionalOp
<
T
>::
to_raw_string
()
const
{
std
::
stringstream
ss
;
ss
<<
boost
::
format
(
"%1% %2% ? %3%"
)
%
this
->
raw_operator_name
()
%
this
->
iftrue_expr_
->
to_raw_string
()
%
this
->
cond_expr_
->
to_raw_string
();
return
ss
.
str
();
}
template
<
class
T
>
std
::
string
ConditionalOp
<
T
>::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
std
::
stringstream
ss
;
ss
<<
boost
::
format
(
"%1% %2% ? %3%"
)
%
this
->
operator_name
(
tagset
)
%
this
->
iftrue_expr_
->
to_string
(
tagset
)
%
this
->
cond_expr_
->
to_string
(
tagset
);
return
ss
.
str
();
}
}
/* end ns Wccl */
}
/* end ns Wccl */
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/formatters.cpp
+
17
−
24
View file @
201e00b0
#include
<libwccl/ops/formatters.h>
#include
<libwccl/ops/formatters.h>
#include
<sstream>
namespace
Wccl
{
namespace
Wccl
{
...
@@ -10,11 +11,10 @@ std::string UnaryFunctionFormatter::to_raw_string(
...
@@ -10,11 +11,10 @@ std::string UnaryFunctionFormatter::to_raw_string(
const
char
*
open_bracket
,
const
char
*
open_bracket
,
const
char
*
close_bracket
)
const
char
*
close_bracket
)
{
{
std
::
string
s
(
f
.
raw_operator_name
());
std
::
stringstream
ss
;
s
.
append
(
open_bracket
);
ss
<<
f
.
raw_operator_name
()
<<
open_bracket
<<
arg_expr
.
to_raw_string
()
s
.
append
(
arg_expr
.
to_raw_string
());
<<
close_bracket
;
s
.
append
(
close_bracket
);
return
ss
.
str
();
return
s
;
}
}
std
::
string
UnaryFunctionFormatter
::
to_string
(
std
::
string
UnaryFunctionFormatter
::
to_string
(
...
@@ -24,11 +24,10 @@ std::string UnaryFunctionFormatter::to_string(
...
@@ -24,11 +24,10 @@ std::string UnaryFunctionFormatter::to_string(
const
char
*
open_bracket
,
const
char
*
open_bracket
,
const
char
*
close_bracket
)
const
char
*
close_bracket
)
{
{
std
::
string
s
(
f
.
operator_name
(
tagset
));
std
::
stringstream
ss
;
s
.
append
(
open_bracket
);
ss
<<
f
.
operator_name
(
tagset
)
<<
open_bracket
<<
arg_expr
.
to_string
(
tagset
)
s
.
append
(
arg_expr
.
to_string
(
tagset
));
<<
close_bracket
;
s
.
append
(
close_bracket
);
return
ss
.
str
();
return
s
;
}
}
// ----- BinaryFunctionFormatter ------
// ----- BinaryFunctionFormatter ------
...
@@ -39,13 +38,10 @@ std::string BinaryFunctionFormatter::to_string(
...
@@ -39,13 +38,10 @@ std::string BinaryFunctionFormatter::to_string(
const
FunctionBase
&
arg1_expr
,
const
FunctionBase
&
arg1_expr
,
const
FunctionBase
&
arg2_expr
)
const
FunctionBase
&
arg2_expr
)
{
{
std
::
string
s
(
f
.
operator_name
(
tagset
));
std
::
stringstream
ss
;
s
.
append
(
"("
);
ss
<<
f
.
operator_name
(
tagset
)
<<
"("
<<
arg1_expr
.
to_string
(
tagset
)
s
.
append
(
arg1_expr
.
to_string
(
tagset
));
<<
", "
<<
arg2_expr
.
to_string
(
tagset
)
<<
")"
;
s
.
append
(
", "
);
return
ss
.
str
();
s
.
append
(
arg2_expr
.
to_string
(
tagset
));
s
.
append
(
")"
);
return
s
;
}
}
std
::
string
BinaryFunctionFormatter
::
to_raw_string
(
std
::
string
BinaryFunctionFormatter
::
to_raw_string
(
...
@@ -53,13 +49,10 @@ std::string BinaryFunctionFormatter::to_raw_string(
...
@@ -53,13 +49,10 @@ std::string BinaryFunctionFormatter::to_raw_string(
const
FunctionBase
&
arg1_expr
,
const
FunctionBase
&
arg1_expr
,
const
FunctionBase
&
arg2_expr
)
const
FunctionBase
&
arg2_expr
)
{
{
std
::
string
s
(
f
.
raw_operator_name
());
std
::
stringstream
ss
;
s
.
append
(
"("
);
ss
<<
f
.
raw_operator_name
()
<<
"("
<<
arg1_expr
.
to_raw_string
()
s
.
append
(
arg1_expr
.
to_raw_string
());
<<
", "
<<
arg2_expr
.
to_raw_string
()
<<
")"
;
s
.
append
(
", "
);
return
ss
.
str
();
s
.
append
(
arg2_expr
.
to_raw_string
());
s
.
append
(
")"
);
return
s
;
}
}
}
/* end ns Wccl */
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/logicalpredicate.cpp
+
14
−
12
View file @
201e00b0
#include
<libwccl/ops/logicalpredicate.h>
#include
<libwccl/ops/logicalpredicate.h>
#include
<sstream>
namespace
Wccl
{
namespace
Wccl
{
std
::
string
LogicalPredicate
::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
std
::
string
LogicalPredicate
::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
{
std
::
string
s
(
operator_name
(
tagset
))
;
std
::
string
stream
ss
;
s
.
append
(
"("
)
;
s
s
<<
operator_name
(
tagset
)
<<
"("
;
BoolFunctionPtrVector
::
const_iterator
it
=
expressions_
->
begin
();
BoolFunctionPtrVector
::
const_iterator
it
=
expressions_
->
begin
();
while
(
it
!=
expressions_
->
end
())
{
while
(
it
!=
expressions_
->
end
())
{
s
.
append
(
(
*
it
)
->
to_string
(
tagset
)
)
;
s
s
<<
(
*
it
)
->
to_string
(
tagset
);
if
(
++
it
!=
expressions_
->
end
())
{
if
(
++
it
!=
expressions_
->
end
())
{
s
.
append
(
", "
)
;
s
s
<<
", "
;
}
}
}
}
s
.
append
(
")"
)
;
s
s
<<
")"
;
return
s
;
return
s
s
.
str
()
;
}
}
std
::
string
LogicalPredicate
::
to_raw_string
()
const
std
::
string
LogicalPredicate
::
to_raw_string
()
const
{
{
std
::
string
s
(
raw_operator_name
())
;
std
::
string
stream
ss
;
s
.
append
(
"("
)
;
s
s
<<
raw_operator_name
()
<<
"("
;
BoolFunctionPtrVector
::
const_iterator
it
=
expressions_
->
begin
();
BoolFunctionPtrVector
::
const_iterator
it
=
expressions_
->
begin
();
while
(
it
!=
expressions_
->
end
())
{
while
(
it
!=
expressions_
->
end
())
{
s
.
append
(
(
*
it
)
->
to_raw_string
()
)
;
s
s
<<
(
*
it
)
->
to_raw_string
();
if
(
++
it
!=
expressions_
->
end
())
{
if
(
++
it
!=
expressions_
->
end
())
{
s
.
append
(
", "
)
;
s
s
<<
", "
;
}
}
}
}
s
.
append
(
")"
)
;
s
s
<<
")"
;
return
s
;
return
s
s
.
str
()
;
}
}
}
/* end ns Wccl */
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment