Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
faiss_c.h
1 /**
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD+Patents license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 // Copyright 2004-present Facebook. All Rights Reserved.
10 // -*- c -*-
11 
12 /// Macros and typedefs for C wrapper API declarations
13 
14 #ifndef FAISS_C_H
15 #define FAISS_C_H
16 
17 typedef long idx_t; ///< all indices are this type
18 
19 /// Declare an opaque type for a class type `clazz`.
20 #define FAISS_DECLARE_CLASS(clazz) \
21  typedef struct Faiss ## clazz ## _H Faiss ## clazz;
22 
23 /// Declare an opaque type for a class type `clazz`, while
24 /// actually aliasing it to an existing parent class type `parent`.
25 #define FAISS_DECLARE_CLASS_INHERITED(clazz, parent) \
26  typedef struct Faiss ## parent ## _H Faiss ## clazz;
27 
28 /// Declare a dynamic downcast operation from a base `FaissIndex*` pointer
29 /// type to a more specific index type. The function returns the same pointer
30 /// if the downcast is valid, and `NULL` otherwise.
31 #define FAISS_DECLARE_INDEX_DOWNCAST(clazz) \
32  Faiss ## clazz * faiss_ ## clazz ## _cast (FaissIndex*);
33 
34 /// Declare a getter for the field `name` in class `clazz`,
35 /// of return type `ty`
36 #define FAISS_DECLARE_GETTER(clazz, ty, name) \
37  ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *);
38 
39 /// Declare a setter for the field `name` in class `clazz`,
40 /// in which the user provides a value of type `ty`
41 #define FAISS_DECLARE_SETTER(clazz, ty, name) \
42  void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *, ty);
43 
44 /// Declare a getter and setter for the field `name` in class `clazz`.
45 #define FAISS_DECLARE_GETTER_SETTER(clazz, ty, name) \
46  FAISS_DECLARE_GETTER(clazz, ty, name) \
47  FAISS_DECLARE_SETTER(clazz, ty, name)
48 
49 /// Declare a destructor function which frees an object of
50 /// type `clazz`.
51 #define FAISS_DECLARE_DESTRUCTOR(clazz) \
52  void faiss_ ## clazz ## _free (Faiss ## clazz *obj);
53 
54 #endif