Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/hoss/faiss/FaissException.h
1 /**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 // -*- c++ -*-
9
10 #ifndef FAISS_EXCEPTION_INCLUDED
11 #define FAISS_EXCEPTION_INCLUDED
12
13 #include <exception>
14 #include <string>
15 #include <vector>
16 #include <utility>
17
18 namespace faiss {
19
20 /// Base class for Faiss exceptions
21 class FaissException : public std::exception {
22 public:
23 explicit FaissException(const std::string& msg);
24
25 FaissException(const std::string& msg,
26 const char* funcName,
27 const char* file,
28 int line);
29
30 /// from std::exception
31 const char* what() const noexcept override;
32
33 std::string msg;
34 };
35
36 /// Handle multiple exceptions from worker threads, throwing an appropriate
37 /// exception that aggregates the information
38 /// The pair int is the thread that generated the exception
39 void
40 handleExceptions(std::vector<std::pair<int, std::exception_ptr>>& exceptions);
41
42 /** bare-bones unique_ptr
43 * this one deletes with delete [] */
44 template<class T>
45 struct ScopeDeleter {
46 const T * ptr;
47 explicit ScopeDeleter (const T* ptr = nullptr): ptr (ptr) {}
48 void release () {ptr = nullptr; }
49 void set (const T * ptr_in) { ptr = ptr_in; }
50 void swap (ScopeDeleter<T> &other) {std::swap (ptr, other.ptr); }
51 ~ScopeDeleter () {
52 delete [] ptr;
53 }
54 };
55
56 /** same but deletes with the simple delete (least common case) */
57 template<class T>
58 struct ScopeDeleter1 {
59 const T * ptr;
60 explicit ScopeDeleter1 (const T* ptr = nullptr): ptr (ptr) {}
61 void release () {ptr = nullptr; }
62 void set (const T * ptr_in) { ptr = ptr_in; }
63 void swap (ScopeDeleter1<T> &other) {std::swap (ptr, other.ptr); }
64 ~ScopeDeleter1 () {
65 delete ptr;
66 }
67 };
68
69 }
70
71 #endif
faiss::handleExceptions
void handleExceptions(std::vector< std::pair< int, std::exception_ptr >> &exceptions)
Definition: FaissException.cpp:35
faiss::ScopeDeleter1
Definition: FaissException.h:58
faiss::FaissException::what
const char * what() const noexceptoverride
from std::exception
Definition: FaissException.cpp:31
faiss::ScopeDeleter
Definition: FaissException.h:45
faiss::FaissException
Base class for Faiss exceptions.
Definition: FaissException.h:21