1 /***********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6 *
7 * THE BSD LICENSE
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *************************************************************************/
30
31 #ifndef FLANN_GENERAL_H_
32 #define FLANN_GENERAL_H_
33
34 #include "defines.h"
35 #include <stdexcept>
36 #include <cassert>
37
38 namespace flann
39 {
40
41 class FLANNException : public std::runtime_error
42 {
43 public:
FLANNException(const char * message)44 FLANNException(const char* message) : std::runtime_error(message) { }
45
FLANNException(const std::string & message)46 FLANNException(const std::string& message) : std::runtime_error(message) { }
47 };
48
flann_datatype_size(flann_datatype_t type)49 inline size_t flann_datatype_size(flann_datatype_t type)
50 {
51 switch (type) {
52 case FLANN_INT8:
53 return 1;
54 break;
55 case FLANN_INT16:
56 return 2;
57 break;
58 case FLANN_INT32:
59 return 4;
60 break;
61 case FLANN_INT64:
62 return 8;
63 break;
64 case FLANN_UINT8:
65 return 1;
66 break;
67 case FLANN_UINT16:
68 return 2;
69 break;
70 case FLANN_UINT32:
71 return 4;
72 break;
73 case FLANN_UINT64:
74 return 8;
75 break;
76 case FLANN_FLOAT32:
77 return 4;
78 break;
79 case FLANN_FLOAT64:
80 return 8;
81 break;
82 default:
83 return 1;
84 }
85 }
86
87 template <typename T>
88 struct flann_datatype
89 {
90 static const flann_datatype_t value = FLANN_NONE;
91 };
92
93 template<>
94 struct flann_datatype<char>
95 {
96 static const flann_datatype_t value = FLANN_INT8;
97 };
98
99 template<>
100 struct flann_datatype<short>
101 {
102 static const flann_datatype_t value = FLANN_INT16;
103 };
104
105 template<>
106 struct flann_datatype<int>
107 {
108 static const flann_datatype_t value = FLANN_INT32;
109 };
110
111 template<>
112 struct flann_datatype<unsigned char>
113 {
114 static const flann_datatype_t value = FLANN_UINT8;
115 };
116
117 template<>
118 struct flann_datatype<unsigned short>
119 {
120 static const flann_datatype_t value = FLANN_UINT16;
121 };
122
123 template<>
124 struct flann_datatype<unsigned int>
125 {
126 static const flann_datatype_t value = FLANN_UINT32;
127 };
128
129 template<>
130 struct flann_datatype<float>
131 {
132 static const flann_datatype_t value = FLANN_FLOAT32;
133 };
134
135 template<>
136 struct flann_datatype<double>
137 {
138 static const flann_datatype_t value = FLANN_FLOAT64;
139 };
140
141 }
142
143
144 #endif /* FLANN_GENERAL_H_ */
145