Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/matthijs/github_faiss/faiss/FaissException.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
11 #ifndef FAISS_EXCEPTION_INCLUDED
12 #define FAISS_EXCEPTION_INCLUDED
13
14 #include <exception>
15 #include <string>
16
17 namespace faiss {
18
19 /// Base class for Faiss exceptions
20 class FaissException : public std::exception {
21 public:
22 explicit FaissException(const std::string& msg);
23
24 FaissException(const std::string& msg,
25 const char* funcName,
26 const char* file,
27 int line);
28
29 /// from std::exception
30 const char* what() const noexcept override;
31
32 std::string msg;
33 };
34
35
36 /** bare-bones unique_ptr
37 * this one deletes with delete [] */
38 template<class T>
39 struct ScopeDeleter {
40 const T * ptr;
41 explicit ScopeDeleter (const T* ptr = nullptr): ptr (ptr) {}
42 void release () {ptr = nullptr; }
43 void set (const T * ptr_in) { ptr = ptr_in; }
44 void swap (ScopeDeleter<T> &other) {std::swap (ptr, other.ptr); }
45 ~ScopeDeleter () {
46 delete [] ptr;
47 }
48 };
49
50 /** same but deletes with the simple delete (least common case) */
51 template<class T>
52 struct ScopeDeleter1 {
53 const T * ptr;
54 explicit ScopeDeleter1 (const T* ptr = nullptr): ptr (ptr) {}
55 void release () {ptr = nullptr; }
56 void set (const T * ptr_in) { ptr = ptr_in; }
57 void swap (ScopeDeleter1<T> &other) {std::swap (ptr, other.ptr); }
58 ~ScopeDeleter1 () {
59 delete ptr;
60 }
61 };
62
63
64
65 }
66
67
68 #endif
faiss::ScopeDeleter1
Definition: FaissException.h:52
faiss::FaissException::what
const char * what() const noexceptoverride
from std::exception
Definition: FaissException.cpp:31
faiss::ScopeDeleter
Definition: FaissException.h:39
faiss::FaissException
Base class for Faiss exceptions.
Definition: FaissException.h:20