9
9
#include " RDConstant.h"
10
10
#include " CQTools.h"
11
11
extern std::map<long long , int > DefaultDice;
12
- // This funtion template is used to convert a type into another type
13
- // Param:origin->Original Data
14
- // Usage:Convert<Converted Type> (Original Data)
15
-
16
- template <typename typeTo, typename typeFrom>
17
- typeTo Convert (typeFrom origin)
18
- {
19
- std::stringstream ConvertStream;
20
- typeTo converted;
21
- ConvertStream << origin;
22
- ConvertStream >> converted;
23
- return converted;
24
- }
25
12
26
13
// This function is used to generate random integer
27
14
inline int Randint (int lowest, int highest)
@@ -52,8 +39,8 @@ class RD
52
39
return Input_Err;
53
40
if (strAddVal.length () > 2 )
54
41
return AddDiceVal_Err;
55
- int intDiceCnt = Convert< int > (strDiceCnt);
56
- int AddDiceVal = Convert< int > (strAddVal);
42
+ int intDiceCnt = stoi (strDiceCnt);
43
+ int AddDiceVal = stoi (strAddVal);
57
44
if (intDiceCnt == 0 )
58
45
return ZeroDice_Err;
59
46
if (AddDiceVal < 5 || AddDiceVal > 10 )
@@ -100,7 +87,7 @@ class RD
100
87
}
101
88
if (strDiceNum.length () > 2 )
102
89
return DiceTooBig_Err;
103
- int intDiceNum = Convert< int > (strDiceNum);
90
+ int intDiceNum = stoi (strDiceNum);
104
91
if (intDiceNum == 0 )
105
92
return ZeroDice_Err;
106
93
std::vector<int > vintTmpRes;
@@ -127,7 +114,7 @@ class RD
127
114
for (int i = 1 ; i != dice.length (); i++)
128
115
if (!isdigit (dice[i]))
129
116
return Input_Err;
130
- int intPNum = Convert< int >( dice.substr (1 ));
117
+ int intPNum = stoi (dice. substr ( 1 ). empty () ? " 1 " : dice.substr (1 ));
131
118
if (dice.length () == 1 )
132
119
intPNum = 1 ;
133
120
if (intPNum == 0 )
@@ -164,7 +151,7 @@ class RD
164
151
for (int i = 1 ; i != dice.length (); i++)
165
152
if (!isdigit (dice[i]))
166
153
return Input_Err;
167
- int intBNum = Convert< int >( dice.substr (1 ));
154
+ int intBNum = stoi (dice. substr ( 1 ). empty () ? " 1 " : dice.substr (1 ));
168
155
if (dice.length () == 1 )
169
156
intBNum = 1 ;
170
157
if (intBNum == 0 )
@@ -222,7 +209,7 @@ class RD
222
209
{
223
210
if (dice.length () > 5 || dice.length () == 0 )
224
211
return Value_Err;
225
- int intTmpRes = Convert< int > (dice);
212
+ int intTmpRes = stoi (dice);
226
213
if (boolNegative)
227
214
intTotal -= intTmpRes;
228
215
else
@@ -237,8 +224,8 @@ class RD
237
224
return DiceTooBig_Err;
238
225
if (dice.substr (dice.find (" D" ) + 1 ).length () > 5 )
239
226
return TypeTooBig_Err;
240
- int intDiceCnt = dice.substr (0 , dice.find (" D" )).length () == 0 ? 1 : Convert< int > (dice.substr (0 , dice.find (" D" )));
241
- int intDiceType = Convert< int > (dice.substr (dice.find (" D" ) + 1 ));
227
+ int intDiceCnt = dice.substr (0 , dice.find (" D" )).length () == 0 ? 1 : stoi (dice.substr (0 , dice.find (" D" )));
228
+ int intDiceType = stoi (dice.substr (dice.find (" D" ) + 1 ));
242
229
if (intDiceCnt == 0 )
243
230
return ZeroDice_Err;
244
231
if (intDiceType == 0 )
@@ -263,12 +250,12 @@ class RD
263
250
{
264
251
if (dice.substr (dice.find (" K" ) + 1 ).length () > 3 )
265
252
return Value_Err;
266
- int intKNum = Convert< int > (dice.substr (dice.find (" K" ) + 1 ));
253
+ int intKNum = stoi (dice.substr (dice.find (" K" ) + 1 ));
267
254
dice = dice.substr (0 , dice.find (" K" ));
268
255
if (dice.substr (0 , dice.find (" D" )).length () > 3 || dice.substr (dice.find (" D" ) + 1 ).length () > 5 )
269
256
return Value_Err;
270
- int intDiceCnt = dice.substr (0 , dice.find (" D" )).length () == 0 ? 1 : Convert< int > (dice.substr (0 , dice.find (" D" )));
271
- int intDiceType = Convert< int > (dice.substr (dice.find (" D" ) + 1 ));
257
+ int intDiceCnt = dice.substr (0 , dice.find (" D" )).length () == 0 ? 1 : stoi (dice.substr (0 , dice.find (" D" )));
258
+ int intDiceType = stoi (dice.substr (dice.find (" D" ) + 1 ));
272
259
if (intKNum <= 0 || intDiceCnt == 0 )
273
260
return ZeroDice_Err;
274
261
if (intKNum > intDiceCnt)
0 commit comments