Program Listing for File base.h
↰ Return to documentation for file (include/converter/include/mindapi/base/base.h
)
#ifndef MINDSPORE_CORE_MINDAPI_BASE_BASE_H_
#define MINDSPORE_CORE_MINDAPI_BASE_BASE_H_
#include <cstdint>
#include <string>
#include <memory>
#include "mindapi/base/macros.h"
#include "mindapi/base/type_traits.h"
#include "mindapi/base/shared_ptr.h"
namespace mindspore {
class Base;
}
namespace mindspore::api {
class MIND_API Base {
public:
explicit Base(const std::shared_ptr<mindspore::Base> &impl);
virtual ~Base() = default;
static uint32_t ClassId();
const std::shared_ptr<mindspore::Base> &impl() const { return impl_; }
std::string ToString() const;
template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<Base, T>, T>>
inline bool isa() const {
return IsFromClassId(T::ClassId());
}
template <typename T, typename U = typename std::enable_if_t<is_wrapper_ptr<T>::value, typename T::element_type>>
inline T cast() {
if (isa<U>()) {
return MakeShared<U>(impl_);
}
return nullptr;
}
protected:
bool IsFromClassId(uint32_t class_id) const;
const std::shared_ptr<mindspore::Base> impl_;
};
#define MIND_API_BASE_MEMBER(current_class) \
explicit current_class(const std::shared_ptr<mindspore::Base> &impl); \
~current_class() override = default; \
static uint32_t ClassId()
using BasePtr = SharedPtr<Base>;
} // namespace mindspore::api
#endif // MINDSPORE_CORE_MINDAPI_BASE_BASE_H_