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 "corefunctions.h"
namespace facebook {
namespace yoga {
namespace vanillajni {
namespace facebook::yoga::vanillajni {
/**
* 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);
}
} // namespace vanillajni
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::vanillajni

View File

@@ -15,9 +15,7 @@
#include <cstddef>
#include <type_traits>
namespace facebook {
namespace yoga {
namespace vanillajni {
namespace facebook::yoga::vanillajni {
/**
* 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);
}
} // namespace vanillajni
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::vanillajni

View File

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

View File

@@ -9,9 +9,7 @@
#include <string>
#include "common.h"
namespace facebook {
namespace yoga {
namespace vanillajni {
namespace facebook::yoga::vanillajni {
/**
* 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
@@ -33,6 +31,5 @@ public:
private:
ScopedGlobalRef<jthrowable> throwable_;
};
} // namespace vanillajni
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::vanillajni

View File

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

View File

@@ -9,9 +9,7 @@
#include "ScopedGlobalRef.h"
#include "ScopedLocalRef.h"
namespace facebook {
namespace yoga {
namespace vanillajni {
namespace facebook::yoga::vanillajni {
/**
* 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<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj);
} // namespace vanillajni
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::vanillajni

View File

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

View File

@@ -10,9 +10,7 @@
#include <jni.h>
#include <cstddef>
namespace facebook {
namespace yoga {
namespace vanillajni {
namespace facebook::yoga::vanillajni {
/**
* 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);
} // namespace vanillajni
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::vanillajni

View File

@@ -10,8 +10,7 @@
#include <cstdint>
#include <yoga/BitUtils.h>
namespace facebook {
namespace yoga {
namespace facebook::yoga {
TEST(BitUtils, one_boolean_defaults_to_false) {
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);
}
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -38,9 +38,7 @@ static_assert(
#define VISIBLE_FOR_TESTING private:
#endif
namespace facebook {
namespace yoga {
namespace detail {
namespace facebook::yoga::detail {
// This class stores YGValue in 32 bits.
// - 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);
}
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::detail

View File

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

View File

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

View File

@@ -95,9 +95,8 @@
#endif
#ifdef __cplusplus
namespace facebook {
namespace yoga {
namespace enums {
namespace facebook::yoga::enums {
template <typename T>
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 enums
} // namespace yoga
} // namespace facebook
} // namespace facebook::yoga::enums
#endif
#define YG_ENUM_DECL(NAME, ...) \
@@ -122,16 +119,13 @@ constexpr int n() {
#define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \
namespace facebook { \
namespace yoga { \
namespace enums { \
\
namespace facebook::yoga::enums { \
template <> \
constexpr int count<NAME>() { \
return detail::n<__VA_ARGS__>(); \
} \
} \
} \
} \
YG_EXTERN_C_BEGIN
#else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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