forked from stepfun-ai/StepMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign_op.h
More file actions
84 lines (80 loc) · 1.54 KB
/
assign_op.h
File metadata and controls
84 lines (80 loc) · 1.54 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
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) 2015 by Contributors
* \file assign_op.h
* \brief assignment operator
* http://en.cppreference.com/w/cpp/language/operator_assignment
*/
#ifndef PS_INTERNAL_ASSIGN_OP_H_
#define PS_INTERNAL_ASSIGN_OP_H_
#include "ps/internal/utils.h"
namespace ps {
enum AssignOp {
ASSIGN, // a = b
PLUS, // a += b
MINUS, // a -= b
TIMES, // a *= b
DIVIDE, // a -= b
AND, // a &= b
OR, // a |= b
XOR // a ^= b
};
/**
* \brief return an assignment function: right op= left
*/
template <typename T>
inline void AssignFunc(const T& lhs, AssignOp op, T* rhs) {
switch (op) {
case ASSIGN:
*rhs = lhs;
break;
case PLUS:
*rhs += lhs;
break;
case MINUS:
*rhs -= lhs;
break;
case TIMES:
*rhs *= lhs;
break;
case DIVIDE:
*rhs /= lhs;
break;
default:
PS_LOG(FATAL) << "use AssignOpInt..";
}
}
/**
* \brief return an assignment function including bit operations, only
* works for integers
*/
template <typename T>
inline void AssignFuncInt(const T& lhs, AssignOp op, T* rhs) {
switch (op) {
case ASSIGN:
*rhs = lhs;
break;
case PLUS:
*rhs += lhs;
break;
case MINUS:
*rhs -= lhs;
break;
case TIMES:
*rhs *= lhs;
break;
case DIVIDE:
*rhs /= lhs;
break;
case AND:
*rhs &= lhs;
break;
case OR:
*rhs |= lhs;
break;
case XOR:
*rhs ^= lhs;
break;
}
}
} // namespace ps
#endif // PS_INTERNAL_ASSIGN_OP_H_