Skip to content

Commit a522f09

Browse files
committed
fix: Put template<...> on a separate line
1 parent 3907c89 commit a522f09

File tree

15 files changed

+109
-54
lines changed

15 files changed

+109
-54
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ReflowComments: true
2020
# Line breaking options
2121
BreakBeforeBraces: Attach
2222
BreakConstructorInitializers: BeforeColon
23+
AlwaysBreakTemplateDeclarations: true
2324
AllowShortFunctionsOnASingleLine: Empty
2425
IndentCaseLabels: true
2526
NamespaceIndentation: Inner

packages/react-native-nitro-modules/android/src/main/cpp/utils/JNISharedPtr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace margelo::nitro {
1111

1212
using namespace facebook;
1313

14-
template <typename T> struct GlobalRefDeleter {
14+
template <typename T>
15+
struct GlobalRefDeleter {
1516
explicit GlobalRefDeleter(jni::global_ref<typename T::javaobject> ref) : _ref(ref) {}
1617

1718
void operator()(T* ptr) {

packages/react-native-nitro-modules/cpp/core/HybridObject.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class HybridObject : public jsi::HostObject, public std::enable_shared_from_this
6767
* Get the `std::shared_ptr` instance of this HybridObject.
6868
* The HybridObject must be managed inside a `shared_ptr` already, otherwise this will fail.
6969
*/
70-
template <typename Derived> std::shared_ptr<Derived> shared() {
70+
template <typename Derived>
71+
std::shared_ptr<Derived> shared() {
7172
return std::static_pointer_cast<Derived>(shared_from_this());
7273
}
7374

packages/react-native-nitro-modules/cpp/core/PointerHolder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace margelo::nitro {
1313

1414
using namespace facebook;
1515

16-
template <typename T> class PointerHolder final : public HybridObject {
16+
template <typename T>
17+
class PointerHolder final : public HybridObject {
1718
protected:
1819
// no default constructor
1920
PointerHolder() = delete;

packages/react-native-nitro-modules/cpp/jsi/JSICache.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ using namespace facebook;
2323

2424
static constexpr auto CACHE_PROP_NAME = "__nitroModulesJSICache";
2525

26-
template <typename T> class JSICache;
26+
template <typename T>
27+
class JSICache;
2728

28-
template <typename T> class JSICacheReference final {
29+
template <typename T>
30+
class JSICacheReference final {
2931
public:
3032
JSICacheReference() = delete;
3133
JSICacheReference(const JSICacheReference&) = delete;
@@ -70,7 +72,8 @@ template <typename T> class JSICacheReference final {
7072
* `jsi::Pointer`s are managed by a `jsi::Runtime`, and will be deleted if the `jsi::Runtime`
7173
* is deleted - even if there are still strong references to the `jsi::Pointer`.
7274
*/
73-
template <typename T = jsi::Pointer> class JSICache final : public jsi::NativeState {
75+
template <typename T = jsi::Pointer>
76+
class JSICache final : public jsi::NativeState {
7477
public:
7578
explicit JSICache(jsi::Runtime* runtime) : _runtime(runtime) {}
7679

packages/react-native-nitro-modules/cpp/jsi/JSIConverter.hpp

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ namespace margelo::nitro {
4040
using namespace facebook;
4141

4242
// Unknown type (error)
43-
template <typename ArgType, typename Enable = void> struct JSIConverter final {
43+
template <typename ArgType, typename Enable = void>
44+
struct JSIConverter final {
4445
JSIConverter() = delete;
4546

4647
static inline ArgType fromJSI(jsi::Runtime&, const jsi::Value&) {
@@ -53,11 +54,13 @@ template <typename ArgType, typename Enable = void> struct JSIConverter final {
5354
}
5455

5556
private:
56-
template <typename> struct always_false : std::false_type {};
57+
template <typename>
58+
struct always_false : std::false_type {};
5759
};
5860

5961
// int <> number
60-
template <> struct JSIConverter<int> {
62+
template <>
63+
struct JSIConverter<int> {
6164
static inline int fromJSI(jsi::Runtime&, const jsi::Value& arg) {
6265
return static_cast<int>(arg.asNumber());
6366
}
@@ -67,7 +70,8 @@ template <> struct JSIConverter<int> {
6770
};
6871

6972
// std::monostate <> null
70-
template <> struct JSIConverter<std::monostate> {
73+
template <>
74+
struct JSIConverter<std::monostate> {
7175
static inline std::monostate fromJSI(jsi::Runtime&, const jsi::Value& arg) {
7276
return std::monostate();
7377
}
@@ -77,7 +81,8 @@ template <> struct JSIConverter<std::monostate> {
7781
};
7882

7983
// double <> number
80-
template <> struct JSIConverter<double> {
84+
template <>
85+
struct JSIConverter<double> {
8186
static inline double fromJSI(jsi::Runtime&, const jsi::Value& arg) {
8287
return arg.asNumber();
8388
}
@@ -87,7 +92,8 @@ template <> struct JSIConverter<double> {
8792
};
8893

8994
// float <> number
90-
template <> struct JSIConverter<float> {
95+
template <>
96+
struct JSIConverter<float> {
9197
static inline float fromJSI(jsi::Runtime&, const jsi::Value& arg) {
9298
return static_cast<float>(arg.asNumber());
9399
}
@@ -97,7 +103,8 @@ template <> struct JSIConverter<float> {
97103
};
98104

99105
// int64_t <> BigInt
100-
template <> struct JSIConverter<int64_t> {
106+
template <>
107+
struct JSIConverter<int64_t> {
101108
static inline double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
102109
return arg.asBigInt(runtime).asInt64(runtime);
103110
}
@@ -107,7 +114,8 @@ template <> struct JSIConverter<int64_t> {
107114
};
108115

109116
// uint64_t <> BigInt
110-
template <> struct JSIConverter<uint64_t> {
117+
template <>
118+
struct JSIConverter<uint64_t> {
111119
static inline double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
112120
return arg.asBigInt(runtime).asUint64(runtime);
113121
}
@@ -117,7 +125,8 @@ template <> struct JSIConverter<uint64_t> {
117125
};
118126

119127
// bool <> boolean
120-
template <> struct JSIConverter<bool> {
128+
template <>
129+
struct JSIConverter<bool> {
121130
static inline bool fromJSI(jsi::Runtime&, const jsi::Value& arg) {
122131
return arg.asBool();
123132
}
@@ -127,7 +136,8 @@ template <> struct JSIConverter<bool> {
127136
};
128137

129138
// std::string <> string
130-
template <> struct JSIConverter<std::string> {
139+
template <>
140+
struct JSIConverter<std::string> {
131141
static inline std::string fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
132142
return arg.asString(runtime).utf8(runtime);
133143
}
@@ -137,7 +147,8 @@ template <> struct JSIConverter<std::string> {
137147
};
138148

139149
// std::optional<T> <> T | undefined
140-
template <typename TInner> struct JSIConverter<std::optional<TInner>> {
150+
template <typename TInner>
151+
struct JSIConverter<std::optional<TInner>> {
141152
static inline std::optional<TInner> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
142153
if (arg.isUndefined() || arg.isNull()) {
143154
return std::nullopt;
@@ -155,7 +166,8 @@ template <typename TInner> struct JSIConverter<std::optional<TInner>> {
155166
};
156167

157168
// std::future<T> <> Promise<T>
158-
template <typename TResult> struct JSIConverter<std::future<TResult>> {
169+
template <typename TResult>
170+
struct JSIConverter<std::future<TResult>> {
159171
static inline std::future<TResult> fromJSI(jsi::Runtime&, const jsi::Value&) {
160172
throw std::runtime_error("Promise cannot be converted to a native type - it needs to be awaited first!");
161173
}
@@ -210,16 +222,20 @@ template <typename TResult> struct JSIConverter<std::future<TResult>> {
210222
}
211223
};
212224

213-
template <typename T> struct future_traits {
225+
template <typename T>
226+
struct future_traits {
214227
using type = void;
215228
};
216-
template <typename T> struct future_traits<std::future<T>> {
229+
template <typename T>
230+
struct future_traits<std::future<T>> {
217231
using type = T;
218232
};
219-
template <typename T> using future_traits_t = typename future_traits<std::remove_reference_t<T>>::type;
233+
template <typename T>
234+
using future_traits_t = typename future_traits<std::remove_reference_t<T>>::type;
220235

221236
// [](Args...) -> T {} <> (Args...) => T
222-
template <typename ReturnType, typename... Args> struct JSIConverter<std::function<ReturnType(Args...)>> {
237+
template <typename ReturnType, typename... Args>
238+
struct JSIConverter<std::function<ReturnType(Args...)>> {
223239
// std::future<T> -> T
224240
using ResultingType = future_traits_t<ReturnType>;
225241

@@ -311,7 +327,8 @@ template <typename ReturnType, typename... Args> struct JSIConverter<std::functi
311327
};
312328

313329
// std::vector<T> <> T[]
314-
template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
330+
template <typename ElementType>
331+
struct JSIConverter<std::vector<ElementType>> {
315332
static inline std::vector<ElementType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
316333
jsi::Array array = arg.asObject(runtime).asArray(runtime);
317334
size_t length = array.size(runtime);
@@ -335,7 +352,8 @@ template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
335352
};
336353

337354
// std::unordered_map<std::string, T> <> Record<string, T>
338-
template <typename ValueType> struct JSIConverter<std::unordered_map<std::string, ValueType>> {
355+
template <typename ValueType>
356+
struct JSIConverter<std::unordered_map<std::string, ValueType>> {
339357
static inline std::unordered_map<std::string, ValueType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
340358
jsi::Object object = arg.asObject(runtime);
341359
jsi::Array propertyNames = object.getPropertyNames(runtime);
@@ -361,7 +379,8 @@ template <typename ValueType> struct JSIConverter<std::unordered_map<std::string
361379
};
362380

363381
// std::tuple<A, B, C> <> [A, B, C]
364-
template <typename... Types> struct JSIConverter<std::tuple<Types...>> {
382+
template <typename... Types>
383+
struct JSIConverter<std::tuple<Types...>> {
365384
static inline std::tuple<Types...> fromJSI(jsi::Runtime& runtime, const jsi::Value& value) {
366385
jsi::Object object = value.asObject(runtime);
367386
jsi::Array array = object.asArray(runtime);
@@ -396,11 +415,14 @@ template <typename... Types> struct JSIConverter<std::tuple<Types...>> {
396415
};
397416

398417
// Helper struct to check if a type is present in a parameter pack
399-
template <typename T, typename... Types> struct is_in_pack : std::disjunction<std::is_same<T, Types>...> {};
400-
template <typename T, typename... Types> inline constexpr bool is_in_pack_v = is_in_pack<T, Types...>::value;
418+
template <typename T, typename... Types>
419+
struct is_in_pack : std::disjunction<std::is_same<T, Types>...> {};
420+
template <typename T, typename... Types>
421+
inline constexpr bool is_in_pack_v = is_in_pack<T, Types...>::value;
401422

402423
// std::variant<A, B, C> <> A | B | C
403-
template <typename... Types> struct JSIConverter<std::variant<Types...>> {
424+
template <typename... Types>
425+
struct JSIConverter<std::variant<Types...>> {
404426
static inline std::variant<Types...> fromJSI(jsi::Runtime& runtime, const jsi::Value& value) {
405427
if (value.isNull()) {
406428
if constexpr (is_in_pack_v<std::monostate, Types...>) {
@@ -465,7 +487,8 @@ template <typename... Types> struct JSIConverter<std::variant<Types...>> {
465487
};
466488

467489
// AnyValue <> Record<K, V>
468-
template <> struct JSIConverter<AnyValue> {
490+
template <>
491+
struct JSIConverter<AnyValue> {
469492
static inline AnyValue fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
470493
return JSIConverter<AnyValue::variant>::fromJSI(runtime, arg);
471494
}
@@ -475,7 +498,8 @@ template <> struct JSIConverter<AnyValue> {
475498
};
476499

477500
// AnyMap <> Record<K, V>
478-
template <> struct JSIConverter<std::shared_ptr<AnyMap>> {
501+
template <>
502+
struct JSIConverter<std::shared_ptr<AnyMap>> {
479503
static inline std::shared_ptr<AnyMap> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
480504
jsi::Object object = arg.asObject(runtime);
481505
jsi::Array propNames = object.getPropertyNames(runtime);
@@ -500,7 +524,8 @@ template <> struct JSIConverter<std::shared_ptr<AnyMap>> {
500524
};
501525

502526
// MutableBuffer <> ArrayBuffer
503-
template <> struct JSIConverter<std::shared_ptr<jsi::MutableBuffer>> {
527+
template <>
528+
struct JSIConverter<std::shared_ptr<jsi::MutableBuffer>> {
504529
static inline std::shared_ptr<ArrayBuffer> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
505530
jsi::Object object = arg.asObject(runtime);
506531
if (!object.isArrayBuffer(runtime)) [[unlikely]] {
@@ -515,9 +540,12 @@ template <> struct JSIConverter<std::shared_ptr<jsi::MutableBuffer>> {
515540
};
516541

517542
// HybridObject <> {}
518-
template <typename T> struct is_shared_ptr_to_host_object : std::false_type {};
519-
template <typename T> struct is_shared_ptr_to_host_object<std::shared_ptr<T>> : std::is_base_of<jsi::HostObject, T> {};
520-
template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_host_object<T>::value>> {
543+
template <typename T>
544+
struct is_shared_ptr_to_host_object : std::false_type {};
545+
template <typename T>
546+
struct is_shared_ptr_to_host_object<std::shared_ptr<T>> : std::is_base_of<jsi::HostObject, T> {};
547+
template <typename T>
548+
struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_host_object<T>::value>> {
521549
using TPointee = typename T::element_type;
522550

523551
static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
@@ -564,9 +592,12 @@ template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_h
564592
};
565593

566594
// NativeState <> {}
567-
template <typename T> struct is_shared_ptr_to_native_state : std::false_type {};
568-
template <typename T> struct is_shared_ptr_to_native_state<std::shared_ptr<T>> : std::is_base_of<jsi::NativeState, T> {};
569-
template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_native_state<T>::value>> {
595+
template <typename T>
596+
struct is_shared_ptr_to_native_state : std::false_type {};
597+
template <typename T>
598+
struct is_shared_ptr_to_native_state<std::shared_ptr<T>> : std::is_base_of<jsi::NativeState, T> {};
599+
template <typename T>
600+
struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_native_state<T>::value>> {
570601
using TPointee = typename T::element_type;
571602

572603
static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {

packages/react-native-nitro-modules/cpp/threading/Dispatcher.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class Dispatcher : public jsi::NativeState {
4444
* Run the given function asynchronously on the Thread this Dispatcher is managing,
4545
* and return a future that will hold the result of the function.
4646
*/
47-
template <typename T> std::future<T> runAsyncAwaitable(std::function<T()>&& function) {
47+
template <typename T>
48+
std::future<T> runAsyncAwaitable(std::function<T()>&& function) {
4849
// 1. Create Promise that can be shared between this and dispatcher thread
4950
auto promise = std::make_shared<std::promise<T>>();
5051
std::future<T> future = promise->get_future();

packages/react-native-nitro-modules/cpp/utils/BorrowingReference+Owning.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace margelo::nitro {
1313

14-
template <typename T> BorrowingReference<T>::BorrowingReference(const OwningReference<T>& ref) {
14+
template <typename T>
15+
BorrowingReference<T>::BorrowingReference(const OwningReference<T>& ref) {
1516
_value = ref._value;
1617
_isDeleted = ref._isDeleted;
1718
_strongRefCount = ref._strongRefCount;
@@ -20,7 +21,8 @@ template <typename T> BorrowingReference<T>::BorrowingReference(const OwningRefe
2021
(*_weakRefCount)++;
2122
}
2223

23-
template <typename T> OwningReference<T> BorrowingReference<T>::lock() {
24+
template <typename T>
25+
OwningReference<T> BorrowingReference<T>::lock() {
2426
std::unique_lock lock(*_mutex);
2527

2628
if (*_isDeleted) {

packages/react-native-nitro-modules/cpp/utils/BorrowingReference.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
namespace margelo::nitro {
1515

1616
// forward-declaration to avoid duplicate symbols
17-
template <typename T> class OwningReference;
17+
template <typename T>
18+
class OwningReference;
1819

1920
/**
2021
A `BorrowingReference<T>` is a weak reference to a pointer created by `OwningReference<T>`.
2122
It can be locked to gain a strong `OwningReference<T>` again if it has not been deleted yet.
2223
*/
23-
template <typename T> class BorrowingReference final {
24+
template <typename T>
25+
class BorrowingReference final {
2426
private:
2527
explicit BorrowingReference(const OwningReference<T>& ref);
2628

packages/react-native-nitro-modules/cpp/utils/DoesClassExist.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace margelo::nitro {
1313

1414
// By default, it is false (class does not exist)
15-
template <typename T, typename = std::void_t<>> struct does_class_exist : std::false_type {};
15+
template <typename T, typename = std::void_t<>>
16+
struct does_class_exist : std::false_type {};
1617

1718
// If sizeof(T) can be a type (number), the type exists - so it is true
18-
template <typename T> struct does_class_exist<T, std::void_t<decltype(sizeof(T))>> : std::true_type {};
19+
template <typename T>
20+
struct does_class_exist<T, std::void_t<decltype(sizeof(T))>> : std::true_type {};
1921

2022
// Direct value accessor for does_class_exist
21-
template <typename T> inline constexpr bool does_class_exist_v = does_class_exist<T>::value;
23+
template <typename T>
24+
inline constexpr bool does_class_exist_v = does_class_exist<T>::value;
2225

2326
} // namespace margelo::nitro

0 commit comments

Comments
 (0)