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
28429701
Commit
28429701
authored
Nov 20, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge BasicArgFormatter and ArgFormatter
parent
d4084ac5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
39 deletions
+26
-39
fmt/format.h
fmt/format.h
+13
-23
fmt/printf.h
fmt/printf.h
+3
-4
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+4
-5
test/format-test.cc
test/format-test.cc
+4
-5
test/ostream-test.cc
test/ostream-test.cc
+2
-2
No files found.
fmt/format.h
View file @
28429701
...
...
@@ -1873,7 +1873,7 @@ void ArgMap<Char>::init(const basic_format_args<Formatter> &args) {
}
}
template
<
typename
Impl
,
typename
Char
>
template
<
typename
Char
>
class
ArgFormatterBase
{
private:
BasicWriter
<
Char
>
&
writer_
;
...
...
@@ -2055,9 +2055,9 @@ class format_context_base {
};
}
// namespace internal
/**
An
argument formatter. */
template
<
typename
Impl
,
typename
Char
>
class
BasicArgFormatter
:
public
internal
::
ArgFormatterBase
<
Impl
,
Char
>
{
/**
The default
argument formatter. */
template
<
typename
Char
>
class
ArgFormatter
:
public
internal
::
ArgFormatterBase
<
Char
>
{
private:
basic_format_context
<
Char
>
&
ctx_
;
...
...
@@ -2065,33 +2065,23 @@ class BasicArgFormatter : public internal::ArgFormatterBase<Impl, Char> {
/**
\rst
Constructs an argument formatter object.
*
formatter* is a reference to the main formatter object, *spec* contains
format specifier information for standard argument types, and *fmt* point
s
to the part of the format string being parsed for custom
argument types.
*
writer* is a reference to the writer to be used for output,
*ctx* is a reference to the formatting context, *spec* contain
s
format specifier information for standard
argument types.
\endrst
*/
Basic
ArgFormatter
(
BasicWriter
<
Char
>
&
writer
,
basic_format_context
<
Char
>
&
ctx
,
FormatSpec
&
spec
)
:
internal
::
ArgFormatterBase
<
Impl
,
Char
>
(
writer
,
spec
),
ctx_
(
ctx
)
{}
ArgFormatter
(
BasicWriter
<
Char
>
&
writer
,
basic_format_context
<
Char
>
&
ctx
,
FormatSpec
&
spec
)
:
internal
::
ArgFormatterBase
<
Char
>
(
writer
,
spec
),
ctx_
(
ctx
)
{}
using
internal
::
ArgFormatterBase
<
Impl
,
Char
>::
operator
();
using
internal
::
ArgFormatterBase
<
Char
>::
operator
();
/** Formats an argument of a custom (user-defined) type. */
void
operator
()(
internal
::
A
rg
::
CustomValue
c
)
{
void
operator
()(
format_a
rg
::
CustomValue
c
)
{
c
.
format
(
&
this
->
writer
(),
c
.
value
,
&
ctx_
);
}
};
/** The default argument formatter. */
template
<
typename
Char
>
class
ArgFormatter
:
public
BasicArgFormatter
<
ArgFormatter
<
Char
>
,
Char
>
{
public:
/** Constructs an argument formatter object. */
ArgFormatter
(
BasicWriter
<
Char
>
&
writer
,
basic_format_context
<
Char
>
&
ctx
,
FormatSpec
&
spec
)
:
BasicArgFormatter
<
ArgFormatter
<
Char
>
,
Char
>
(
writer
,
ctx
,
spec
)
{}
};
template
<
typename
Char
>
class
basic_format_context
:
public
internal
::
format_context_base
<
Char
,
basic_format_context
<
Char
>>
{
...
...
@@ -2305,7 +2295,7 @@ class BasicWriter {
template
<
typename
T
>
void
append_float_length
(
Char
*&
,
T
)
{}
template
<
typename
Impl
,
typename
Char_
>
template
<
typename
Char_
>
friend
class
internal
::
ArgFormatterBase
;
template
<
typename
Char_
>
...
...
fmt/printf.h
View file @
28429701
...
...
@@ -208,15 +208,14 @@ class WidthHandler {
\endrst
*/
template
<
typename
Char
>
class
PrintfArgFormatter
:
public
internal
::
ArgFormatterBase
<
PrintfArgFormatter
<
Char
>
,
Char
>
{
class
PrintfArgFormatter
:
public
internal
::
ArgFormatterBase
<
Char
>
{
private:
void
write_null_pointer
()
{
this
->
spec
().
type_
=
0
;
this
->
write
(
"(nil)"
);
}
typedef
internal
::
ArgFormatterBase
<
PrintfArgFormatter
<
Char
>
,
Char
>
Base
;
typedef
internal
::
ArgFormatterBase
<
Char
>
Base
;
public:
/**
...
...
@@ -227,7 +226,7 @@ class PrintfArgFormatter :
\endrst
*/
PrintfArgFormatter
(
BasicWriter
<
Char
>
&
writer
,
FormatSpec
&
spec
)
:
internal
::
ArgFormatterBase
<
PrintfArgFormatter
<
Char
>
,
Char
>
(
writer
,
spec
)
{}
:
internal
::
ArgFormatterBase
<
Char
>
(
writer
,
spec
)
{}
using
Base
::
operator
();
...
...
test/custom-formatter-test.cc
View file @
28429701
...
...
@@ -14,19 +14,18 @@ using fmt::PrintfArgFormatter;
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
class
CustomArgFormatter
:
public
fmt
::
BasicArgFormatter
<
CustomArgFormatter
,
char
>
{
class
CustomArgFormatter
:
public
fmt
::
ArgFormatter
<
char
>
{
public:
CustomArgFormatter
(
fmt
::
Writer
&
w
,
fmt
::
basic_format_context
<
char
>
&
ctx
,
fmt
::
FormatSpec
&
s
)
:
fmt
::
BasicArgFormatter
<
CustomArgFormatter
,
char
>
(
w
,
ctx
,
s
)
{}
:
fmt
::
ArgFormatter
<
char
>
(
w
,
ctx
,
s
)
{}
using
fmt
::
BasicArgFormatter
<
CustomArgFormatter
,
char
>::
operator
();
using
fmt
::
ArgFormatter
<
char
>::
operator
();
void
operator
()(
double
value
)
{
if
(
round
(
value
*
pow
(
10
,
spec
().
precision
()))
==
0
)
value
=
0
;
fmt
::
BasicArgFormatter
<
CustomArgFormatter
,
char
>::
operator
()(
value
);
fmt
::
ArgFormatter
<
char
>::
operator
()(
value
);
}
};
...
...
test/format-test.cc
View file @
28429701
...
...
@@ -1619,17 +1619,16 @@ TEST(FormatTest, Enum) {
EXPECT_EQ
(
"0"
,
fmt
::
format
(
"{}"
,
A
));
}
class
MockArgFormatter
:
public
fmt
::
internal
::
ArgFormatterBase
<
MockArgFormatter
,
char
>
{
class
MockArgFormatter
:
public
fmt
::
internal
::
ArgFormatterBase
<
char
>
{
private:
MOCK_METHOD1
(
call
,
void
(
int
value
));
public:
typedef
fmt
::
internal
::
ArgFormatterBase
<
MockArgFormatter
,
char
>
Base
;
typedef
fmt
::
internal
::
ArgFormatterBase
<
char
>
Base
;
MockArgFormatter
(
fmt
::
Writer
&
w
,
fmt
::
format_context
&
ctx
,
fmt
::
FormatSpec
&
s
)
:
fmt
::
internal
::
ArgFormatterBase
<
MockArgFormatter
,
char
>
(
w
,
s
)
{
:
fmt
::
internal
::
ArgFormatterBase
<
char
>
(
w
,
s
)
{
EXPECT_CALL
(
*
this
,
call
(
42
));
}
...
...
@@ -1637,7 +1636,7 @@ class MockArgFormatter :
void
operator
()(
int
value
)
{
call
(
value
);
}
void
operator
()(
fmt
::
internal
::
A
rg
::
CustomValue
)
{}
void
operator
()(
fmt
::
format_a
rg
::
CustomValue
)
{}
};
void
custom_vformat
(
fmt
::
CStringRef
format_str
,
fmt
::
format_args
args
)
{
...
...
test/ostream-test.cc
View file @
28429701
...
...
@@ -58,10 +58,10 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ
(
"0"
,
fmt
::
format
(
"{}"
,
A
));
}
struct
TestArgFormatter
:
fmt
::
BasicArgFormatter
<
TestArgFormatter
,
char
>
{
struct
TestArgFormatter
:
fmt
::
ArgFormatter
<
char
>
{
TestArgFormatter
(
fmt
::
Writer
&
w
,
fmt
::
format_context
&
ctx
,
fmt
::
FormatSpec
&
s
)
:
fmt
::
BasicArgFormatter
<
TestArgFormatter
,
char
>
(
w
,
ctx
,
s
)
{}
:
fmt
::
ArgFormatter
<
char
>
(
w
,
ctx
,
s
)
{}
};
TEST
(
OStreamTest
,
CustomArg
)
{
...
...
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