Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,21 @@ and argument deduction remain unchanged: a const integer lvalue can deduce the
unqualified type through `const T&`, while explicitly checking a const-qualified
trait remains false. Constant types and values, including UID bit allocation and
network timeouts, remain unchanged.

## Standard utility migration

**Breaking source change:** `ARK_TO_STRING`, `ARRAY_LENTGH`, `ARK_SRATIC_ASSERT`,
`ARRAY_CLEAR`, `MEMORY_CLEAR` and `MEMORY_CLEAR_POINTER` are no longer defined.

| Removed name | Migration |
| --- | --- |
| `ARK_TO_STRING(value)` | Include `<string>` and call `std::to_string(value)`. This is the same standard function previously used by the alias, including its C++20 floating-point formatting. |
| `ARRAY_LENTGH(array)` | Include `<iterator>` and use `std::size(array)` for bounded arrays. If code needs a type's first array extent, include `<type_traits>` and use `std::extent_v<T>`; `std::size` does not accept a raw pointer. |
| `ARK_SRATIC_ASSERT` | Write `static_assert` directly. |
| `ARRAY_CLEAR`, `MEMORY_CLEAR`, `MEMORY_CLEAR_POINTER` | These unused helpers are removed without a replacement alias. Choose value initialization, typed assignment or an explicit byte operation according to the object's storage contract; there is no universal safe object-clearing operation. `MEMORY_CLEAR_POINTER` also contained the invalid token `0xx`. |

The existing data and endpoint conversions still call `std::to_string` with the
same argument types. Numeric output and precision remain unchanged. Array-count
call sites keep their existing `int` variables, lookup order, enum mappings and
range handling. Remaining allocation, ownership, runtime-assertion, platform,
plugin-registration and byte-order macros retain their existing behavior.
16 changes: 16 additions & 0 deletions docs/code-style_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ clang-tidy 应与 CMake 配置使用同一套编译器工具链,以正确找
`check_buildin_type` 的签名、异常契约、参数推导保持不变:const 整数左值可通过
`const T&` 推导出未限定的类型,但显式检查 const 限定的 trait 仍返回 false。
常量类型和值保持不变,包括 UID 位分配和网络超时。

## 标准工具迁移

**源码不兼容变更:** 不再定义 `ARK_TO_STRING`、`ARRAY_LENTGH`、
`ARK_SRATIC_ASSERT`、`ARRAY_CLEAR`、`MEMORY_CLEAR` 和 `MEMORY_CLEAR_POINTER`。

| 移除的名称 | 迁移方式 |
| --- | --- |
| `ARK_TO_STRING(value)` | 包含 `<string>`,调用 `std::to_string(value)`。它与原别名调用的标准函数相同,包括 C++20 的浮点格式化行为。 |
| `ARRAY_LENTGH(array)` | 对有界数组,包含 `<iterator>` 并使用 `std::size(array)`。若需要查询类型的首维数组长度,包含 `<type_traits>` 并使用 `std::extent_v<T>`;`std::size` 不接受裸指针。 |
| `ARK_SRATIC_ASSERT` | 直接使用 `static_assert`。 |
| `ARRAY_CLEAR`、`MEMORY_CLEAR`、`MEMORY_CLEAR_POINTER` | 移除未使用的工具,不提供替代别名。根据对象的存储契约选择值初始化、类型明确的赋值或显式字节操作;不存在对所有对象都安全的清零操作。`MEMORY_CLEAR_POINTER` 还包含非法 token `0xx`。 |

现有数据和端点转换仍以相同的参数类型调用 `std::to_string`,数值输出和精度不变。
数组长度调用点保留原有的 `int` 变量、查找顺序、枚举映射和范围处理。
其余分配、所有权、运行时断言、平台、插件注册和字节序宏保持原有行为。
16 changes: 9 additions & 7 deletions include/ark/kernel/data_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#pragma once

#include <string>

