Move as from common.h to as.h.
GitOrigin-RevId: 3ecc4b4c4ff6c9b070d30cf017e22a8acce0af09
This commit is contained in:
parent
22eb4e1cb2
commit
3850a4da7f
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "td/mtproto/mtproto_api.h"
|
#include "td/mtproto/mtproto_api.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "td/mtproto/TcpTransport.h"
|
#include "td/mtproto/TcpTransport.h"
|
||||||
#include "td/mtproto/Transport.h"
|
#include "td/mtproto/Transport.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/Gzip.h"
|
#include "td/utils/Gzip.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#include "td/mtproto/TcpTransport.h"
|
#include "td/mtproto/TcpTransport.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/Random.h"
|
#include "td/utils/Random.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "td/mtproto/AuthKey.h"
|
#include "td/mtproto/AuthKey.h"
|
||||||
#include "td/mtproto/crypto.h"
|
#include "td/mtproto/crypto.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/mtproto/mtproto_api.h"
|
#include "td/mtproto/mtproto_api.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
#include "td/utils/int_types.h" // for UInt256, UInt128, etc
|
#include "td/utils/int_types.h" // for UInt256, UInt128, etc
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "td/actor/MultiPromise.h"
|
#include "td/actor/MultiPromise.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/SecureStorage.h"
|
#include "td/telegram/SecureStorage.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/UniqueId.h"
|
#include "td/telegram/UniqueId.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/SecureStorage.h"
|
#include "td/telegram/SecureStorage.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
|
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ set(TDUTILS_SOURCE
|
|||||||
td/utils/port/detail/WineventPoll.h
|
td/utils/port/detail/WineventPoll.h
|
||||||
|
|
||||||
td/utils/AesCtrByteFlow.h
|
td/utils/AesCtrByteFlow.h
|
||||||
|
td/utils/as.h
|
||||||
td/utils/base64.h
|
td/utils/base64.h
|
||||||
td/utils/benchmark.h
|
td/utils/benchmark.h
|
||||||
td/utils/BigNum.h
|
td/utils/BigNum.h
|
||||||
|
64
tdutils/td/utils/as.h
Normal file
64
tdutils/td/utils/as.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class As {
|
||||||
|
public:
|
||||||
|
As(void *ptr) : ptr_(ptr) {
|
||||||
|
}
|
||||||
|
As(As &&) = default;
|
||||||
|
As<T> &operator=(const As &new_value) && {
|
||||||
|
memcpy(ptr_, new_value.ptr_, sizeof(T));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
As<T> &operator=(const T new_value) && {
|
||||||
|
memcpy(ptr_, &new_value, sizeof(T));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const {
|
||||||
|
T res;
|
||||||
|
memcpy(&res, ptr_, sizeof(T));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void *ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class ConstAs {
|
||||||
|
public:
|
||||||
|
ConstAs(const void *ptr) : ptr_(ptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const {
|
||||||
|
T res;
|
||||||
|
memcpy(&res, ptr_, sizeof(T));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const void *ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class ToT, class FromT>
|
||||||
|
As<ToT> as(FromT *from) {
|
||||||
|
return As<ToT>(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ToT, class FromT>
|
||||||
|
const ConstAs<ToT> as(const FromT *from) {
|
||||||
|
return ConstAs<ToT>(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
@ -45,7 +45,6 @@
|
|||||||
#include "td/utils/int_types.h"
|
#include "td/utils/int_types.h"
|
||||||
#include "td/utils/unique_ptr.h"
|
#include "td/utils/unique_ptr.h"
|
||||||
|
|
||||||
#include <cstring> // temporary for std::memcpy
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -108,55 +107,4 @@ struct Auto {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class As {
|
|
||||||
public:
|
|
||||||
As(void *ptr) : ptr_(ptr) {
|
|
||||||
}
|
|
||||||
As(As &&) = default;
|
|
||||||
As<T> &operator=(const As &new_value) && {
|
|
||||||
memcpy(ptr_, new_value.ptr_, sizeof(T));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
As<T> &operator=(const T new_value) && {
|
|
||||||
memcpy(ptr_, &new_value, sizeof(T));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T() const {
|
|
||||||
T res;
|
|
||||||
memcpy(&res, ptr_, sizeof(T));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void *ptr_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class ConstAs {
|
|
||||||
public:
|
|
||||||
ConstAs(const void *ptr) : ptr_(ptr) {
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T() const {
|
|
||||||
T res;
|
|
||||||
memcpy(&res, ptr_, sizeof(T));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const void *ptr_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class ToT, class FromT>
|
|
||||||
As<ToT> as(FromT *from) {
|
|
||||||
return As<ToT>(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ToT, class FromT>
|
|
||||||
const ConstAs<ToT> as(const FromT *from) {
|
|
||||||
return ConstAs<ToT>(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// 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)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
#include "td/utils/as.h"
|
||||||
#include "td/utils/base64.h"
|
#include "td/utils/base64.h"
|
||||||
#include "td/utils/BigNum.h"
|
#include "td/utils/BigNum.h"
|
||||||
#include "td/utils/bits.h"
|
#include "td/utils/bits.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user