-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.h
80 lines (61 loc) · 1.69 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
/*
* main.h
*
* Created on: Oct 8, 2013
* Author: llongi
*/
#ifndef MAIN_H_
#define MAIN_H_
// Common includes, useful for everyone.
#include <libcaer/libcaer.h>
#include <libcaer/events/packetContainer.h>
#include "ext/sshs/sshs.h"
// Suppress unused argument warnings, if needed
#define UNUSED_ARGUMENT(arg) (void)(arg)
// Support symbol export on Windows GCC/Clang.
#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && (defined(__GNUC__) || defined(__clang__))
#define CAER_SYMBOL_EXPORT __attribute__ ((__dllexport__))
#else
#define CAER_SYMBOL_EXPORT
#endif
#ifdef __cplusplus
#include <libcaercpp/libcaer.hpp>
#include "ext/sshs/sshs.hpp"
#include <algorithm>
#include <vector>
template<typename InIter, typename Elem>
static inline bool findBool(InIter begin, InIter end, const Elem &val) {
const auto result = std::find(begin, end, val);
if (result == end) {
return (false);
}
return (true);
}
template<typename InIter, typename Pred>
static inline bool findIfBool(InIter begin, InIter end, Pred predicate) {
const auto result = std::find_if(begin, end, predicate);
if (result == end) {
return (false);
}
return (true);
}
template<class T>
static void vectorSortUnique(std::vector<T> &vec) {
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
template<class T>
static bool vectorDetectDuplicates(std::vector<T> &vec) {
// Detect duplicates.
size_t sizeBefore = vec.size();
vectorSortUnique(vec);
size_t sizeAfter = vec.size();
// If size changed, duplicates must have been removed, so they existed
// in the first place!
if (sizeAfter != sizeBefore) {
return (true);
}
return (false);
}
#endif
#endif /* MAIN_H_ */