#include "ark/core_def.hpp"
#include "ark/kernel/data.hpp"
#include "ark/misc.hpp"
Expand Down Expand Up @@ -546,25 +548,25 @@ class data_base final : public data
switch (get_type())
{
case data_type::dt_boolean:
return ARK_TO_STRING(this->bool_value_);
return std::to_string(this->bool_value_);
break;
case data_type::dt_int32:
return ARK_TO_STRING(this->int_value_);
return std::to_string(this->int_value_);
break;
case data_type::dt_int64:
return ARK_TO_STRING(this->int64_value_);
return std::to_string(this->int64_value_);
break;
case data_type::dt_uint32:
return ARK_TO_STRING(this->uint32_value_);
return std::to_string(this->uint32_value_);
break;
case data_type::dt_uint64:
return ARK_TO_STRING(this->uint64_value_);
return std::to_string(this->uint64_value_);
break;
case data_type::dt_float:
return ARK_TO_STRING(this->float_value_);
return std::to_string(this->float_value_);
break;
case data_type::dt_double:
return ARK_TO_STRING(this->double_value_);
return std::to_string(this->double_value_);
break;
case data_type::dt_string:
return this->string_value_;
Expand Down
16 changes: 9 additions & 7 deletions include/ark/kernel/data_list_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#pragma once

#include <string>

#include "ark/kernel/data.hpp"
#include "ark/kernel/data_list.hpp"
#include "ark/misc.hpp"
Expand Down Expand Up @@ -739,25 +741,25 @@ class base_data_list final : public data_list
switch (data_[index].type)
{
case data_type::dt_boolean:
data = ARK_TO_STRING(data_[index].bool_value);
data = std::to_string(data_[index].bool_value);
break;
case data_type::dt_int32:
data = ARK_TO_STRING(data_[index].int_value);
data = std::to_string(data_[index].int_value);
break;
case data_type::dt_int64:
data = ARK_TO_STRING(data_[index].int64_value);
data = std::to_string(data_[index].int64_value);
break;
case data_type::dt_uint32:
data = ARK_TO_STRING(data_[index].uint32_value);
data = std::to_string(data_[index].uint32_value);
break;
case data_type::dt_uint64:
data = ARK_TO_STRING(data_[index].uint64_value);
data = std::to_string(data_[index].uint64_value);
break;
case data_type::dt_float:
data = ARK_TO_STRING(data_[index].float_value);
data = std::to_string(data_[index].float_value);
break;
case data_type::dt_double:
data = ARK_TO_STRING(data_[index].double_value);
data = std::to_string(data_[index].double_value);
break;
case data_type::dt_string:
data = string(index);
Expand Down
8 changes: 0 additions & 8 deletions include/ark/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
#define INOUT
#endif

#define ARRAY_CLEAR(v) memset((v), 0x0, sizeof((v)))
#define MEMORY_CLEAR(v) memset(&(v), 0x0, sizeof((v)))
#define MEMORY_CLEAR_POINTER(v) memset((v), 0xx, sizeof(*(v)))
#define ARRAY_LENTGH(v) std::extent<decltype(v)>::value

#define MAX_NAME 256
#define MAX_BUF 256

Expand Down Expand Up @@ -326,8 +321,6 @@ typedef struct HINSTANCE__* library_instance;
} while (false);
#endif

#define ARK_TO_STRING(value) std::to_string(value)

/// math: is zero
#define IS_FLOAT_ZERO(type, value) (std::abs(value) < std::numeric_limits<type>::epsilon())

Expand All @@ -337,7 +330,6 @@ typedef struct HINSTANCE__* library_instance;
#define ARK_FORMAT_FUNCTION(my_fmt, ...) \
fmt::format(fmt::runtime(std::string("[{}:{}]") + (my_fmt)), ARK_FUNCTION_LINE, ##__VA_ARGS__);

#define ARK_SRATIC_ASSERT static_assert
#define GET_CLASS_NAME(class_name) (typeid(class_name).name())
//////////////////////////////////////////////////////////////////////////
// Plugin macros
Expand Down
4 changes: 3 additions & 1 deletion include/ark/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#pragma once

#include <iterator>

#include "ark/bus.hpp"
#include "ark/enum.hpp"
#include "ark/macros.hpp"
Expand Down Expand Up @@ -110,7 +112,7 @@ class misc
// If there are more types, please add type name in here.
};

static int data_type_len = ARRAY_LENTGH(data_type_names);
static int data_type_len = std::size(data_type_names);
for (int i = 0; i < data_type_len; ++i)
{
if (type_name == data_type_names[i])
Expand Down
11 changes: 7 additions & 4 deletions include/ark/socket_func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#pragma once

#include <iterator>
#include <string>

#include "ark/dep.hpp"
#include "ark/error.hpp"
#include "ark/macros.hpp"
Expand Down Expand Up @@ -63,7 +66,7 @@ class endpoint final
{
public:
static std::string make_url(const std::string& protocol, const std::string& hostname, const uint16_t& port) {
std::string domain = protocol + "://" + hostname + ":" + ARK_TO_STRING(port);
std::string domain = protocol + "://" + hostname + ":" + std::to_string(port);
return domain;
}

Expand All @@ -79,7 +82,7 @@ class endpoint final
"zk",
};

static int n = ARRAY_LENTGH(proto_type_s);
static int n = std::size(proto_type_s);
for (int i = 0; i < n; ++i)
{
if (ARK_STRICMP(s.c_str(), proto_type_s[i]) == 0)
Expand All @@ -103,7 +106,7 @@ class endpoint final
"zk",
};

static int n = ARRAY_LENTGH(proto_type_s);
static int n = std::size(proto_type_s);
if ((int)proto >= n)
{
return proto_type_s[0];
Expand Down Expand Up @@ -185,7 +188,7 @@ class endpoint final
url += socket::proto2str(proto()) + "://";
}

url += get_ip() + ":" + ARK_TO_STRING(get_port()) + get_path();
url += get_ip() + ":" + std::to_string(get_port()) + get_path();
return url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/net/net_service_manager_module_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ std::shared_ptr<net_client_service> net_service_manager_module_impl::get_client_
// auto check = service.mutable_check();
// check->set_id(app_whole_name + "_check");
// check->set_name(app_whole_name);
// check->set_tcp(self_proc.intranet_ep.GetIP() + ":" + ARK_TO_STRING(self_proc.intranet_ep.GetPort()));
// check->set_tcp(self_proc.intranet_ep.GetIP() + ":" + std::to_string(self_proc.intranet_ep.GetPort()));
// check->set_interval(reg_center.check_interval);
// check->set_timeout(reg_center.check_timeout);
//
Expand Down
Loading