Move TlDowncastHelper to tdutils.
This commit is contained in:
parent
964a3e1d08
commit
47d3806c62
@ -17,6 +17,7 @@
|
||||
#include "td/utils/SliceBuilder.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/tl_storers.h"
|
||||
#include "td/utils/TlDowncastHelper.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
@ -149,21 +150,6 @@ Status from_json(std::vector<T> &to, JsonValue from) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class DowncastHelper final : public T {
|
||||
public:
|
||||
explicit DowncastHelper(int32 constructor) : constructor_(constructor) {
|
||||
}
|
||||
int32 get_id() const final {
|
||||
return constructor_;
|
||||
}
|
||||
void store(TlStorerToString &s, const char *field_name) const final {
|
||||
}
|
||||
|
||||
private:
|
||||
int32 constructor_{0};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
std::enable_if_t<!std::is_constructible<T>::value, Status> from_json(tl_object_ptr<T> &to, JsonValue from) {
|
||||
if (from.type() != JsonValue::Type::Object) {
|
||||
@ -185,7 +171,7 @@ std::enable_if_t<!std::is_constructible<T>::value, Status> from_json(tl_object_p
|
||||
return Status::Error(PSLICE() << "Expected String or Integer, got " << constructor_value.type());
|
||||
}
|
||||
|
||||
DowncastHelper<T> helper(constructor);
|
||||
TlDowncastHelper<T> helper(constructor);
|
||||
Status status;
|
||||
bool ok = downcast_call(static_cast<T &>(helper), [&](auto &dummy) {
|
||||
auto result = make_tl_object<std::decay_t<decltype(dummy)>>();
|
||||
|
@ -256,10 +256,10 @@ set(TDUTILS_SOURCE
|
||||
td/utils/Time.h
|
||||
td/utils/TimedStat.h
|
||||
td/utils/Timer.h
|
||||
td/utils/TsFileLog.h
|
||||
td/utils/tl_helpers.h
|
||||
td/utils/tl_parsers.h
|
||||
td/utils/tl_storers.h
|
||||
td/utils/TlDowncastHelper.h
|
||||
td/utils/translit.h
|
||||
td/utils/TsCerr.h
|
||||
td/utils/TsFileLog.h
|
||||
|
26
tdutils/td/utils/TlDowncastHelper.h
Normal file
26
tdutils/td/utils/TlDowncastHelper.h
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
|
||||
template <class T>
|
||||
class TlDowncastHelper final : public T {
|
||||
public:
|
||||
explicit TlDowncastHelper(int32 constructor) : constructor_(constructor) {
|
||||
}
|
||||
int32 get_id() const final {
|
||||
return constructor_;
|
||||
}
|
||||
void store(TlStorerToString &s, const char *field_name) const final {
|
||||
}
|
||||
|
||||
private:
|
||||
int32 constructor_{0};
|
||||
};
|
||||
|
||||
} // namespace td
|
Loading…
Reference in New Issue
Block a user