Skip to content

Commit

Permalink
feat: overload stream insertion operator(<<) to support formatting by…
Browse files Browse the repository at this point in the history
… {fmt} (#1225)
  • Loading branch information
empiredan authored Nov 7, 2022
1 parent e2a0088 commit ba723a9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
5 changes: 3 additions & 2 deletions src/common/gpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include <cstdint>
#include <ostream>
#include <thrift/protocol/TProtocol.h>

namespace dsn {
Expand Down Expand Up @@ -71,9 +72,9 @@ class gpid

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:
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/rpc/asio_net_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/rpc/network.sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/task/task_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#pragma once

#include <ostream>

#include "utils/ports.h"
#include "utils/enum_helper.h"
#include "utils/threadpool_code.h"
Expand Down Expand Up @@ -123,7 +125,7 @@ class task_code

friend std::ostream &operator<<(std::ostream &os, const task_code &tc)
{
return os << std::string(tc.to_string());
return os << tc.to_string();
}

private:
Expand Down
5 changes: 5 additions & 0 deletions src/utils/customizable_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/utils/error_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#pragma once

#include <ostream>

#include "customizable_id.h"
#include <thrift/protocol/TProtocol.h>

Expand Down Expand Up @@ -59,7 +61,7 @@ class error_code

friend std::ostream &operator<<(std::ostream &os, const error_code &ec)
{
return os << std::string(ec.to_string());
return os << ec.to_string();
}

private:
Expand Down
7 changes: 7 additions & 0 deletions src/utils/threadpool_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#pragma once

#include <ostream>

#include "ports.h"

namespace dsn {
Expand All @@ -49,6 +51,11 @@ class threadpool_code
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;
};
Expand Down

0 comments on commit ba723a9

Please sign in to comment.