ChaiScript / ChaiScript
1
// This file is distributed under the BSD License.
2
// See "license.txt" for details.
3
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4
// Copyright 2009-2018, Jason Turner (jason@emptycrate.com)
5
// http://www.chaiscript.com
6

7
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
8
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9

10

11
#ifndef CHAISCRIPT_OPERATORS_HPP_
12
#define CHAISCRIPT_OPERATORS_HPP_
13

14
#include "../chaiscript_defines.hpp"
15
#include "register_function.hpp"
16

17
namespace chaiscript 
18
{
19
  namespace bootstrap
20
  {
21
    namespace operators
22
    {
23
      template<typename T>
24 1
        void assign(Module& m)
25
        {
26 1
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs = rhs;}), "=");
27
        }
28

29
      template<typename T>
30
        void assign_bitwise_and(Module& m)
31
        {
32
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs &= rhs;}), "&=");
33
        }
34

35
      template<typename T>
36
        void assign_xor(Module& m)
37
        {
38
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs ^= rhs;}), "^=");
39
        }
40

41
      template<typename T>
42
        void assign_bitwise_or(Module& m)
43
        {
44
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs |= rhs;}), "|=");
45
        }
46

47
      template<typename T>
48
        void assign_difference(Module& m)
49
        {
50
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs -= rhs;}), "-=");
51
        }
52

53
      template<typename T>
54
        void assign_left_shift(Module& m)
55
        {
56
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs <<= rhs;}), "<<=");
57
        }
58

59
      template<typename T>
60
        void assign_product(Module& m)
61
        {
62
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs <<= rhs;}), "*=");
63
        }
64

65
      template<typename T>
66
        void assign_quotient(Module& m)
67
        {
68
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs /= rhs;}), "/=");
69
        }
70

71
      template<typename T>
72
        void assign_remainder(Module& m)
73
        {
74
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs %= rhs;}), "%=");
75
        }
76

77
      template<typename T>
78
        void assign_right_shift(Module& m)
79
        {
80
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs >>= rhs;}), ">>=");
81
        }
82

83
      template<typename T>
84 1
        void assign_sum(Module& m)
85
        {
86 1
          m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs += rhs;}), "+=");
87
        }
88

89
      template<typename T>
90
        void prefix_decrement(Module& m)
91
        {
92
          m.add(chaiscript::fun([](T &lhs)->T&{return --lhs;}), "--");
93
        }
94

95
      template<typename T>
96
        void prefix_increment(Module& m)
97
        {
98
          m.add(chaiscript::fun([](T &lhs)->T&{return ++lhs;}), "++");
99
        }
100

101
      template<typename T>
102 1
        void equal(Module& m)
103
        {
104 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs==rhs;}), "==");
105
        }
106

107
      template<typename T>
108 1
        void greater_than(Module& m)
109
        {
110 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>rhs;}), ">");
111
        }
112

113
      template<typename T>
114 1
        void greater_than_equal(Module& m)
115
        {
116 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>=rhs;}), ">=");
117
        }
118

119
      template<typename T>
120 1
        void less_than(Module& m)
121
        {
122 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<rhs;}), "<");
123
        }
124

125
      template<typename T>
126 1
        void less_than_equal(Module& m)
127
        {
128 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<=rhs;}), "<=");
129
        }
130

131
      template<typename T>
132 1
        void logical_compliment(Module& m)
133
        {
134 1
          m.add(chaiscript::fun([](const T &lhs){return !lhs;}), "!");
135
        }
136

137
      template<typename T>
138 1
        void not_equal(Module& m)
139
        {
140 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs!=rhs;}), "!=");
141
        }
142

143
      template<typename T>
144 1
        void addition(Module& m)
145
        {
146 1
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs+rhs;}), "+");
147
        }
148

149
      template<typename T>
150
        void unary_plus(Module& m)
151
        {
152
          m.add(chaiscript::fun([](const T &lhs){return +lhs;}), "+");
153
        }
154

155
      template<typename T>
156
        void subtraction(Module& m)
157
        {
158
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs-rhs;}), "-");
159
        }
160

161
      template<typename T>
162
        void unary_minus(Module& m)
163
        {
164
          m.add(chaiscript::fun([](const T &lhs){return -lhs;}), "-");
165
        }
166

167
      template<typename T>
168
        void bitwise_and(Module& m)
169
        {
170
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs&rhs;}), "&");
171
        }
172

173
      template<typename T>
174
        void bitwise_compliment(Module& m)
175
        {
176
          m.add(chaiscript::fun([](const T &lhs){return ~lhs;}), "~");
177
        }
178

179
      template<typename T>
180
        void bitwise_xor(Module& m)
181
        {
182
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs^rhs;}), "^");
183
        }
184

185
      template<typename T>
186
        void bitwise_or(Module& m)
187
        {
188
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs|rhs;}), "|");
189
        }
190

191
      template<typename T>
192
        void division(Module& m)
193
        {
194
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs/rhs;}), "/");
195
        }
196

197
      template<typename T>
198
        void left_shift(Module& m)
199
        {
200
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<<rhs;}), "<<");
201
        }
202

203
      template<typename T>
204
        void multiplication(Module& m)
205
        {
206
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs*rhs;}), "*");
207
        }
208

209
      template<typename T>
210
        void remainder(Module& m)
211
        {
212
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs%rhs;}), "%");
213
        }
214

215
      template<typename T>
216
        void right_shift(Module& m)
217
        {
218
          m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>>rhs;}), ">>");
219
        }
220
    }
221
  }
222
}
223

224
#endif

Read our documentation on viewing source code .

Loading