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
3f4984fb
Commit
3f4984fb
authored
Sep 19, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean core-test and fix linkage errors on older gcc
parent
d4366505
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
635 additions
and
606 deletions
+635
-606
include/fmt/core.h
include/fmt/core.h
+48
-0
include/fmt/format.h
include/fmt/format.h
+0
-48
src/format.cc
src/format.cc
+17
-10
test/CMakeLists.txt
test/CMakeLists.txt
+2
-2
test/core-test.cc
test/core-test.cc
+94
-527
test/format-test.cc
test/format-test.cc
+455
-0
test/mock-allocator.h
test/mock-allocator.h
+11
-10
test/test-assert.h
test/test-assert.h
+8
-9
No files found.
include/fmt/core.h
View file @
3f4984fb
...
@@ -755,6 +755,54 @@ class basic_format_arg {
...
@@ -755,6 +755,54 @@ class basic_format_arg {
bool
is_arithmetic
()
const
{
return
internal
::
is_arithmetic
(
type_
);
}
bool
is_arithmetic
()
const
{
return
internal
::
is_arithmetic
(
type_
);
}
};
};
struct
monostate
{};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template
<
typename
Visitor
,
typename
Context
>
FMT_CONSTEXPR
typename
internal
::
result_of
<
Visitor
(
int
)
>::
type
visit
(
Visitor
&&
vis
,
const
basic_format_arg
<
Context
>
&
arg
)
{
typedef
typename
Context
::
char_type
char_type
;
switch
(
arg
.
type_
)
{
case
internal
:
:
none_type
:
break
;
case
internal
:
:
named_arg_type
:
FMT_ASSERT
(
false
,
"invalid argument type"
);
break
;
case
internal
:
:
int_type
:
return
vis
(
arg
.
value_
.
int_value
);
case
internal
:
:
uint_type
:
return
vis
(
arg
.
value_
.
uint_value
);
case
internal
:
:
long_long_type
:
return
vis
(
arg
.
value_
.
long_long_value
);
case
internal
:
:
ulong_long_type
:
return
vis
(
arg
.
value_
.
ulong_long_value
);
case
internal
:
:
bool_type
:
return
vis
(
arg
.
value_
.
int_value
!=
0
);
case
internal
:
:
char_type
:
return
vis
(
static_cast
<
char_type
>
(
arg
.
value_
.
int_value
));
case
internal
:
:
double_type
:
return
vis
(
arg
.
value_
.
double_value
);
case
internal
:
:
long_double_type
:
return
vis
(
arg
.
value_
.
long_double_value
);
case
internal
:
:
cstring_type
:
return
vis
(
arg
.
value_
.
string
.
value
);
case
internal
:
:
string_type
:
return
vis
(
basic_string_view
<
char_type
>
(
arg
.
value_
.
string
.
value
,
arg
.
value_
.
string
.
size
));
case
internal
:
:
pointer_type
:
return
vis
(
arg
.
value_
.
pointer
);
case
internal
:
:
custom_type
:
return
vis
(
typename
basic_format_arg
<
Context
>::
handle
(
arg
.
value_
.
custom
));
}
return
vis
(
monostate
());
}
// Parsing context consisting of a format string range being parsed and an
// Parsing context consisting of a format string range being parsed and an
// argument counter for automatic indexing.
// argument counter for automatic indexing.
template
<
typename
Char
,
typename
ErrorHandler
=
internal
::
error_handler
>
template
<
typename
Char
,
typename
ErrorHandler
=
internal
::
error_handler
>
...
...
include/fmt/format.h
View file @
3f4984fb
...
@@ -1154,54 +1154,6 @@ template <typename T = void>
...
@@ -1154,54 +1154,6 @@ template <typename T = void>
struct
null
{};
struct
null
{};
}
// namespace internal
}
// namespace internal
struct
monostate
{};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template
<
typename
Visitor
,
typename
Context
>
FMT_CONSTEXPR
typename
internal
::
result_of
<
Visitor
(
int
)
>::
type
visit
(
Visitor
&&
vis
,
const
basic_format_arg
<
Context
>
&
arg
)
{
typedef
typename
Context
::
char_type
char_type
;
switch
(
arg
.
type_
)
{
case
internal
:
:
none_type
:
break
;
case
internal
:
:
named_arg_type
:
FMT_ASSERT
(
false
,
"invalid argument type"
);
break
;
case
internal
:
:
int_type
:
return
vis
(
arg
.
value_
.
int_value
);
case
internal
:
:
uint_type
:
return
vis
(
arg
.
value_
.
uint_value
);
case
internal
:
:
long_long_type
:
return
vis
(
arg
.
value_
.
long_long_value
);
case
internal
:
:
ulong_long_type
:
return
vis
(
arg
.
value_
.
ulong_long_value
);
case
internal
:
:
bool_type
:
return
vis
(
arg
.
value_
.
int_value
!=
0
);
case
internal
:
:
char_type
:
return
vis
(
static_cast
<
char_type
>
(
arg
.
value_
.
int_value
));
case
internal
:
:
double_type
:
return
vis
(
arg
.
value_
.
double_value
);
case
internal
:
:
long_double_type
:
return
vis
(
arg
.
value_
.
long_double_value
);
case
internal
:
:
cstring_type
:
return
vis
(
arg
.
value_
.
string
.
value
);
case
internal
:
:
string_type
:
return
vis
(
basic_string_view
<
char_type
>
(
arg
.
value_
.
string
.
value
,
arg
.
value_
.
string
.
size
));
case
internal
:
:
pointer_type
:
return
vis
(
arg
.
value_
.
pointer
);
case
internal
:
:
custom_type
:
return
vis
(
typename
basic_format_arg
<
Context
>::
handle
(
arg
.
value_
.
custom
));
}
return
vis
(
monostate
());
}
enum
alignment
{
enum
alignment
{
ALIGN_DEFAULT
,
ALIGN_LEFT
,
ALIGN_RIGHT
,
ALIGN_CENTER
,
ALIGN_NUMERIC
ALIGN_DEFAULT
,
ALIGN_LEFT
,
ALIGN_RIGHT
,
ALIGN_CENTER
,
ALIGN_NUMERIC
};
};
...
...
src/format.cc
View file @
3f4984fb
...
@@ -14,33 +14,40 @@ template struct internal::basic_data<void>;
...
@@ -14,33 +14,40 @@ template struct internal::basic_data<void>;
template
FMT_API
char
internal
::
thousands_sep
(
locale_provider
*
lp
);
template
FMT_API
char
internal
::
thousands_sep
(
locale_provider
*
lp
);
template
void
internal
::
basic_buffer
<
char
>
::
append
(
const
char
*
,
const
char
*
);
template
void
basic_fixed_buffer
<
char
>
::
grow
(
std
::
size_t
);
template
void
basic_fixed_buffer
<
char
>
::
grow
(
std
::
size_t
);
template
void
internal
::
arg_map
<
format_context
>
::
init
(
template
void
internal
::
arg_map
<
format_context
>
::
init
(
const
basic_format_args
<
format_context
>
&
args
);
const
basic_format_args
<
format_context
>
&
args
);
template
FMT_API
int
internal
::
char_traits
<
char
>
::
format_float
(
template
FMT_API
int
internal
::
char_traits
<
char
>
::
format_float
(
char
*
buffer
,
std
::
size_t
size
,
const
char
*
format
,
int
precision
,
char
*
,
std
::
size_t
,
const
char
*
,
int
,
double
);
double
value
);
template
FMT_API
int
internal
::
char_traits
<
char
>
::
format_float
(
template
FMT_API
int
internal
::
char_traits
<
char
>
::
format_float
(
char
*
buffer
,
std
::
size_t
size
,
const
char
*
format
,
int
precision
,
char
*
,
std
::
size_t
,
const
char
*
,
int
,
long
double
);
long
double
value
);
template
FMT_API
std
::
string
internal
::
vformat
<
char
>(
string_view
,
basic_format_args
<
format_context
>
);
// Explicit instantiations for wchar_t.
// Explicit instantiations for wchar_t.
template
FMT_API
wchar_t
internal
::
thousands_sep
(
locale_provider
*
lp
);
template
FMT_API
wchar_t
internal
::
thousands_sep
(
locale_provider
*
);
template
void
internal
::
basic_buffer
<
wchar_t
>
::
append
(
const
wchar_t
*
,
const
wchar_t
*
);
template
void
basic_fixed_buffer
<
wchar_t
>
::
grow
(
std
::
size_t
);
template
void
basic_fixed_buffer
<
wchar_t
>
::
grow
(
std
::
size_t
);
template
void
internal
::
arg_map
<
wformat_context
>
::
init
(
template
void
internal
::
arg_map
<
wformat_context
>
::
init
(
const
basic_format_args
<
wformat_context
>
&
args
);
const
basic_format_args
<
wformat_context
>
&
);
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
wchar_t
*
,
std
::
size_t
,
const
wchar_t
*
,
int
,
double
);
int
precision
,
double
value
);
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
template
FMT_API
int
internal
::
char_traits
<
wchar_t
>
::
format_float
(
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
wchar_t
*
,
std
::
size_t
,
const
wchar_t
*
,
int
,
long
double
);
int
precision
,
long
double
value
);
template
FMT_API
std
::
wstring
internal
::
vformat
<
wchar_t
>(
wstring_view
,
basic_format_args
<
wformat_context
>
);
FMT_END_NAMESPACE
FMT_END_NAMESPACE
test/CMakeLists.txt
View file @
3f4984fb
...
@@ -85,9 +85,9 @@ function(add_fmt_test name)
...
@@ -85,9 +85,9 @@ function(add_fmt_test name)
endfunction
()
endfunction
()
add_fmt_test
(
assert-test
)
add_fmt_test
(
assert-test
)
add_fmt_test
(
core-test
mock-allocator.h
)
add_fmt_test
(
core-test
)
add_fmt_test
(
gtest-extra-test
)
add_fmt_test
(
gtest-extra-test
)
add_fmt_test
(
format-test
)
add_fmt_test
(
format-test
mock-allocator.h
)
add_fmt_test
(
format-impl-test
)
add_fmt_test
(
format-impl-test
)
add_fmt_test
(
ostream-test
)
add_fmt_test
(
ostream-test
)
add_fmt_test
(
printf-test
)
add_fmt_test
(
printf-test
)
...
...
test/core-test.cc
View file @
3f4984fb
This diff is collapsed.
Click to expand it.
test/format-test.cc
View file @
3f4984fb
This diff is collapsed.
Click to expand it.
test/mock-allocator.h
View file @
3f4984fb
...
@@ -9,23 +9,24 @@
...
@@ -9,23 +9,24 @@
#define FMT_MOCK_ALLOCATOR_H_
#define FMT_MOCK_ALLOCATOR_H_
#include "gmock.h"
#include "gmock.h"
#include "fmt/format.h"
template
<
typename
T
>
template
<
typename
T
>
class
MockA
llocator
{
class
mock_a
llocator
{
public:
public:
MockA
llocator
()
{}
mock_a
llocator
()
{}
MockAllocator
(
const
MockA
llocator
&
)
{}
mock_allocator
(
const
mock_a
llocator
&
)
{}
typedef
T
value_type
;
typedef
T
value_type
;
MOCK_METHOD1_T
(
allocate
,
T
*
(
std
::
size_t
n
));
MOCK_METHOD1_T
(
allocate
,
T
*
(
std
::
size_t
n
));
MOCK_METHOD2_T
(
deallocate
,
void
(
T
*
p
,
std
::
size_t
n
));
MOCK_METHOD2_T
(
deallocate
,
void
(
T
*
p
,
std
::
size_t
n
));
};
};
template
<
typename
Allocator
>
template
<
typename
Allocator
>
class
AllocatorR
ef
{
class
allocator_r
ef
{
private:
private:
Allocator
*
alloc_
;
Allocator
*
alloc_
;
void
move
(
AllocatorR
ef
&
other
)
{
void
move
(
allocator_r
ef
&
other
)
{
alloc_
=
other
.
alloc_
;
alloc_
=
other
.
alloc_
;
other
.
alloc_
=
nullptr
;
other
.
alloc_
=
nullptr
;
}
}
...
@@ -33,18 +34,18 @@ class AllocatorRef {
...
@@ -33,18 +34,18 @@ class AllocatorRef {
public:
public:
typedef
typename
Allocator
::
value_type
value_type
;
typedef
typename
Allocator
::
value_type
value_type
;
explicit
AllocatorR
ef
(
Allocator
*
alloc
=
nullptr
)
:
alloc_
(
alloc
)
{}
explicit
allocator_r
ef
(
Allocator
*
alloc
=
nullptr
)
:
alloc_
(
alloc
)
{}
AllocatorRef
(
const
AllocatorR
ef
&
other
)
:
alloc_
(
other
.
alloc_
)
{}
allocator_ref
(
const
allocator_r
ef
&
other
)
:
alloc_
(
other
.
alloc_
)
{}
AllocatorRef
(
AllocatorR
ef
&&
other
)
{
move
(
other
);
}
allocator_ref
(
allocator_r
ef
&&
other
)
{
move
(
other
);
}
AllocatorRef
&
operator
=
(
AllocatorR
ef
&&
other
)
{
allocator_ref
&
operator
=
(
allocator_r
ef
&&
other
)
{
assert
(
this
!=
&
other
);
assert
(
this
!=
&
other
);
move
(
other
);
move
(
other
);
return
*
this
;
return
*
this
;
}
}
AllocatorRef
&
operator
=
(
const
AllocatorR
ef
&
other
)
{
allocator_ref
&
operator
=
(
const
allocator_r
ef
&
other
)
{
alloc_
=
other
.
alloc_
;
alloc_
=
other
.
alloc_
;
return
*
this
;
return
*
this
;
}
}
...
...
test/test-assert.h
View file @
3f4984fb
...
@@ -5,23 +5,22 @@
...
@@ -5,23 +5,22 @@
//
//
// For the license information refer to format.h.
// For the license information refer to format.h.
#ifndef FMT_TEST_ASSERT_H
#ifndef FMT_TEST_ASSERT_H
_
#define FMT_TEST_ASSERT_H
#define FMT_TEST_ASSERT_H
_
#include <stdexcept>
#include <stdexcept>
#include "gtest.h"
class
AssertionF
ailure
:
public
std
::
logic_error
{
class
assertion_f
ailure
:
public
std
::
logic_error
{
public:
public:
explicit
AssertionF
ailure
(
const
char
*
message
)
:
std
::
logic_error
(
message
)
{}
explicit
assertion_f
ailure
(
const
char
*
message
)
:
std
::
logic_error
(
message
)
{}
};
};
#define FMT_ASSERT(condition, message) \
#define FMT_ASSERT(condition, message) \
if (!(condition)) throw AssertionFailure(message);
if (!(condition)) throw assertion_failure(message);
#include "gtest-extra.h"
// Expects an assertion failure.
// Expects an assertion failure.
#define EXPECT_ASSERT(stmt, message) \
#define EXPECT_ASSERT(stmt, message) \
EXPECT_THROW_MSG(stmt, AssertionFailure, message
)
FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_
)
#endif // FMT_TEST_ASSERT_H
#endif // FMT_TEST_ASSERT_H
_
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