mirror of
https://github.com/zoriya/nitro.git
synced 2026-10-13 00:05:23 +00:00
* feat: Base for Kotlin modules * fix: Properly make sure Nitro C++ is initialized * Update JNIOnLoad.java * feat: Set up `initHybrid()` in JHybridObject * chore: Fix a bunch of linter issues * fix: Fix fbjni codegen * Update JHybridObject.hpp * fix: Make `initHybrid()` JVM static * feat: Make `mHybridData` private member of each in inheritance chain * Generate specs * feat: Set up proper inheritance graph in FBJNI using virtual inheritance `HybridObject` (#46) * feat: Try to set up proper inheritance in FBJNI * Virtual inheritance * Update JHybridImageFactorySpec.cpp * It works... * feat: Virtual base * Update HybridTestObject.hpp * Update CMakeLists.txt * Update JHybridObject.hpp * Virtual dtor * Dynamic cast to NativeState 🤔 * Virtual proper * feat: Generate as virtual base? * chore: Change to `updateNative` * feat: Cannot default-construct HybridObject * fix: Use `dynamic` pointer cast for `HybridContext` because `HybridObject` is now a virtual base * Update README.md
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
//
|
|
// Created by Marc Rousavy on 05.03.24.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <cstdarg>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace margelo::nitro {
|
|
|
|
class Logger final {
|
|
private:
|
|
Logger() = delete;
|
|
|
|
public:
|
|
template <typename... Args>
|
|
static void log(const char* tag, const char* message, Args&&... args) {
|
|
//std::string formattedMessage = format(message, std::forward<Args>(args)...);
|
|
//std::cout << "[Nitro." << tag << "] " << formattedMessage << std::endl;
|
|
}
|
|
|
|
private:
|
|
template <typename... Args>
|
|
static inline std::string format(const char* formatString, Args&&... args) {
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wformat-security"
|
|
int size_s = std::snprintf(nullptr, 0, formatString, toCString(args)...) + 1; // Extra space for '\0'
|
|
if (size_s <= 0) [[unlikely]] {
|
|
throw std::runtime_error("Failed to format log message \"" + std::string(formatString) + "\"!");
|
|
}
|
|
auto size = static_cast<size_t>(size_s);
|
|
std::vector<char> buf(size);
|
|
std::snprintf(buf.data(), size, formatString, toCString(args)...);
|
|
return std::string(buf.data(), buf.data() + size - 1); // We don't want the '\0' inside
|
|
#pragma clang diagnostic pop
|
|
}
|
|
|
|
private:
|
|
// When the user passes an `std::string`, it will automatically be converted to a `const char*`
|
|
static inline const char* toCString(const std::string& s) {
|
|
return s.c_str();
|
|
}
|
|
// When the user passes a `const char*`, we don't want to implicitly convert to `std::string`, so block that
|
|
static inline const char* toCString(const char* s) {
|
|
return s;
|
|
}
|
|
// When the user passes any other type, just return that directly.
|
|
template <typename T>
|
|
static inline T toCString(T value) {
|
|
return value;
|
|
}
|
|
};
|
|
|
|
} // namespace margelo::nitro
|