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
42a31907
Commit
42a31907
authored
Dec 29, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parameterize Value on context
parent
a4d6cb32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
fmt/format.h
fmt/format.h
+10
-11
test/util-test.cc
test/util-test.cc
+5
-4
No files found.
fmt/format.h
View file @
42a31907
...
@@ -1098,7 +1098,7 @@ struct CustomValue {
...
@@ -1098,7 +1098,7 @@ struct CustomValue {
};
};
// A formatting argument value.
// A formatting argument value.
template
<
typename
C
har
>
template
<
typename
C
ontext
>
struct
Value
{
struct
Value
{
union
{
union
{
int
int_value
;
int
int_value
;
...
@@ -1111,8 +1111,8 @@ struct Value {
...
@@ -1111,8 +1111,8 @@ struct Value {
StringValue
<
char
>
string
;
StringValue
<
char
>
string
;
StringValue
<
signed
char
>
sstring
;
StringValue
<
signed
char
>
sstring
;
StringValue
<
unsigned
char
>
ustring
;
StringValue
<
unsigned
char
>
ustring
;
StringValue
<
Char
>
tstring
;
StringValue
<
typename
Context
::
char_type
>
tstring
;
CustomValue
<
Char
>
custom
;
CustomValue
<
typename
Context
::
char_type
>
custom
;
};
};
};
};
...
@@ -1177,7 +1177,7 @@ constexpr Type type() { return gettype<typename std::decay<T>::type>(); }
...
@@ -1177,7 +1177,7 @@ constexpr Type type() { return gettype<typename std::decay<T>::type>(); }
// Makes a format_arg object from any type.
// Makes a format_arg object from any type.
template
<
typename
Context
>
template
<
typename
Context
>
class
MakeValue
:
public
Value
<
typename
Context
::
char_type
>
{
class
MakeValue
:
public
Value
<
Context
>
{
public:
public:
typedef
typename
Context
::
char_type
Char
;
typedef
typename
Context
::
char_type
Char
;
...
@@ -1347,7 +1347,7 @@ class basic_format_args;
...
@@ -1347,7 +1347,7 @@ class basic_format_args;
template
<
typename
Context
>
template
<
typename
Context
>
class
basic_format_arg
{
class
basic_format_arg
{
private:
private:
internal
::
Value
<
typename
Context
::
char_type
>
value_
;
internal
::
Value
<
Context
>
value_
;
internal
::
Type
type_
;
internal
::
Type
type_
;
template
<
typename
ContextType
,
typename
T
>
template
<
typename
ContextType
,
typename
T
>
...
@@ -1514,8 +1514,7 @@ constexpr uint64_t make_type<void>() { return 0; }
...
@@ -1514,8 +1514,7 @@ constexpr uint64_t make_type<void>() { return 0; }
enum
{
MAX_PACKED_ARGS
=
16
};
enum
{
MAX_PACKED_ARGS
=
16
};
template
<
bool
IS_PACKED
,
typename
Context
,
typename
T
>
template
<
bool
IS_PACKED
,
typename
Context
,
typename
T
>
inline
typename
std
::
enable_if
<
inline
typename
std
::
enable_if
<
IS_PACKED
,
Value
<
Context
>>::
type
IS_PACKED
,
Value
<
typename
Context
::
char_type
>>::
type
make_arg
(
const
T
&
value
)
{
make_arg
(
const
T
&
value
)
{
return
MakeValue
<
Context
>
(
value
);
return
MakeValue
<
Context
>
(
value
);
}
}
...
@@ -1538,7 +1537,7 @@ class format_arg_store {
...
@@ -1538,7 +1537,7 @@ class format_arg_store {
typedef
typename
Context
::
char_type
char_type
;
typedef
typename
Context
::
char_type
char_type
;
typedef
typename
std
::
conditional
<
IS_PACKED
,
typedef
typename
std
::
conditional
<
IS_PACKED
,
internal
::
Value
<
char_type
>
,
basic_format_arg
<
Context
>>::
type
value_type
;
internal
::
Value
<
Context
>
,
basic_format_arg
<
Context
>>::
type
value_type
;
// If the arguments are not packed, add one more element to mark the end.
// If the arguments are not packed, add one more element to mark the end.
typedef
std
::
array
<
value_type
,
NUM_ARGS
+
(
IS_PACKED
?
0
:
1
)
>
Array
;
typedef
std
::
array
<
value_type
,
NUM_ARGS
+
(
IS_PACKED
?
0
:
1
)
>
Array
;
...
@@ -1582,7 +1581,7 @@ class basic_format_args {
...
@@ -1582,7 +1581,7 @@ class basic_format_args {
// This is done to reduce compiled code size as storing larger objects
// This is done to reduce compiled code size as storing larger objects
// may require more code (at least on x86-64) even if the same amount of
// may require more code (at least on x86-64) even if the same amount of
// data is actually copied to stack. It saves ~10% on the bloat test.
// data is actually copied to stack. It saves ~10% on the bloat test.
const
internal
::
Value
<
C
har
>
*
values_
;
const
internal
::
Value
<
C
ontext
>
*
values_
;
const
format_arg
*
args_
;
const
format_arg
*
args_
;
};
};
...
@@ -1595,7 +1594,7 @@ class basic_format_args {
...
@@ -1595,7 +1594,7 @@ class basic_format_args {
friend
class
internal
::
ArgMap
<
Context
>
;
friend
class
internal
::
ArgMap
<
Context
>
;
void
set_data
(
const
internal
::
Value
<
C
har
>
*
values
)
{
values_
=
values
;
}
void
set_data
(
const
internal
::
Value
<
C
ontext
>
*
values
)
{
values_
=
values
;
}
void
set_data
(
const
format_arg
*
args
)
{
args_
=
args
;
}
void
set_data
(
const
format_arg
*
args
)
{
args_
=
args
;
}
format_arg
get
(
size_type
index
)
const
{
format_arg
get
(
size_type
index
)
const
{
...
@@ -1603,7 +1602,7 @@ class basic_format_args {
...
@@ -1603,7 +1602,7 @@ class basic_format_args {
bool
use_values
=
type
(
internal
::
MAX_PACKED_ARGS
-
1
)
==
internal
::
NONE
;
bool
use_values
=
type
(
internal
::
MAX_PACKED_ARGS
-
1
)
==
internal
::
NONE
;
if
(
index
<
internal
::
MAX_PACKED_ARGS
)
{
if
(
index
<
internal
::
MAX_PACKED_ARGS
)
{
typename
internal
::
Type
arg_type
=
type
(
index
);
typename
internal
::
Type
arg_type
=
type
(
index
);
internal
::
Value
<
C
har
>
&
val
=
arg
.
value_
;
internal
::
Value
<
C
ontext
>
&
val
=
arg
.
value_
;
if
(
arg_type
!=
internal
::
NONE
)
if
(
arg_type
!=
internal
::
NONE
)
val
=
use_values
?
values_
[
index
]
:
args_
[
index
].
value_
;
val
=
use_values
?
values_
[
index
]
:
args_
[
index
].
value_
;
arg
.
type_
=
arg_type
;
arg
.
type_
=
arg_type
;
...
...
test/util-test.cc
View file @
42a31907
...
@@ -412,19 +412,20 @@ TEST(UtilTest, FormatArgs) {
...
@@ -412,19 +412,20 @@ TEST(UtilTest, FormatArgs) {
EXPECT_FALSE
(
args
[
1
]);
EXPECT_FALSE
(
args
[
1
]);
}
}
struct
Custom
Formatter
{
struct
Custom
Context
{
typedef
char
char_type
;
typedef
char
char_type
;
bool
called
;
bool
called
;
};
};
void
format_value
(
fmt
::
Writer
&
,
const
Test
&
,
Custom
Formatter
&
ctx
)
{
void
format_value
(
fmt
::
Writer
&
,
const
Test
&
,
Custom
Context
&
ctx
)
{
ctx
.
called
=
true
;
ctx
.
called
=
true
;
}
}
TEST
(
UtilTest
,
MakeValueWithCustomFormatter
)
{
TEST
(
UtilTest
,
MakeValueWithCustomFormatter
)
{
::
Test
t
;
::
Test
t
;
fmt
::
internal
::
Value
<
char
>
arg
=
fmt
::
internal
::
MakeValue
<
CustomFormatter
>
(
t
);
fmt
::
internal
::
Value
<
CustomContext
>
arg
=
CustomFormatter
ctx
=
{
false
};
fmt
::
internal
::
MakeValue
<
CustomContext
>
(
t
);
CustomContext
ctx
=
{
false
};
fmt
::
MemoryWriter
w
;
fmt
::
MemoryWriter
w
;
arg
.
custom
.
format
(
w
,
&
t
,
&
ctx
);
arg
.
custom
.
format
(
w
,
&
t
,
&
ctx
);
EXPECT_TRUE
(
ctx
.
called
);
EXPECT_TRUE
(
ctx
.
called
);
...
...
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