feat(base): Replace the DISALLOW_COPY_AND_ASSIGN macro with explicit deleted copy and assign constructors

This commit is contained in:
churchill-zhang
2022-07-05 15:56:28 +08:00
committed by GitHub
parent 65379a79f1
commit 2a03e6bfac
15 changed files with 39 additions and 73 deletions
@@ -48,6 +48,9 @@ class AnimationManager
public:
AnimationManager();
AnimationManager(AnimationManager&) = delete;
AnimationManager& operator=(AnimationManager&) = delete;
inline std::weak_ptr<RootNode> GetRootNode() {
return root_node_;
}
@@ -132,8 +135,6 @@ class AnimationManager
*/
std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::string>> node_animation_props_map_;
uint64_t listener_id_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(AnimationManager);
};
} // namespace dom
} // namespace hippy
+3 -2
View File
@@ -75,6 +75,9 @@ class DomManager : public std::enable_shared_from_this<DomManager> {
DomManager();
~DomManager();
DomManager(DomManager&) = delete;
DomManager& operator=(DomManager&) = delete;
inline int32_t GetId() { return id_; }
inline std::weak_ptr<RenderManager> GetRenderManager() { return render_manager_; }
inline std::shared_ptr<TaskRunner> GetTaskRunner() { return dom_task_runner_; }
@@ -134,8 +137,6 @@ class DomManager : public std::enable_shared_from_this<DomManager> {
std::weak_ptr<RenderManager> render_manager_;
std::shared_ptr<TaskRunner> dom_task_runner_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(DomManager);
friend DomNode;
};
-15
View File
@@ -1,15 +0,0 @@
//
// Copyright (c) 2020 Tencent Corporation. All rights reserved.
//
#define WEAK_THIS weak_this = weak_from_this()
#define SHARED_THIS self = this->shared_from_this()
// 表明该lambda不会被存储,可以安全使用this
#define THIS_NO_STORE this
#define HAS_SELF(type) auto self = std::static_pointer_cast<type>(weak_this.lock())
#define DEFINE_SELF(type) HAS_SELF(type);
#define DEFINE_AND_CHECK_SELF(type) \
DEFINE_SELF(type) \
if (!self) { \
return; \
}
@@ -11,7 +11,6 @@
#include "footstone/base_time.h"
#include "dom/dom_node.h"
#include "dom/macro.h"
#include "dom/node_props.h"
#include "dom/render_manager.h"
#include "dom/root_node.h"
-1
View File
@@ -12,7 +12,6 @@
#include "dom/dom_event.h"
#include "dom/dom_node.h"
#include "dom/layer_optimized_render_manager.h"
#include "dom/macro.h"
#include "dom/render_manager.h"
#include "dom/root_node.h"
#include "footstone/serializer.h"
-1
View File
@@ -4,7 +4,6 @@
#include <utility>
#include "footstone/logging.h"
#include "dom/diff_utils.h"
#include "dom/macro.h"
#include "dom/node_props.h"
#include "dom/render_manager.h"
#include "dom/root_node.h"
@@ -22,7 +22,6 @@
#include "dom/dom_manager.h"
#include "dom/dom_node.h"
#include "dom/macro.h"
namespace hippy::devtools {
constexpr char kScreenShot[] = "screenShot";
@@ -40,6 +40,9 @@ class BaseTimer {
explicit BaseTimer(const std::shared_ptr<TaskRunner>& task_runner);
virtual ~BaseTimer();
BaseTimer(BaseTimer&) = delete;
BaseTimer& operator=(BaseTimer&) = delete;
void Stop();
void Reset();
inline void BindTaskRunner(std::shared_ptr<TaskRunner> task_runner) {
@@ -65,8 +68,6 @@ class BaseTimer {
bool is_running_;
TimePoint desired_run_time_;
TimePoint scheduled_run_time_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(BaseTimer);
};
} // namespace timer
@@ -35,6 +35,9 @@ class IdleTimer : public BaseTimer {
explicit IdleTimer(std::shared_ptr<TaskRunner> task_runner);
virtual ~IdleTimer();
IdleTimer(IdleTimer&) = delete;
IdleTimer& operator=(IdleTimer&) = delete;
virtual void Start(std::unique_ptr<IdleTask> idle_task, TimeDelta timeout);
virtual void Start(std::unique_ptr<IdleTask> idle_task);
@@ -43,8 +46,6 @@ class IdleTimer : public BaseTimer {
void RunUserTask() final;
std::shared_ptr<IdleTask> idle_task_ ;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(IdleTimer);
};
}
@@ -90,6 +90,9 @@ class LogMessage {
LogMessage(LogSeverity severity, const char* file, int line, const char* condition);
~LogMessage();
LogMessage(LogMessage&) = delete;
LogMessage& operator=(LogMessage&) = delete;
inline static void InitializeDelegate(
std::function<void(const std::ostringstream&, LogSeverity)> delegate) {
if (!delegate) {
@@ -114,8 +117,6 @@ class LogMessage {
const LogSeverity severity_;
const char* file_;
const int line_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(LogMessage);
};
int GetVlogVerbosity();
+11 -37
View File
@@ -20,42 +20,16 @@
#pragma once
#define FOOTSTONE_EMBEDDER_ONLY
#define FOOTSTONE_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete
#define FOOTSTONE_DISALLOW_ASSIGN(TypeName) TypeName& operator=(const TypeName&) = delete
#define FOOTSTONE_DISALLOW_MOVE(TypeName) \
TypeName(TypeName&&) = delete; \
TypeName& operator=(TypeName&&) = delete
#define FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName& operator=(const TypeName&) = delete
#define FOOTSTONE_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName(TypeName&&) = delete; \
TypeName& operator=(const TypeName&) = delete; \
TypeName& operator=(TypeName&&) = delete
#define FOOTSTONE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() = delete; \
FOOTSTONE_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
#ifdef NDEBUG
#define assert_fn(fn) ((void)0)
#else
#define assert_fn(fn) \
do { \
auto b = fn(); \
assert(b); \
} while (0)
#endif
#define RETURN_IF(x) \
if (x) { \
return; \
#define WEAK_THIS weak_this = weak_from_this()
#define SHARED_THIS self = this->shared_from_this()
// 表明该lambda不会被存储,可以安全使用this
#define THIS_NO_STORE this
#define HAS_SELF(type) auto self = std::static_pointer_cast<type>(weak_this.lock())
#define DEFINE_SELF(type) HAS_SELF(type);
#define DEFINE_AND_CHECK_SELF(type) \
DEFINE_SELF(type) \
if (!self) { \
return; \
}
@@ -35,6 +35,9 @@ inline namespace timer {
explicit OneShotTimer(const std::shared_ptr<TaskRunner>& task_runner);
virtual ~OneShotTimer();
OneShotTimer(OneShotTimer&) = delete;
OneShotTimer& operator=(OneShotTimer&) = delete;
void Start(std::unique_ptr<Task> user_task, TimeDelta delay);
void FireNow();
@@ -45,8 +48,6 @@ inline namespace timer {
void RunUserTask() final;
std::unique_ptr<Task> user_task_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(OneShotTimer);
};
} // namespace base
@@ -33,14 +33,15 @@ inline namespace timer {
explicit RepeatingTimer(const std::shared_ptr<TaskRunner>& task_runner);
virtual ~RepeatingTimer();
RepeatingTimer(RepeatingTimer&) = delete;
RepeatingTimer& operator=(RepeatingTimer&) = delete;
void Start(std::unique_ptr<Task> user_task, TimeDelta delay);
virtual std::shared_ptr<BaseTimer> GetWeakSelf() override;
private:
void OnStop() final;
void RunUserTask() override;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(RepeatingTimer);
};
} // namespace base
@@ -49,6 +49,9 @@ class TaskRunner {
bool is_schedulable = true, std::string name = "");
~TaskRunner();
TaskRunner(TaskRunner&) = delete;
TaskRunner& operator=(TaskRunner&) = delete;
void Clear();
bool AddSubTaskRunner(const std::shared_ptr<TaskRunner> &sub_runner,
bool is_task_running = false);
@@ -145,7 +148,6 @@ class TaskRunner {
* 不可调度的TaskRunner不会被迁移,但其所在的Worker还是可以加入其他TaskRunner
*/
bool is_schedulable_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(TaskRunner);
};
} // namespace runner
@@ -32,6 +32,10 @@ class WorkerManager {
public:
explicit WorkerManager(uint32_t size);
~WorkerManager();
WorkerManager(WorkerManager&) = delete;
WorkerManager& operator=(WorkerManager&) = delete;
void Terminate();
void Resize(uint32_t size);
void AddWorker(const std::shared_ptr<Worker>& worker);
@@ -58,8 +62,6 @@ class WorkerManager {
int32_t index_;
uint32_t size_;
std::mutex mutex_;
FOOTSTONE_DISALLOW_COPY_AND_ASSIGN(WorkerManager);
};
} // namespace runner