mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
bf9872a7b5
Summary: changelog: [internal] You can read more about this rule on https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-equals-default.html Reviewed By: rubennorte Differential Revision: D33295116 fbshipit-source-id: d7da62c35e141fc2bf5a83c28f80f4f8d355c4cb
67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "Sealable.h"
|
|
|
|
#include <react/debug/flags.h>
|
|
#include <react/debug/react_native_assert.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Note:
|
|
* We must explicitly implement all *the rule of five* methods because:
|
|
* 1. Using `std::atomic` behind `sealed_` implicitly deletes default
|
|
* constructors;
|
|
* 2. We have to establish behaviour where any new cloned or moved instances
|
|
* of the object lose `sealed` flag.
|
|
*
|
|
* See more about the rule of three/five/zero:
|
|
* http://en.cppreference.com/w/cpp/language/rule_of_three
|
|
*/
|
|
|
|
#ifdef REACT_NATIVE_DEBUG
|
|
|
|
Sealable::Sealable() : sealed_(false) {}
|
|
|
|
Sealable::Sealable(const Sealable &other) : sealed_(false){};
|
|
|
|
Sealable::Sealable(Sealable &&other) noexcept : sealed_(false) {
|
|
other.ensureUnsealed();
|
|
};
|
|
|
|
Sealable::~Sealable() noexcept = default;
|
|
|
|
Sealable &Sealable::operator=(const Sealable &other) {
|
|
ensureUnsealed();
|
|
return *this;
|
|
}
|
|
|
|
Sealable &Sealable::operator=(Sealable &&other) noexcept {
|
|
ensureUnsealed();
|
|
other.ensureUnsealed();
|
|
return *this;
|
|
}
|
|
|
|
void Sealable::seal() const {
|
|
sealed_ = true;
|
|
}
|
|
|
|
bool Sealable::getSealed() const {
|
|
return sealed_;
|
|
}
|
|
|
|
void Sealable::ensureUnsealed() const {
|
|
react_native_assert(!sealed_ && "Attempt to mutate a sealed object.");
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|