-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtemplate_function.h
More file actions
72 lines (67 loc) · 1.59 KB
/
template_function.h
File metadata and controls
72 lines (67 loc) · 1.59 KB
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
//
// template_function.h
// template_function
//
// Created by Hys on 2017/5/30.
// Copyright © 2017年 Hys. All rights reserved.
//
#ifndef _TEMPLATE_FUNCTION_H_
#define _TEMPLATE_FUNCTION_H_ 1
#include <sstream>
//以下是几个模版函数,目的是为了简化record_manager中的代码
template <typename T>
int getDataLength(T data) {
std::stringstream stream;
stream << data;
return stream.str().length();
}
template <typename T>
bool isSatisfied(T a , T b , WHERE relation) {
switch(relation) {
case LESS:{
if (a < b)
return true;
else
return false;
};break;
case LESS_OR_EQUAL:{
if (a <= b)
return true;
else
return false;
};break;
case EQUAL:{
if (a == b)
return true;
else
return false;
};break;
case GREATER_OR_EQUAL:{
if (a >= b)
return true;
else
return false;
};break;
case GREATER:{
if (a > b)
return true;
else
return false;
};break;
case NOT_EQUAL:{
if (a != b)
return true;
else
return false;
};break;
}
}
template <typename T>
void copyString(char* p , int& offset , T data) {
std::stringstream stream;
stream << data;
std::string s1 = stream.str();
for (int i = 0;i < s1.length();i++,offset++)
p[offset] = s1[i];
}
#endif