// Copyright (c) 2004-present, Facebook, Inc. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. #pragma once #include #include #include #ifndef RN_EXPORT #define RN_EXPORT __attribute__((visibility("default"))) #endif namespace facebook { namespace react { // Base class for private data used to implement hybrid JS-native objects. A common root class, // rtti and dynamic_cast allow us to do some runtime type checking that makes it possible // for multiple hybrid object implementations to co-exist. class RN_EXPORT PrivateDataBase { public: virtual ~PrivateDataBase(); // Casts given void* to PrivateDataBase and performs dynamic_cast to desired type. Returns null on // failure. template static typename std::enable_if::value, T>::type* tryCast(void* ptr) { #ifdef _MSC_VER #pragma warning(suppress: 4541) return dynamic_cast(reinterpret_cast(ptr)); #else return dynamic_cast(reinterpret_cast(ptr)); #endif } // Like tryCast, but aborts on failure. template static typename std::enable_if::value, T>::type* cast(void* ptr) { auto result = tryCast(ptr); if (!result) { assert(false && "could not cast to desired type"); abort(); } return result; } }; } }