blob: c08d44be920a6e9bd9495e3a2971f781379d8158 [file] [log] [blame]
Hugo Hudsonb83ad732011-07-14 23:31:17 +01001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef FRAMEWORKS_EX_VARIABLESPEED_JNI_MACROS_H_
18#define FRAMEWORKS_EX_VARIABLESPEED_JNI_MACROS_H_
19
20#include <hlogging.h>
21
22inline float min(float a, float b) {
23 return (a < b) ? a : b;
24}
25
26inline float max(float a, float b) {
27 return (a > b) ? a : b;
28}
29
30template <class ForwardIterator>
31 ForwardIterator min_element(ForwardIterator first, ForwardIterator last) {
32 ForwardIterator lowest = first;
33 if (first == last) return last;
34 while (++first != last)
35 if (*first < *lowest)
36 lowest = first;
37 return lowest;
38}
39
40// A macro to disallow the copy constructor and operator= functions
41// This should be used in the private: declarations for a class
42#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
43 TypeName(const TypeName&); \
44 void operator=(const TypeName&)
45
46#define CHECK(x) { \
47 if (!(x)) { \
48 LOGE("assertion failed: " #x); \
49 LOGE("file: %s line: %d", __FILE__, __LINE__); \
50 int* frob = NULL; \
51 *frob = 5; \
52 } \
53}
54
55template <class Dest, class Source>
56inline Dest bit_cast(const Source& source) {
57 // Compile time assertion: sizeof(Dest) == sizeof(Source)
58 // A compile error here means your Dest and Source have different sizes.
59 typedef char VerifySizesAreEqual [sizeof(Dest) == sizeof(Source) ? 1 : -1]; // NOLINT
60
61 Dest dest;
62 memcpy(&dest, &source, sizeof(dest));
63 return dest;
64}
65
66#endif // FRAMEWORKS_EX_VARIABLESPEED_JNI_MACROS_H_