C++ 17 style nested namespaces (#1326)

Summary:
X-link: https://github.com/facebook/react-native/pull/38304

Pull Request resolved: https://github.com/facebook/yoga/pull/1326

For better readability

Reviewed By: christophpurrer

Differential Revision: D47384926

fbshipit-source-id: 2f60d50a185331b3624d45d1fc45f98d504b3034
This commit is contained in:
Nick Gerleman
2023-07-12 09:38:40 -07:00
committed by Facebook GitHub Bot
parent 423dc155d8
commit 660edcec20
25 changed files with 61 additions and 145 deletions

View File

@@ -12,9 +12,7 @@
#include <type_traits> #include <type_traits>
#include "corefunctions.h" #include "corefunctions.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
/** /**
* ScopedGlobalRef is a sort of smart reference that allows us to control the * ScopedGlobalRef is a sort of smart reference that allows us to control the
@@ -132,6 +130,4 @@ ScopedGlobalRef<T> make_global_ref(T globalRef) {
return ScopedGlobalRef<T>(globalRef); return ScopedGlobalRef<T>(globalRef);
} }
} // namespace vanillajni } // namespace facebook::yoga::vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -15,9 +15,7 @@
#include <cstddef> #include <cstddef>
#include <type_traits> #include <type_traits>
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
/** /**
* ScopedLocalRef is a sort of smart reference that allows us to control the * ScopedLocalRef is a sort of smart reference that allows us to control the
@@ -132,6 +130,4 @@ ScopedLocalRef<T> make_local_ref(JNIEnv* env, T localRef) {
return ScopedLocalRef<T>(env, localRef); return ScopedLocalRef<T>(env, localRef);
} }
} // namespace vanillajni } // namespace facebook::yoga::vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -10,9 +10,7 @@
#include "YogaJniException.h" #include "YogaJniException.h"
#include "common.h" #include "common.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
YogaJniException::YogaJniException() { YogaJniException::YogaJniException() {
jclass cl = getCurrentEnv()->FindClass("java/lang/RuntimeException"); jclass cl = getCurrentEnv()->FindClass("java/lang/RuntimeException");
@@ -47,6 +45,5 @@ ScopedLocalRef<jthrowable> YogaJniException::getThrowable() const noexcept {
getCurrentEnv(), getCurrentEnv(),
static_cast<jthrowable>(getCurrentEnv()->NewLocalRef(throwable_.get()))); static_cast<jthrowable>(getCurrentEnv()->NewLocalRef(throwable_.get())));
} }
} // namespace vanillajni
} // namespace yoga } // namespace facebook::yoga::vanillajni
} // namespace facebook

View File

@@ -9,9 +9,7 @@
#include <string> #include <string>
#include "common.h" #include "common.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
/** /**
* This class wraps a Java exception (jthrowable) into a C++ exception; A global * This class wraps a Java exception (jthrowable) into a C++ exception; A global
* reference to Java exception (jthrowable) is made so that the exception object * reference to Java exception (jthrowable) is made so that the exception object
@@ -33,6 +31,5 @@ public:
private: private:
ScopedGlobalRef<jthrowable> throwable_; ScopedGlobalRef<jthrowable> throwable_;
}; };
} // namespace vanillajni
} // namespace yoga } // namespace facebook::yoga::vanillajni
} // namespace facebook

View File

@@ -7,9 +7,7 @@
#include "common.h" #include "common.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
void registerNatives( void registerNatives(
JNIEnv* env, JNIEnv* env,
@@ -109,6 +107,5 @@ ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj) {
return make_global_ref(result); return make_global_ref(result);
} }
} // namespace vanillajni
} // namespace yoga } // namespace facebook::yoga::vanillajni
} // namespace facebook

View File

@@ -9,9 +9,7 @@
#include "ScopedGlobalRef.h" #include "ScopedGlobalRef.h"
#include "ScopedLocalRef.h" #include "ScopedLocalRef.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
/** /**
* Registers a set of methods for a JNI class. Aborts if registration fails. * Registers a set of methods for a JNI class. Aborts if registration fails.
@@ -74,6 +72,5 @@ ScopedLocalRef<jobject> callStaticObjectMethod(
ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj); ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj);
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj); ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj);
} // namespace vanillajni
} // namespace yoga } // namespace facebook::yoga::vanillajni
} // namespace facebook

View File

@@ -9,9 +9,7 @@
#include "macros.h" #include "macros.h"
#include "YogaJniException.h" #include "YogaJniException.h"
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
namespace { namespace {
JavaVM* globalVm = NULL; JavaVM* globalVm = NULL;
@@ -90,6 +88,4 @@ void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition) {
throw YogaJniException(); throw YogaJniException();
} }
} // namespace vanillajni } // namespace facebook::yoga::vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -10,9 +10,7 @@
#include <jni.h> #include <jni.h>
#include <cstddef> #include <cstddef>
namespace facebook { namespace facebook::yoga::vanillajni {
namespace yoga {
namespace vanillajni {
/** /**
* This method has to be called before using the vanillajni library. This method * This method has to be called before using the vanillajni library. This method
@@ -49,6 +47,4 @@ void assertNoPendingJniException(JNIEnv* env);
void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition); void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition);
} // namespace vanillajni } // namespace facebook::yoga::vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -10,8 +10,7 @@
#include <cstdint> #include <cstdint>
#include <yoga/BitUtils.h> #include <yoga/BitUtils.h>
namespace facebook { namespace facebook::yoga {
namespace yoga {
TEST(BitUtils, one_boolean_defaults_to_false) { TEST(BitUtils, one_boolean_defaults_to_false) {
constexpr uint8_t flags = 0; constexpr uint8_t flags = 0;
@@ -202,5 +201,4 @@ TEST(BitUtils, setting_values_does_not_spill_over) {
ASSERT_EQ(detail::getEnumData<YGEdge>(flags, edgesOffset), 0xf); ASSERT_EQ(detail::getEnumData<YGEdge>(flags, edgesOffset), 0xf);
} }
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook

View File

@@ -18,9 +18,7 @@
#include "util/TestUtil.h" #include "util/TestUtil.h"
namespace facebook { namespace facebook::yoga::test {
namespace yoga {
namespace test {
template <Event::Type E> template <Event::Type E>
struct TypedEventTestData {}; struct TypedEventTestData {};
@@ -353,6 +351,4 @@ void EventTest::TearDown() {
std::vector<EventArgs> EventTest::events{}; std::vector<EventArgs> EventTest::events{};
} // namespace test } // namespace facebook::yoga::test
} // namespace yoga
} // namespace facebook

View File

@@ -76,8 +76,7 @@
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \ INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
} }
namespace facebook { namespace facebook::yoga {
namespace yoga {
using CompactValue = detail::CompactValue; using CompactValue = detail::CompactValue;
@@ -255,5 +254,4 @@ ACCESSOR_TEST(
#endif #endif
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook

View File

@@ -10,9 +10,7 @@
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <yoga/event/event.h> #include <yoga/event/event.h>
namespace facebook { namespace facebook::yoga::test {
namespace yoga {
namespace test {
int nodeInstanceCount = 0; int nodeInstanceCount = 0;
@@ -61,6 +59,4 @@ ScopedEventSubscription::~ScopedEventSubscription() {
Event::reset(); Event::reset();
} }
} // namespace test } // namespace facebook::yoga::test
} // namespace yoga
} // namespace facebook

View File

@@ -11,9 +11,7 @@
#include <functional> #include <functional>
namespace facebook { namespace facebook::yoga::test {
namespace yoga {
namespace test {
struct YOGA_EXPORT TestUtil { struct YOGA_EXPORT TestUtil {
static void startCountingNodes(); static void startCountingNodes();
@@ -26,6 +24,4 @@ struct ScopedEventSubscription {
~ScopedEventSubscription(); ~ScopedEventSubscription();
}; };
} // namespace test } // namespace facebook::yoga::test
} // namespace yoga
} // namespace facebook

View File

@@ -13,10 +13,7 @@
#include <yoga/YGEnums.h> #include <yoga/YGEnums.h>
namespace facebook { namespace facebook::yoga::detail {
namespace yoga {
namespace detail {
// std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL // std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL
template <typename Enum> template <typename Enum>
@@ -68,6 +65,4 @@ inline void setBooleanData(uint8_t& flags, size_t index, bool value) {
} }
} }
} // namespace detail } // namespace facebook::yoga::detail
} // namespace yoga
} // namespace facebook

View File

@@ -38,9 +38,7 @@ static_assert(
#define VISIBLE_FOR_TESTING private: #define VISIBLE_FOR_TESTING private:
#endif #endif
namespace facebook { namespace facebook::yoga::detail {
namespace yoga {
namespace detail {
// This class stores YGValue in 32 bits. // This class stores YGValue in 32 bits.
// - The value does not matter for Undefined and Auto. NaNs are used for their // - The value does not matter for Undefined and Auto. NaNs are used for their
@@ -209,6 +207,4 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
return !(a == b); return !(a == b);
} }
} // namespace detail } // namespace facebook::yoga::detail
} // namespace yoga
} // namespace facebook

View File

@@ -9,16 +9,14 @@
using namespace facebook::yoga; using namespace facebook::yoga;
namespace facebook { namespace facebook::yoga {
namespace yoga {
bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b) { bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b) {
return a->getErrata() != b->getErrata() || return a->getErrata() != b->getErrata() ||
a->getEnabledExperiments() != b->getEnabledExperiments() || a->getEnabledExperiments() != b->getEnabledExperiments() ||
a->getPointScaleFactor() != b->getPointScaleFactor() || a->getPointScaleFactor() != b->getPointScaleFactor() ||
a->useWebDefaults() != b->useWebDefaults(); a->useWebDefaults() != b->useWebDefaults();
} }
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook
YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} { YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
setLogger(logger); setLogger(logger);

View File

@@ -12,8 +12,7 @@
#include "BitUtils.h" #include "BitUtils.h"
#include "Yoga-internal.h" #include "Yoga-internal.h"
namespace facebook { namespace facebook::yoga {
namespace yoga {
// Whether moving a node from config "a" to config "b" should dirty previously // Whether moving a node from config "a" to config "b" should dirty previously
// calculated layout results. // calculated layout results.
@@ -48,8 +47,7 @@ struct YGConfigFlags {
}; };
#pragma pack(pop) #pragma pack(pop)
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook
struct YOGA_EXPORT YGConfig { struct YOGA_EXPORT YGConfig {
YGConfig(YGLogger logger); YGConfig(YGLogger logger);

View File

@@ -95,9 +95,8 @@
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
namespace facebook {
namespace yoga { namespace facebook::yoga::enums {
namespace enums {
template <typename T> template <typename T>
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9
@@ -109,9 +108,7 @@ constexpr int n() {
} }
} // namespace detail } // namespace detail
} // namespace enums } // namespace facebook::yoga::enums
} // namespace yoga
} // namespace facebook
#endif #endif
#define YG_ENUM_DECL(NAME, ...) \ #define YG_ENUM_DECL(NAME, ...) \
@@ -122,16 +119,13 @@ constexpr int n() {
#define YG_ENUM_SEQ_DECL(NAME, ...) \ #define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \ YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \ YG_EXTERN_C_END \
namespace facebook { \ \
namespace yoga { \ namespace facebook::yoga::enums { \
namespace enums { \
template <> \ template <> \
constexpr int count<NAME>() { \ constexpr int count<NAME>() { \
return detail::n<__VA_ARGS__>(); \ return detail::n<__VA_ARGS__>(); \
} \ } \
} \ } \
} \
} \
YG_EXTERN_C_BEGIN YG_EXTERN_C_BEGIN
#else #else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL #define YG_ENUM_SEQ_DECL YG_ENUM_DECL

View File

@@ -16,8 +16,7 @@
#include "Yoga-internal.h" #include "Yoga-internal.h"
#include "Utils.h" #include "Utils.h"
namespace facebook { namespace facebook::yoga {
namespace yoga {
typedef std::string string; typedef std::string string;
static void indent(string& base, uint32_t level) { static void indent(string& base, uint32_t level) {
@@ -242,6 +241,6 @@ void YGNodeToString(
} }
appendFormattedString(str, "</div>"); appendFormattedString(str, "</div>");
} }
} // namespace yoga
} // namespace facebook } // namespace facebook::yoga
#endif #endif

View File

@@ -13,8 +13,7 @@
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
namespace facebook { namespace facebook::yoga {
namespace yoga {
void YGNodeToString( void YGNodeToString(
std::string& str, std::string& str,
@@ -22,7 +21,6 @@ void YGNodeToString(
YGPrintOptions options, YGPrintOptions options,
uint32_t level); uint32_t level);
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook
#endif #endif

View File

@@ -33,8 +33,7 @@ void YGNodeDeallocate(YGNodeRef node);
YG_EXTERN_C_END YG_EXTERN_C_END
namespace facebook { namespace facebook::yoga {
namespace yoga {
inline bool isUndefined(float value) { inline bool isUndefined(float value) {
return std::isnan(value); return std::isnan(value);
@@ -46,8 +45,7 @@ inline bool isUndefined(double value) {
void throwLogicalErrorWithMessage(const char* message); void throwLogicalErrorWithMessage(const char* message);
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook
extern const std::array<YGEdge, 4> trailing; extern const std::array<YGEdge, 4> trailing;
extern const std::array<YGEdge, 4> leading; extern const std::array<YGEdge, 4> leading;
@@ -103,9 +101,7 @@ struct YGCachedMeasurement {
// 98% of analyzed layouts require less than 8 entries. // 98% of analyzed layouts require less than 8 entries.
#define YG_MAX_CACHED_RESULT_COUNT 8 #define YG_MAX_CACHED_RESULT_COUNT 8
namespace facebook { namespace facebook::yoga::detail {
namespace yoga {
namespace detail {
template <size_t Size> template <size_t Size>
class Values { class Values {
@@ -149,9 +145,8 @@ public:
Values& operator=(const Values& other) = default; Values& operator=(const Values& other) = default;
}; };
} // namespace detail
} // namespace yoga } // namespace facebook::yoga::detail
} // namespace facebook
static const float kDefaultFlexGrow = 0.0f; static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f; static const float kDefaultFlexShrink = 0.0f;

View File

@@ -9,8 +9,7 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
namespace facebook { namespace facebook::yoga {
namespace yoga {
const char* LayoutPassReasonToString(const LayoutPassReason value) { const char* LayoutPassReasonToString(const LayoutPassReason value) {
switch (value) { switch (value) {
@@ -82,5 +81,4 @@ void Event::publish(const YGNode& node, Type eventType, const Data& eventData) {
} }
} }
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook

View File

@@ -16,8 +16,7 @@
struct YGConfig; struct YGConfig;
struct YGNode; struct YGNode;
namespace facebook { namespace facebook::yoga {
namespace yoga {
enum struct LayoutType : int { enum struct LayoutType : int {
kLayout = 0, kLayout = 0,
@@ -140,5 +139,4 @@ struct Event::TypedData<Event::NodeLayout> {
void* layoutContext; void* layoutContext;
}; };
} // namespace yoga } // namespace facebook::yoga
} // namespace facebook

View File

@@ -11,9 +11,7 @@
#include "YGConfig.h" #include "YGConfig.h"
#include "YGNode.h" #include "YGNode.h"
namespace facebook { namespace facebook::yoga::detail {
namespace yoga {
namespace detail {
namespace { namespace {
@@ -59,6 +57,4 @@ void Log::log(
va_end(args); va_end(args);
} }
} // namespace detail } // namespace facebook::yoga::detail
} // namespace yoga
} // namespace facebook

View File

@@ -12,10 +12,7 @@
struct YGNode; struct YGNode;
struct YGConfig; struct YGConfig;
namespace facebook { namespace facebook::yoga::detail {
namespace yoga {
namespace detail {
struct Log { struct Log {
static void log( static void log(
@@ -33,6 +30,4 @@ struct Log {
...) noexcept; ...) noexcept;
}; };
} // namespace detail } // namespace facebook::yoga::detail
} // namespace yoga
} // namespace facebook