Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
cbaddefd
Commit
cbaddefd
authored
Dec 15, 2012
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forbid copying of ActiveFormat other that from a temporary object.
parent
4dbf00b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
30 deletions
+23
-30
format.h
format.h
+22
-14
format_test.cc
format_test.cc
+1
-16
No files found.
format.h
View file @
cbaddefd
...
...
@@ -402,8 +402,18 @@ class ActiveFormatter : public internal::ArgInserter {
Formatter
formatter_
;
Action
action_
;
// Forbid copying other than from a temporary. Do not implement.
ActiveFormatter
(
ActiveFormatter
&
);
// Do not implement.
ActiveFormatter
&
operator
=
(
const
ActiveFormatter
&
);
ActiveFormatter
&
operator
=
(
const
ActiveFormatter
&
);
struct
Proxy
{
const
char
*
format
;
Action
action
;
Proxy
(
const
char
*
fmt
,
Action
a
)
:
format
(
fmt
),
action
(
a
)
{}
};
public:
// Creates an active formatter with a format string and an action.
...
...
@@ -415,21 +425,21 @@ class ActiveFormatter : public internal::ArgInserter {
Init
(
formatter_
,
format
);
}
// Creates an active formatter with the same format string and action
// as other has and modifies other so that it doesn't call action in
// destructor. Note that the buffer content is not copied because the
// the buffer in ActiveFormatter is populated when all the arguments
// are provided.
ActiveFormatter
(
const
ActiveFormatter
&
other
)
:
ArgInserter
(
0
),
action_
(
other
.
action_
)
{
Init
(
formatter_
,
other
.
format
());
other
.
ResetFormatter
();
ActiveFormatter
(
const
Proxy
&
p
)
:
ArgInserter
(
0
),
action_
(
p
.
action
)
{
Init
(
formatter_
,
p
.
format
);
}
~
ActiveFormatter
()
{
if
(
formatter
())
action_
(
*
Format
());
}
operator
Proxy
()
{
const
char
*
fmt
=
format
();
ResetFormatter
();
return
Proxy
(
fmt
,
action_
);
}
};
// A formatting action that does nothing.
...
...
@@ -441,8 +451,7 @@ struct Ignore {
// Example:
// std::string s = str(Format("Elapsed time: {0:.2f} seconds") << 1.23);
inline
ActiveFormatter
<
Ignore
>
Format
(
const
char
*
format
)
{
ActiveFormatter
<
Ignore
>
af
(
format
);
return
af
;
return
ActiveFormatter
<
Ignore
>
(
format
);
}
// A formatting action that writes formatted output to stdout.
...
...
@@ -456,8 +465,7 @@ struct Write {
// Example:
// Print("Elapsed time: {0:.2f} seconds") << 1.23;
inline
ActiveFormatter
<
Write
>
Print
(
const
char
*
format
)
{
ActiveFormatter
<
Write
>
af
(
format
);
return
af
;
return
ActiveFormatter
<
Write
>
(
format
);
}
}
...
...
format_test.cc
View file @
cbaddefd
...
...
@@ -708,20 +708,6 @@ TEST(ActiveFormatterTest, Action) {
EXPECT_EQ
(
1
,
num_calls
);
}
TEST
(
ActiveFormatterTest
,
Copy
)
{
int
num_calls
=
0
;
typedef
fmt
::
ActiveFormatter
<
CountCalls
>
AF
;
std
::
auto_ptr
<
AF
>
af
(
new
AF
(
"test"
,
CountCalls
(
num_calls
)));
EXPECT_EQ
(
0
,
num_calls
);
{
AF
copy
(
*
af
);
EXPECT_EQ
(
0
,
num_calls
);
af
.
reset
();
EXPECT_EQ
(
0
,
num_calls
);
}
EXPECT_EQ
(
1
,
num_calls
);
}
TEST
(
ActiveFormatterTest
,
ActionNotCalledOnError
)
{
int
num_calls
=
0
;
{
...
...
@@ -751,8 +737,7 @@ struct PrintError {
};
fmt
::
ActiveFormatter
<
PrintError
>
ReportError
(
const
char
*
format
)
{
fmt
::
ActiveFormatter
<
PrintError
>
af
(
format
);
return
af
;
return
fmt
::
ActiveFormatter
<
PrintError
>
(
format
);
}
TEST
(
ActiveFormatterTest
,
Example
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment