forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FaissException.h
68 lines (52 loc) · 1.57 KB
/
FaissException.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD+Patents license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
#ifndef FAISS_EXCEPTION_INCLUDED
#define FAISS_EXCEPTION_INCLUDED
#include <exception>
#include <string>
namespace faiss {
/// Base class for Faiss exceptions
class FaissException : public std::exception {
public:
explicit FaissException(const std::string& msg);
FaissException(const std::string& msg,
const char* funcName,
const char* file,
int line);
/// from std::exception
const char* what() const noexcept override;
std::string msg;
};
/** bare-bones unique_ptr
* this one deletes with delete [] */
template<class T>
struct ScopeDeleter {
const T * ptr;
explicit ScopeDeleter (const T* ptr = nullptr): ptr (ptr) {}
void release () {ptr = nullptr; }
void set (const T * ptr_in) { ptr = ptr_in; }
void swap (ScopeDeleter<T> &other) {std::swap (ptr, other.ptr); }
~ScopeDeleter () {
delete [] ptr;
}
};
/** same but deletes with the simple delete (least common case) */
template<class T>
struct ScopeDeleter1 {
const T * ptr;
explicit ScopeDeleter1 (const T* ptr = nullptr): ptr (ptr) {}
void release () {ptr = nullptr; }
void set (const T * ptr_in) { ptr = ptr_in; }
void swap (ScopeDeleter1<T> &other) {std::swap (ptr, other.ptr); }
~ScopeDeleter1 () {
delete ptr;
}
};
}
#endif