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
422236af
Commit
422236af
authored
Dec 28, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't erase writer type
parent
abb6996f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
18 deletions
+20
-18
fmt/format.h
fmt/format.h
+11
-10
fmt/printf.h
fmt/printf.h
+2
-2
test/format-test.cc
test/format-test.cc
+1
-1
test/util-test.cc
test/util-test.cc
+6
-5
No files found.
fmt/format.h
View file @
422236af
...
...
@@ -1089,9 +1089,11 @@ struct StringValue {
std
::
size_t
size
;
};
typedef
void
(
*
FormatFunc
)(
void
*
writer
,
const
void
*
arg
,
void
*
ctx
);
template
<
typename
Char
>
struct
CustomValue
{
typedef
void
(
*
FormatFunc
)(
BasicWriter
<
Char
>
&
writer
,
const
void
*
arg
,
void
*
ctx
);
const
void
*
value
;
FormatFunc
format
;
};
...
...
@@ -1111,7 +1113,7 @@ struct Value {
StringValue
<
signed
char
>
sstring
;
StringValue
<
unsigned
char
>
ustring
;
StringValue
<
Char
>
tstring
;
CustomValue
custom
;
CustomValue
<
Char
>
custom
;
};
};
...
...
@@ -1216,9 +1218,8 @@ class MakeValue : public Value<typename Context::char_type> {
// Formats an argument of a custom type, such as a user-defined class.
template
<
typename
T
>
static
void
format_custom_arg
(
void
*
writer
,
const
void
*
arg
,
void
*
context
)
{
format_value
(
*
static_cast
<
BasicWriter
<
Char
>*>
(
writer
),
*
static_cast
<
const
T
*>
(
arg
),
BasicWriter
<
Char
>
&
writer
,
const
void
*
arg
,
void
*
context
)
{
format_value
(
writer
,
*
static_cast
<
const
T
*>
(
arg
),
*
static_cast
<
Context
*>
(
context
));
}
...
...
@@ -2140,8 +2141,8 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> {
using
internal
::
ArgFormatterBase
<
Char
>::
operator
();
/** Formats an argument of a custom (user-defined) type. */
void
operator
()(
internal
::
CustomValue
c
)
{
c
.
format
(
&
this
->
writer
(),
c
.
value
,
&
ctx_
);
void
operator
()(
internal
::
CustomValue
<
Char
>
c
)
{
c
.
format
(
this
->
writer
(),
c
.
value
,
&
ctx_
);
}
};
...
...
@@ -3371,8 +3372,8 @@ class CustomFormatter {
CustomFormatter
(
BasicWriter
<
Char
>
&
writer
,
Context
&
ctx
)
:
writer_
(
writer
),
ctx_
(
ctx
)
{}
bool
operator
()(
internal
::
CustomValue
custom
)
{
custom
.
format
(
&
writer_
,
custom
.
value
,
&
ctx_
);
bool
operator
()(
internal
::
CustomValue
<
Char
>
custom
)
{
custom
.
format
(
writer_
,
custom
.
value
,
&
ctx_
);
return
true
;
}
...
...
fmt/printf.h
View file @
422236af
...
...
@@ -281,11 +281,11 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
}
/** Formats an argument of a custom (user-defined) type. */
void
operator
()(
internal
::
CustomValue
c
)
{
void
operator
()(
internal
::
CustomValue
<
Char
>
c
)
{
const
Char
format_str
[]
=
{
'}'
,
'\0'
};
auto
args
=
basic_format_args
<
basic_format_context
<
Char
>
,
Char
>
();
basic_format_context
<
Char
>
ctx
(
format_str
,
args
);
c
.
format
(
&
this
->
writer
(),
c
.
value
,
&
ctx
);
c
.
format
(
this
->
writer
(),
c
.
value
,
&
ctx
);
}
};
...
...
test/format-test.cc
View file @
422236af
...
...
@@ -1637,7 +1637,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
void
operator
()(
int
value
)
{
call
(
value
);
}
void
operator
()(
fmt
::
internal
::
CustomValue
)
{}
void
operator
()(
fmt
::
internal
::
CustomValue
<
char
>
)
{}
};
void
custom_vformat
(
fmt
::
CStringRef
format_str
,
fmt
::
format_args
args
)
{
...
...
test/util-test.cc
View file @
422236af
...
...
@@ -426,14 +426,15 @@ TEST(UtilTest, MakeValueWithCustomFormatter) {
fmt
::
internal
::
Value
<
char
>
arg
=
fmt
::
internal
::
MakeValue
<
CustomFormatter
>
(
t
);
CustomFormatter
ctx
=
{
false
};
fmt
::
MemoryWriter
w
;
arg
.
custom
.
format
(
&
w
,
&
t
,
&
ctx
);
arg
.
custom
.
format
(
w
,
&
t
,
&
ctx
);
EXPECT_TRUE
(
ctx
.
called
);
}
namespace
fmt
{
namespace
internal
{
bool
operator
==
(
CustomValue
lhs
,
CustomValue
rhs
)
{
template
<
typename
Char
>
bool
operator
==
(
CustomValue
<
Char
>
lhs
,
CustomValue
<
Char
>
rhs
)
{
return
lhs
.
value
==
rhs
.
value
;
}
}
...
...
@@ -563,14 +564,14 @@ TEST(UtilTest, PointerArg) {
TEST
(
UtilTest
,
CustomArg
)
{
::
Test
test
;
typedef
MockVisitor
<
fmt
::
internal
::
CustomValue
>
Visitor
;
typedef
MockVisitor
<
fmt
::
internal
::
CustomValue
<
char
>
>
Visitor
;
testing
::
StrictMock
<
Visitor
>
visitor
;
EXPECT_CALL
(
visitor
,
visit
(
_
)).
WillOnce
(
testing
::
Invoke
([
&
](
fmt
::
internal
::
CustomValue
custom
)
{
testing
::
Invoke
([
&
](
fmt
::
internal
::
CustomValue
<
char
>
custom
)
{
EXPECT_EQ
(
&
test
,
custom
.
value
);
fmt
::
MemoryWriter
w
;
fmt
::
format_context
ctx
(
"}"
,
fmt
::
format_args
());
custom
.
format
(
&
w
,
&
test
,
&
ctx
);
custom
.
format
(
w
,
&
test
,
&
ctx
);
EXPECT_EQ
(
"test"
,
w
.
str
());
return
Visitor
::
Result
();
}));
...
...
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