diff options
author | Yifan Hong <elsk@google.com> | 2017-04-03 11:33:22 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2017-04-03 15:04:51 -0700 |
commit | 6b7f0700d3771e552964cf24ab9887275c310c4b (patch) | |
tree | fa1b6e3a56df55cfbe2d44900c053bfff3fdc5cc /utils | |
parent | 932464e77e181a98a55e65c046db7a63372b39f6 (diff) | |
download | hidl-6b7f0700d3771e552964cf24ab9887275c310c4b.tar.gz |
Add Formatter::operator<< for integer types / char
It only had operator<< for size_t, but VTS is using implicit
conversions to size_t. Explicit declare these types.
operator<<(char) now actaully output the char. So
operator<<(int8_t) operator<<(uint8_t) would not work as
expected. Checked VTS code to make sure this doesn't happen.
Test: make vts
Test: make
Change-Id: I5cf30bbeecdfdb441985eeb458c4eb5806fa29df
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Android.bp | 2 | ||||
-rw-r--r-- | utils/Formatter.cpp | 32 | ||||
-rw-r--r-- | utils/include/hidl-util/Formatter.h | 17 |
3 files changed, 46 insertions, 5 deletions
diff --git a/utils/Android.bp b/utils/Android.bp index e4f718a2..b3913ee9 100644 --- a/utils/Android.bp +++ b/utils/Android.bp @@ -17,9 +17,9 @@ cc_library_shared { host_supported: true, cflags: hidl_flags, srcs: [ + "FQName.cpp", "Formatter.cpp", "StringHelper.cpp", - "FQName.cpp" ], shared_libs: [ "libbase", diff --git a/utils/Formatter.cpp b/utils/Formatter.cpp index 503d1459..a4f20473 100644 --- a/utils/Formatter.cpp +++ b/utils/Formatter.cpp @@ -148,9 +148,35 @@ Formatter &Formatter::operator<<(const std::string &out) { return *this; } -Formatter &Formatter::operator<<(size_t n) { - return (*this) << std::to_string(n); -} +#define FORMATTER_INPUT_INTEGER(__type__) \ + Formatter &Formatter::operator<<(__type__ n) { \ + return (*this) << std::to_string(n); \ + } \ + +FORMATTER_INPUT_INTEGER(short); +FORMATTER_INPUT_INTEGER(unsigned short); +FORMATTER_INPUT_INTEGER(int); +FORMATTER_INPUT_INTEGER(unsigned int); +FORMATTER_INPUT_INTEGER(long); +FORMATTER_INPUT_INTEGER(unsigned long); +FORMATTER_INPUT_INTEGER(long long); +FORMATTER_INPUT_INTEGER(unsigned long long); +FORMATTER_INPUT_INTEGER(float); +FORMATTER_INPUT_INTEGER(double); +FORMATTER_INPUT_INTEGER(long double); + +#undef FORMATTER_INPUT_INTEGER + +#define FORMATTER_INPUT_CHAR(__type__) \ + Formatter &Formatter::operator<<(__type__ c) { \ + return (*this) << std::string(1, (char)c); \ + } \ + +FORMATTER_INPUT_CHAR(char); +FORMATTER_INPUT_CHAR(signed char); +FORMATTER_INPUT_CHAR(unsigned char); + +#undef FORMATTER_INPUT_CHAR void Formatter::setNamespace(const std::string &space) { mSpace = space; diff --git a/utils/include/hidl-util/Formatter.h b/utils/include/hidl-util/Formatter.h index d897c1df..513efad1 100644 --- a/utils/include/hidl-util/Formatter.h +++ b/utils/include/hidl-util/Formatter.h @@ -109,7 +109,22 @@ struct Formatter { std::function<void(const typename std::iterator_traits<I>::value_type &)> func); Formatter &operator<<(const std::string &out); - Formatter &operator<<(size_t n); + + Formatter &operator<<(char c); + Formatter &operator<<(signed char c); + Formatter &operator<<(unsigned char c); + + Formatter &operator<<(short c); + Formatter &operator<<(unsigned short c); + Formatter &operator<<(int c); + Formatter &operator<<(unsigned int c); + Formatter &operator<<(long c); + Formatter &operator<<(unsigned long c); + Formatter &operator<<(long long c); + Formatter &operator<<(unsigned long long c); + Formatter &operator<<(float c); + Formatter &operator<<(double c); + Formatter &operator<<(long double c); // Any substrings matching "space" will be stripped out of the output. void setNamespace(const std::string &space); |