18 #include "FaissException.h"
19 #include "error_impl.h"
24 #define CATCH_AND_HANDLE \
25 catch (faiss::FaissException& e) { \
26 faiss_last_exception = \
27 std::make_exception_ptr(e); \
29 } catch (std::exception& e) { \
30 faiss_last_exception = \
31 std::make_exception_ptr(e); \
34 faiss_last_exception = \
35 std::make_exception_ptr( \
36 std::runtime_error("Unknown error")); \
40 #define CATCH_AND_HANDLE \
41 catch (faiss::FaissException& e) { \
42 std::cerr << e.what() << '\n'; \
43 faiss_last_exception = \
44 std::make_exception_ptr(e); \
46 } catch (std::exception& e) { \
47 std::cerr << e.what() << '\n'; \
48 faiss_last_exception = \
49 std::make_exception_ptr(e); \
52 std::cerr << "Unrecognized exception!\n"; \
53 faiss_last_exception = \
54 std::make_exception_ptr( \
55 std::runtime_error("Unknown error")); \
60 #define DEFINE_GETTER(clazz, ty, name) \
61 ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *obj) { \
62 return static_cast< ty >( \
63 reinterpret_cast< const faiss::clazz *>(obj)-> name \
67 #define DEFINE_GETTER_SUBCLASS(clazz, parent, ty, name) \
68 ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *obj) { \
69 return static_cast< ty >( \
70 reinterpret_cast<const faiss::parent::clazz *>(obj)-> name \
74 #define DEFINE_GETTER_PERMISSIVE(clazz, ty, name) \
75 ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *obj) { \
77 reinterpret_cast<const faiss::clazz *>(obj)-> name \
81 #define DEFINE_GETTER_SUBCLASS_PERMISSIVE(clazz, parent, ty, name) \
82 ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *obj) { \
84 reinterpret_cast<const faiss::parent::clazz *>(obj)-> name \
88 #define DEFINE_SETTER(clazz, ty, name) \
89 void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *obj, ty val) { \
90 reinterpret_cast< faiss::clazz *>(obj)-> name = val; \
93 #define DEFINE_SETTER_STATIC(clazz, ty_to, ty_from, name) \
94 void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *obj, ty_from val) { \
95 reinterpret_cast< faiss::clazz *>(obj)-> name = \
96 static_cast< ty_to >(val); \
99 #define DEFINE_DESTRUCTOR(clazz) \
100 void faiss_ ## clazz ## _free (Faiss ## clazz *obj) { \
101 delete reinterpret_cast<faiss::clazz *>(obj); \
104 #define DEFINE_INDEX_DOWNCAST(clazz) \
105 Faiss ## clazz * faiss_ ## clazz ## _cast (FaissIndex* index) { \
106 return reinterpret_cast<Faiss ## clazz *>( \
107 dynamic_cast< faiss::clazz *>( \
108 reinterpret_cast<faiss::Index*>(index))); \