This is an automated email from the ASF dual-hosted git repository.
laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new ba723a991 feat: overload stream insertion operator(<<) to support
formatting by {fmt} (#1225)
ba723a991 is described below
commit ba723a9914b2c66cdd303ec47bc8806e92fc63f4
Author: Dan Wang <[email protected]>
AuthorDate: Mon Nov 7 21:08:21 2022 +0800
feat: overload stream insertion operator(<<) to support formatting by {fmt}
(#1225)
---
.gitignore | 1 -
src/common/gpid.h | 5 +++--
src/runtime/rpc/asio_net_provider.cpp | 2 +-
src/runtime/rpc/network.sim.cpp | 2 +-
src/runtime/task/task_code.h | 4 +++-
src/utils/customizable_id.h | 5 +++++
src/utils/error_code.h | 4 +++-
src/utils/threadpool_code.h | 7 +++++++
8 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index 3fbead679..26cf95f1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@ src/base/rrdb_types.cpp
src/include/rrdb/rrdb_types.h
src/common/serialization_helper/dsn.layer2_types.h
src/runtime/dsn.layer2_types.cpp
-src/runtime
src/*builder
onebox/
diff --git a/src/common/gpid.h b/src/common/gpid.h
index eb4d0dcfc..1792df310 100644
--- a/src/common/gpid.h
+++ b/src/common/gpid.h
@@ -26,6 +26,7 @@
#pragma once
#include <cstdint>
+#include <ostream>
#include <thrift/protocol/TProtocol.h>
namespace dsn {
@@ -71,9 +72,9 @@ public:
int thread_hash() const { return _value.u.app_id * 7919 +
_value.u.partition_index; }
- friend std::ostream &operator<<(std::ostream &os, gpid id)
+ friend std::ostream &operator<<(std::ostream &os, const gpid &id)
{
- return os << std::string(id.to_string());
+ return os << id.to_string();
}
private:
diff --git a/src/runtime/rpc/asio_net_provider.cpp
b/src/runtime/rpc/asio_net_provider.cpp
index b76c05876..af26fe5fa 100644
--- a/src/runtime/rpc/asio_net_provider.cpp
+++ b/src/runtime/rpc/asio_net_provider.cpp
@@ -96,7 +96,7 @@ error_code asio_network_provider::start(rpc_channel channel,
int port, bool clie
CHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP,
"invalid given channel {}",
- channel.to_string());
+ channel);
_address.assign_ipv4(get_local_ipv4(), port);
diff --git a/src/runtime/rpc/network.sim.cpp b/src/runtime/rpc/network.sim.cpp
index fc10b76ea..37139c9f3 100644
--- a/src/runtime/rpc/network.sim.cpp
+++ b/src/runtime/rpc/network.sim.cpp
@@ -174,7 +174,7 @@ error_code sim_network_provider::start(rpc_channel channel,
int port, bool clien
{
CHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP,
"invalid given channel {}",
- channel.to_string());
+ channel);
_address = ::dsn::rpc_address("localhost", port);
auto hostname = boost::asio::ip::host_name();
diff --git a/src/runtime/task/task_code.h b/src/runtime/task/task_code.h
index 8695fa99a..3609171d5 100644
--- a/src/runtime/task/task_code.h
+++ b/src/runtime/task/task_code.h
@@ -26,6 +26,8 @@
#pragma once
+#include <ostream>
+
#include "utils/ports.h"
#include "utils/enum_helper.h"
#include "utils/threadpool_code.h"
@@ -123,7 +125,7 @@ public:
friend std::ostream &operator<<(std::ostream &os, const task_code &tc)
{
- return os << std::string(tc.to_string());
+ return os << tc.to_string();
}
private:
diff --git a/src/utils/customizable_id.h b/src/utils/customizable_id.h
index 6ce09428d..629caebab 100644
--- a/src/utils/customizable_id.h
+++ b/src/utils/customizable_id.h
@@ -81,6 +81,11 @@ struct customized_id
static bool is_exist(const char *name);
static customized_id from_string(const char *name, customized_id
invalid_value);
+ friend std::ostream &operator<<(std::ostream &os, const customized_id &id)
+ {
+ return os << id.to_string();
+ }
+
protected:
static int assign(const char *xxx);
customized_id(int code);
diff --git a/src/utils/error_code.h b/src/utils/error_code.h
index 94256afeb..e2aafffd2 100644
--- a/src/utils/error_code.h
+++ b/src/utils/error_code.h
@@ -26,6 +26,8 @@
#pragma once
+#include <ostream>
+
#include "customizable_id.h"
#include <thrift/protocol/TProtocol.h>
@@ -59,7 +61,7 @@ public:
friend std::ostream &operator<<(std::ostream &os, const error_code &ec)
{
- return os << std::string(ec.to_string());
+ return os << ec.to_string();
}
private:
diff --git a/src/utils/threadpool_code.h b/src/utils/threadpool_code.h
index 5abf4747c..2ff31d739 100644
--- a/src/utils/threadpool_code.h
+++ b/src/utils/threadpool_code.h
@@ -26,6 +26,8 @@
#pragma once
+#include <ostream>
+
#include "ports.h"
namespace dsn {
@@ -49,6 +51,11 @@ public:
static int max();
static bool is_exist(const char *name);
+ friend std::ostream &operator<<(std::ostream &os, const threadpool_code
&pool_code)
+ {
+ return os << pool_code.to_string();
+ }
+
private:
int _internal_code;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]