Skip to content

Commit 9c21805

Browse files
committed
Improve tlx
1 parent b343ff9 commit 9c21805

File tree

89 files changed

+861
-2214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+861
-2214
lines changed

3rdparty/yasio/yasio/array_buffer.hpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

3rdparty/yasio/yasio/bindings/lyasio.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum
3939
};
4040

4141
template <typename _Stream>
42-
static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_field_bits)
42+
static void obstream_write_v(_Stream* obs, std::string_view val, int length_field_bits)
4343
{
4444
// default: Use variant length of length field, just like .net BinaryWriter.Write(String),
4545
// see:
@@ -58,7 +58,7 @@ static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_fi
5858
}
5959
};
6060
template <typename _Stream>
61-
static cxx17::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
61+
static std::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
6262
{
6363
// default: Use variant length of length field, just like .net BinaryReader.ReadString,
6464
// see:
@@ -113,21 +113,21 @@ static void register_obstream(sol::table& lib, const char* usertype)
113113
"write_f16", &_Stream::template write<fp16_t>,
114114
# endif
115115
"write_f", &_Stream::template write<float>, "write_lf", &_Stream::template write<double>, "write_v",
116-
[](_Stream* obs, cxx17::string_view sv, sol::variadic_args args) {
116+
[](_Stream* obs, std::string_view sv, sol::variadic_args args) {
117117
int lfl = -1;
118118
if (args.size() > 0)
119119
lfl = static_cast<int>(args[0]);
120120
return obstream_write_v<_Stream>(obs, sv, lfl);
121121
},
122-
"write_bytes", static_cast<void (_Stream::*)(cxx17::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
123-
[](_Stream* obs) { return cxx17::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
122+
"write_bytes", static_cast<void (_Stream::*)(std::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
123+
[](_Stream* obs) { return std::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
124124
}
125125

126126
template <typename _Stream, typename _StreamView, typename _OStream>
127127
static void register_ibstream(sol::table& lib, const char* usertype)
128128
{
129129
lib.new_usertype<_Stream>(
130-
usertype, sol::constructors<_Stream(), _Stream(yasio::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
130+
usertype, sol::constructors<_Stream(), _Stream(tlx::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
131131
&_Stream::template read_ix<int64_t>, "read_bool", &_Stream::template read<bool>, "read_i8", &_Stream::template read<int8_t>, "read_i16",
132132
&_Stream::template read<int16_t>, "read_i32", &_Stream::template read<int32_t>, "read_i64", &_Stream::template read<int64_t>, "read_u8",
133133
&_Stream::template read<uint8_t>, "read_u16", &_Stream::template read<uint16_t>, "read_u32", &_Stream::template read<uint32_t>, "read_u64",
@@ -142,8 +142,8 @@ static void register_ibstream(sol::table& lib, const char* usertype)
142142
lfl = static_cast<int>(args[0]);
143143
return ibstream_read_v<_Stream>(ibs, lfl);
144144
},
145-
"read_bytes", static_cast<cxx17::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
146-
"to_string", [](_Stream* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); });
145+
"read_bytes", static_cast<std::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
146+
"to_string", [](_Stream* ibs) { return std::string_view(ibs->data(), ibs->length()); });
147147
}
148148
} // namespace lyasio
149149

@@ -170,11 +170,11 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
170170
switch (buffer_type)
171171
{
172172
case lyasio::BUFFER_RAW:
173-
return sol::make_object(L, cxx17::string_view{packet_data(pkt), packet_len(pkt)});
173+
return sol::make_object(L, std::string_view{packet_data(pkt), packet_len(pkt)});
174174
case lyasio::BUFFER_FAST:
175-
return sol::make_object(L, cxx14::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
175+
return sol::make_object(L, std::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
176176
default:
177-
return sol::make_object(L, cxx14::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
177+
return sol::make_object(L, std::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
178178
}
179179
},
180180
"cindex", &io_event::cindex, "transport", &io_event::transport
@@ -192,13 +192,13 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
192192
std::vector<io_hostent> hosts;
193193
auto host = channel_eps["host"];
194194
if (host.valid())
195-
hosts.push_back(io_hostent(host.get<cxx17::string_view>(), channel_eps["port"]));
195+
hosts.push_back(io_hostent(host.get<std::string_view>(), channel_eps["port"]));
196196
else
197197
{
198198
for (auto item : channel_eps)
199199
{
200200
auto ep = item.second.as<sol::table>();
201-
hosts.push_back(io_hostent(ep["host"].get<cxx17::string_view>(), ep["port"]));
201+
hosts.push_back(io_hostent(ep["host"].get<std::string_view>(), ep["port"]));
202202
}
203203
}
204204
return new (&uninitialized_memory)
@@ -258,16 +258,16 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
258258
sol::overload(static_cast<void (io_service::*)(transport_handle_t)>(&io_service::close), static_cast<void (io_service::*)(int)>(&io_service::close)),
259259
"write",
260260
sol::overload(
261-
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
262-
return service->write(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()});
261+
[](io_service* service, transport_handle_t transport, std::string_view s) {
262+
return service->write(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()});
263263
},
264264
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); }),
265265
"write_to",
266266
sol::overload(
267-
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
268-
return service->write_to(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
267+
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
268+
return service->write_to(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
269269
},
270-
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
270+
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
271271
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
272272
}),
273273
"native_ptr", [](io_service* service) { return (void*)service; });
@@ -280,8 +280,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
280280
lyasio::register_ibstream<ibstream, ibstream_view, obstream>(yasio_lib, "ibstream");
281281
lyasio::register_ibstream<fast_ibstream, fast_ibstream_view, fast_obstream>(yasio_lib, "fast_ibstream");
282282

283-
yasio_lib["highp_clock"] = &highp_clock<yasio::steady_clock_t>;
284-
yasio_lib["highp_time"] = &highp_clock<yasio::system_clock_t>;
283+
yasio_lib["highp_clock"] = &tlx::highp_clock<tlx::steady_clock_t>;
284+
yasio_lib["highp_time"] = &tlx::highp_clock<tlx::system_clock_t>;
285285

286286
yasio_lib["unwrap_ptr"] = [](lua_State* L) -> int {
287287
auto& pkt = *(packet_t*)lua_touserdata(L, 1);
@@ -371,19 +371,19 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
371371
/// customize the type conversion from/to lua
372372
namespace kaguya
373373
{
374-
// cxx17::string_view
374+
// std::string_view
375375
template <>
376-
struct lua_type_traits<cxx17::string_view> {
377-
typedef cxx17::string_view get_type;
378-
typedef cxx17::string_view push_type;
376+
struct lua_type_traits<std::string_view> {
377+
typedef std::string_view get_type;
378+
typedef std::string_view push_type;
379379

380380
static bool strictCheckType(lua_State* l, int index) { return lua_type(l, index) == LUA_TSTRING; }
381381
static bool checkType(lua_State* l, int index) { return lua_isstring(l, index) != 0; }
382382
static get_type get(lua_State* l, int index)
383383
{
384384
size_t size = 0;
385385
const char* buffer = lua_tolstring(l, index, &size);
386-
return cxx17::string_view(buffer, size);
386+
return std::string_view(buffer, size);
387387
}
388388
static int push(lua_State* l, push_type s)
389389
{
@@ -527,15 +527,15 @@ static void register_obstream(kaguya::LuaTable& lib, const char* usertype, const
527527
.addFunction("write_f", &_BaseStream::template write<float>)
528528
.addFunction("write_lf", &_BaseStream::template write<double>)
529529
.addStaticFunction("write_v",
530-
[](_BaseStream* obs, cxx17::string_view sv, kaguya::VariadicArgType args) {
530+
[](_BaseStream* obs, std::string_view sv, kaguya::VariadicArgType args) {
531531
int lfl = -1;
532532
if (args.size() > 0)
533533
lfl = static_cast<int>(args[0]);
534534
return lyasio::obstream_write_v(obs, sv, lfl);
535535
})
536-
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(cxx17::string_view)>(&_BaseStream::write_bytes))
536+
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(std::string_view)>(&_BaseStream::write_bytes))
537537
.addFunction("length", &_BaseStream::length)
538-
.addStaticFunction("to_string", [](_BaseStream* obs) { return cxx17::string_view(obs->data(), obs->length()); }));
538+
.addStaticFunction("to_string", [](_BaseStream* obs) { return std::string_view(obs->data(), obs->length()); }));
539539
// ##-- obstream
540540
lib[usertype].setClass(userclass);
541541
}
@@ -565,10 +565,10 @@ static void register_ibstream(kaguya::LuaTable& lib, const char* usertype, const
565565
length_field_bits = static_cast<int>(args[0]);
566566
return lyasio::ibstream_read_v(ibs, length_field_bits);
567567
})
568-
.addFunction("read_bytes", static_cast<cxx17::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
568+
.addFunction("read_bytes", static_cast<std::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
569569
.addFunction("seek", &_StreamView::seek)
570570
.addFunction("length", &_StreamView::length)
571-
.addStaticFunction("to_string", [](_StreamView* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); }));
571+
.addStaticFunction("to_string", [](_StreamView* ibs) { return std::string_view(ibs->data(), ibs->length()); }));
572572

573573
// ##-- ibstream
574574
lib[usertype].setClass(userclass);
@@ -602,8 +602,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
602602
[](io_event* ev) {
603603
auto& pkt = ev->packet();
604604
if (is_packet_empty(pkt))
605-
return cxx17::string_view{""};
606-
return cxx17::string_view{packet_data(pkt), packet_len(pkt)};
605+
return std::string_view{""};
606+
return std::string_view{packet_data(pkt), packet_len(pkt)};
607607
})
608608
.addStaticFunction("fast_packet",
609609
[](io_event* ev) {
@@ -652,16 +652,16 @@ end
652652
static_cast<void (io_service::*)(int)>(&io_service::close))
653653
.addOverloadedFunctions(
654654
"write",
655-
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
655+
[](io_service* service, transport_handle_t transport, std::string_view s) {
656656
return service->write(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()));
657657
},
658658
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); })
659659
.addOverloadedFunctions(
660660
"write_to",
661-
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
661+
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
662662
return service->write_to(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()), ip::endpoint{ip.data(), port});
663663
},
664-
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
664+
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
665665
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
666666
})
667667
.addStaticFunction("set_option",

3rdparty/yasio/yasio/bindings/yasio_axlua.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ SOFTWARE.
3030
#include "yasio/bindings/yasio_axlua.hpp"
3131
#include "yasio/bindings/lyasio.hpp"
3232
#include "yasio/object_pool.hpp"
33-
#include "yasio/ref_ptr.hpp"
34-
#include "yasio/string_view.hpp"
3533

3634
// A workaround to fix compile issue caused by `CCPlatformMacros.h` doesn't handle `__has_attribute` it properly
3735
# if !__has_attribute(format)
@@ -40,6 +38,7 @@ SOFTWARE.
4038

4139
#include "axmol/base/Director.h"
4240
#include "axmol/base/Scheduler.h"
41+
#include "axmol/tlx/memory.hpp"
4342

4443
using namespace ax;
4544

@@ -63,15 +62,23 @@ struct TimerObject
6362
static uintptr_t s_timerId;
6463

6564
DEFINE_FAST_OBJECT_POOL_ALLOCATION(TimerObject, 128)
66-
YASIO__DEFINE_REFERENCE_CLASS
65+
66+
void retain() { ++_referenceCount; }
67+
void release()
68+
{
69+
if (--_referenceCount == 0)
70+
delete this;
71+
}
72+
73+
uint32_t _referenceCount{1};
6774
};
6875
uintptr_t TimerObject::s_timerId = 0;
6976

7077
static TIMER_ID loop(unsigned int n, float interval, vcallback_t callback)
7178
{
7279
if (n > 0 && interval >= 0)
7380
{
74-
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
81+
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);
7582

7683
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);
7784

@@ -93,7 +100,7 @@ static TIMER_ID delay(float delay, vcallback_t callback)
93100
{
94101
if (delay > 0)
95102
{
96-
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
103+
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);
97104
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);
98105

99106
std::string key = fmt::format("LSTMR#{}", fmt::ptr(timerId));

3rdparty/yasio/yasio/bindings/yasio_sol.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ SOFTWARE.
3131
# include "sol2/sol.hpp" // sol2-2.x
3232
#endif
3333

34-
// use cxx17::string_view workaround with std::string_view
34+
// use std::string_view workaround with std::string_view
3535
#if !YASIO__HAS_CXX17
3636
namespace sol
3737
{
3838
namespace stack
3939
{
4040
template <>
41-
struct pusher<cxx17::string_view> {
42-
static int push(lua_State* L, const cxx17::string_view& str)
41+
struct pusher<std::string_view> {
42+
static int push(lua_State* L, const std::string_view& str)
4343
{
4444
lua_pushlstring(L, !str.empty() ? str.c_str() : "", str.length());
4545
return 1;
4646
}
4747
};
4848
template <>
49-
struct getter<cxx17::string_view> {
50-
static cxx17::string_view get(lua_State* L, int index, record& tracking)
49+
struct getter<std::string_view> {
50+
static std::string_view get(lua_State* L, int index, record& tracking)
5151
{
5252
tracking.use(1); // THIS IS THE ONLY BIT THAT CHANGES
5353
size_t len = 0;
5454
const char* s = lua_tolstring(L, index, &len);
55-
return cxx17::string_view(s, len);
55+
return std::string_view(s, len);
5656
}
5757
};
5858
} // namespace stack
5959
template <>
60-
struct lua_type_of<cxx17::string_view> : std::integral_constant<type, type::string> {};
60+
struct lua_type_of<std::string_view> : std::integral_constant<type, type::string> {};
6161
} // namespace sol
6262
#endif
6363

3rdparty/yasio/yasio/compiler/feature_test.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,7 @@ SOFTWARE.
259259

260260
#define YASIO__STD ::std::
261261

262-
#if YASIO__HAS_CXX14
263-
namespace cxx14
264-
{
265-
using namespace std;
266-
};
267-
#endif
268-
269-
#if YASIO__HAS_CXX17
270-
namespace cxx17
271-
{
272-
using namespace std;
273-
};
274-
#endif
262+
// The yasio is the original tlx provider
263+
#define _TLX ::tlx::
275264

276265
#endif

0 commit comments

Comments
 (0)