-
Notifications
You must be signed in to change notification settings - Fork 0
/
any.h
4276 lines (3748 loc) · 126 KB
/
any.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ***********************************************************************
// Copyright (c) 2016-2022 Florent Guelfucci
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// @see https://opensource.org/licenses/MIT
// ***********************************************************************
#pragma once
// string representation of the version number
#define MYODD_ANY_VERSION "0.1.17"
// the version number is #.###.###
// first number is major
// then 3 numbers for minor
// and 3 numbers for tiny
#define MYODD_ANY_VERSION_NUMBER 0001017
#if defined(_MSC_VER)
# if _MSC_VER < 1800
# error This project needs atleast Visual Studio 2013
# endif
// 199711L - c++98
// 201103L - c++11
// 201300L - c++14
#elif __cplusplus <= 201103L
# error This project can only be compiled with a compiler that supports C++14
#endif
/* What version of GCC is being used. 0 means GCC is not being used */
/* from sqlite 3*/
#ifdef __GNUC__
# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
#else
# define GCC_VERSION 0
#endif
#include <typeinfo> // std::bad_cast
#include <algorithm> // memcpy
#include <math.h> // modf
#include <cstring>
#include <string>
#include <locale> // std::wstring_convert
#include <cctype> // isdigit
#include <codecvt> // string <-> wstring
#include <stdlib.h> // std::strtoll / std::strtoull
#include <type_traits> // std::is_trivially_copyable
// std::is_pointer
#include <cstddef> // nullptr_t
#include <memory> // std::unique_ptr
#include "types.h" // data type
#include <iostream> // std::cout, std::right, std::endl
namespace myodd {
namespace _Check
{
struct No {};
template<typename T, typename Arg> No operator== (const T&, const Arg&);
template<typename T, typename Arg = T>
struct EqualExists
{
enum { value = !std::is_same<decltype(*(T*)(0) == *(Arg*)(0)), No>::value };
};
}
namespace dynamic {
class Any
{
private:
/**
* This is the type of comparaison we ar doing.
*/
enum CompareType {
CompareType_Equal,
CompareType_LessThan,
CompareType_MoreThan
};
// the string status, does it represent a number? a floating number?
// is it a partial or non partial number?
enum StringStatus {
StringStatus_Not_A_Number, // 'blah' or 'blah123'
StringStatus_Partial_Pos_Number, // '+123blah'
StringStatus_Partial_Neg_Number, // '-123blah'
StringStatus_Pos_Number, // '+123' or '123' or '0' or '-0'
StringStatus_Neg_Number, // '-123'
StringStatus_Floating_Partial_Pos_Number, // '+123.00blah' or '123.00blah'
StringStatus_Floating_Partial_Neg_Number, // '-123.00blah'
StringStatus_Floating_Pos_Number, // '+123.1' or '123.1' or '0.1' or '-0.1'
StringStatus_Floating_Neg_Number, // '-123.1'
};
public:
/**
* default constructor.
*/
Any() :
_unkvalue(nullptr),
_llivalue(0),
_ldvalue(0),
_cvalue(nullptr),
_lcvalue(0),
_stringStatus(StringStatus_Not_A_Number),
_svalue(nullptr),
_swvalue(nullptr),
_type(Type::Misc_null)
{
}
/**
* Copy constructor
* @see CreateFrom(T)
* @param T value the value we want to copy/set
*/
template<class T>
Any(const T& value) :
Any()
{
CreateFrom(value);
}
template<class T>
Any(T source, size_t num ) :
Any()
{
CreateFromCharacters(source, num );
}
/**
* Copy constructor
* @param const Any& any the value we are copying.
*/
Any(const Any& any) :
Any()
{
*this = any;
}
/**
* Destructor.
*/
virtual ~Any()
{
CleanValues();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
template<class T>
operator T() const {
return CastToCopy<T>();
}
template<class T>
operator T*() const
{
return CastToCopyPtr<T*>();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator bool() const
{
// cast *this to value
return CastToBool();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator float() const
{
// cast *this to value
return CastToFloat();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator double() const
{
// cast *this to value
return CastToDouble();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator long double() const
{
// cast *this to value
return CastToLongDouble();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator int() const
{
// cast *this to value
return CastToInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator short int() const
{
// cast *this to value
return CastToShortInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned short int() const
{
// cast *this to value
return CastToUnsignedShortInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned int() const
{
// cast *this to value
return CastToUnsignedInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator long int() const
{
// cast *this to value
return CastToLongInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned long int() const
{
// cast *this to value
return CastToUnsignedLongInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator long long int() const
{
// cast *this to value
return CastToLongLongInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned long long int() const
{
// cast *this to value
return CastToUnsignedLongLongInt();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator char*() const
{
// cast *this to value
return CastToChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator const char*() const
{
// cast *this to value
return CastToChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator std::string() const
{
// cast *this to value
return CastToChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator char() const
{
// cast *this to value
return CastToChar();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator const signed char*() const
{
// cast *this to value
return CastToSignedChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator signed char*() const
{
// cast *this to value
return CastToSignedChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator signed char() const
{
// cast *this to value
return CastToSignedChar();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned char*() const
{
// cast *this to value
return CastToUnsignedChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator const unsigned char*() const
{
// cast *this to value
return CastToUnsignedChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator unsigned char() const
{
// cast *this to value
return CastToUnsignedChar();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator const wchar_t*() const
{
// cast *this to value
return CastToWideChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator std::wstring() const
{
// cast *this to value
return CastToWideChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator wchar_t*() const
{
// cast *this to value
return CastToWideChars();
}
/**
* The T operator, cast a value to T
* @see CastTo
* @return T the template operator.
*/
operator wchar_t() const
{
// cast *this to value
return CastToWideChar();
}
friend std::ostream& operator<< (std::ostream& stream, const Any& any)
{
// write obj to stream
if ( dynamic::is_type_copy( any.Type() ))
{
stream << "Copy Value";
}
else
{
try
{
std::string value;
any.CastToCharacters(value);
stream << value.c_str();
}
catch (...)
{
// no idea how to display this.
stream << "NAN";
}
}
return stream;
}
/**
* The logical negation operator.
* @return false if the current value can be represented as true
*/
bool operator !() const
{
return !((bool)*this);
}
/**
* The equal operator
* @param const Any& other the value we are trying to set.
* @return const Any& this value.
*/
const Any& operator = (const Any& other)
{
if (this != &other)
{
// clear everything
CleanValues();
// copy the values over.
_type = other._type;
// long long int
_llivalue = other._llivalue;
// long double
_ldvalue = other._ldvalue;
// copy the unknown type
if (other._unkvalue)
{
++other._unkvalue->_counter;
_unkvalue = other._unkvalue;
}
// copy the character value
if (other._lcvalue > 0 && other._cvalue)
{
_lcvalue = other._lcvalue;
_cvalue = new char[_lcvalue];
std::memset(_cvalue, '\0', _lcvalue);
std::memcpy(_cvalue, other._cvalue, _lcvalue);
_stringStatus = other._stringStatus;
}
}
return *this;
}
/**
* The equal operator
* @param const Any &other the value we are comparing
* @return bool if the values are equal
*/
bool operator==(const Any& other) const { return Compare(*this, other, CompareType_Equal ); }
/**
* The friend equal operator.
* @param const Any &other the value we are comparing
* @return bool if the values are equal
*/
template<class T> friend bool operator==(const T& lhs, const Any& rhs){ return Compare(Any(lhs), rhs, CompareType_Equal); }
/**
* The friend equal operator.
* @param const Any &lhs the value we are comparing
* @param const T &rhs the rhs value we are comparing.
* @return bool if the values are equal
*/
template<class T> friend bool operator==(const Any& lhs, const T& rhs){ return Compare(lhs, Any(rhs), CompareType_Equal); }
/**
* The not equal operator
* @param const Any &other the value we are comparing
* @return bool if the values are _not_ equal
*/
bool operator!=(const Any &other) const{ return !Compare(*this, other, CompareType_Equal); }
/**
* The friend equal operator.
* @param const Any &other the value we are comparing
* @return bool if the values are equal
*/
template<class T> friend bool operator!=(const T& lhs, const Any& rhs){ return !Compare(Any(lhs), rhs, CompareType_Equal); }
/**
* The friend equal operator.
* @param const Any &other the value we are comparing
* @return bool if the values are equal
*/
template<class T> friend bool operator!=(const Any& lhs, const T& rhs){ return !Compare(lhs, Any(rhs), CompareType_Equal); }
/**
* Relational operator less than
* @param const Any& rhs
* @return bool if *this < rhs
*/
bool operator< (const Any& rhs) const { return Compare(*this, rhs, CompareType_LessThan ); }
/**
* Relational operator less than
* @param const Any& lhs
* @param const T& rhs
* @return bool if lhs < rhs
*/
template<class T> friend bool operator< (const Any& lhs, const T& rhs ){ return Compare(lhs, Any(rhs), CompareType_LessThan); }
/**
* Relational operator less than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs < rhs
*/
template<class T> friend bool operator< (const T& lhs, const Any& rhs) { return Compare(Any(lhs), rhs, CompareType_LessThan); }
/**
* Relational operator greater than
* @param const Any& rhs
* @return bool if lhs > rhs
*/
bool operator> (const Any& rhs) const { return Compare(*this, rhs, CompareType_MoreThan); }
/**
* Relational operator greater than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs > rhs
*/
template<class T> friend bool operator> (const T& lhs, const Any& rhs) { return Compare(Any(lhs), rhs, CompareType_MoreThan); }
/**
* Relational operator greater than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs > rhs
*/
template<class T> friend bool operator> (const Any& lhs, const T& rhs) { return Compare(lhs, Any(rhs), CompareType_MoreThan); }
/**
* Relational operator less or equal than
* @param const Any& rhs
* @return bool if lhs <= rhs
*/
bool operator<=(const Any& rhs) const { return !(*this > rhs); }
/**
* Relational operator less or equal than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs <= rhs
*/
template<class T> friend bool operator<=(const T& lhs, const Any& rhs) { return !(Any(lhs) > rhs); }
/**
* Relational operator less or equal than
* @param const Any& lhs
* @param const T& rhs
* @return bool if lhs <= rhs
*/
template<class T> friend bool operator<=(const Any& lhs, const T& rhs) { return !(lhs > Any(rhs)); }
/**
* Relational operator more or equal than
* @param const Any& rhs
* @return bool if lhs >= rhs
*/
bool operator>=(const Any& rhs) const { return !(*this < rhs); }
/**
* Relational operator more or equal than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs >= rhs
*/
template<class T> friend bool operator>=(const T& lhs, const Any& rhs) { return !(Any(lhs) < rhs); }
/**
* Relational operator more or equal than
* @param const T& lhs
* @param const Any& rhs
* @return bool if lhs >= rhs
*/
template<class T> friend bool operator>=(const Any& lhs, const T& rhs) { return !(lhs < Any(rhs)); }
//
// +operators
//
#ifdef _MSC_VER
# pragma region
#endif
/**
* Binary arithmetic operators - addition
* @param const Any& the item we are adding to this.
* @return Any& *this+rhs
*/
Any& operator+=(const Any& rhs)
{
if (rhs.UseUnsignedInteger())
{
return AddNumber(CalculateType(*this, rhs), (unsigned long long int)rhs._llivalue);
}
if (rhs.UseSignedInteger())
{
return AddNumber(CalculateType(*this, rhs), (long long int)rhs._llivalue);
}
return AddNumber(CalculateType(*this, rhs), rhs._ldvalue);
}
/**
* Default += function add the rhs to *this.
* @param const T& rhs the value we are adding to *this
* @param *this + rhs.
*/
template<class T>
Any& operator+=(T rhs)
{
*this += Any(rhs);
return *this;
}
/**
* Specialized += function add the rhs to *this.
* @param float rhs the value we are adding to *this
* @param *this + rhs.
*/
Any& operator+=(long double rhs)
{
return AddNumber(CalculateType(*this, dynamic::Floating_point_long_double), rhs);
}
/**
* Binary arithmetic operators - addition
* @param const Any& the item we are adding to this.
* @return Any *this+rhs
*/
Any operator+(const Any& rhs) const
{
// copy the value
Any value = *this;
// add the rhs
value += rhs;
// return the result.
return value;
}
/**
* Binary arithmetic operators - addition
* @param Any the item we are adding to this.
* @param const Any& the item we are adding to this.
* @return Any *this+rhs
*/
template<class T> friend Any operator+(const Any& lhs, const T& rhs) { auto tmp = lhs; tmp += rhs; return tmp; }
/**
* Binary arithmetic operators - addition
* @param Any the item we are adding to this.
* @param const Any& the item we are adding to this.
* @return Any *this+rhs
*/
template<class T> friend Any operator+(const T& lhs, const Any& rhs) { auto tmp = Any(lhs); tmp += rhs; return tmp; }
/**
* Add one to the current value.
* @return Any *this +1
*/
Any& operator++()
{
// save the current type.
dynamic::Type type = NumberType();
// add an int.
if (dynamic::is_type_floating(type))
{
// we cannot call ++_ldvalue as the value is passed by reference.
// to CreateFrom( cons T& ) and the first thing we do is clear the value
// so _ldvalue/_llivalue become 0
CreateFrom(_ldvalue + 1);
}
else
{
// we cannot call ++_ldvalue as the value is passed by reference.
// to CreateFrom( cons T& ) and the first thing we do is clear the value
// so _ldvalue/_llivalue become 0
CreateFrom(_llivalue + 1);
}
// update the type.
_type = CalculateType(type, dynamic::Integer_int);
// return this.
return *this;
}
/**
* Add one to the current value.
* @return Any *this +1
*/
Any operator++(int)
{
Any tmp(*this);
operator++();
return tmp;
}
//
// +operators
//
#ifdef _MSC_VER
# pragma endregion +=operators
#endif
//
// -operators
//
#ifdef _MSC_VER
# pragma region
#endif
/**
* Binary arithmetic operators - subtraction
* @param const Any& the item we are subtracting to this.
* @return Any& *this-rhs
*/
Any& operator-=(const Any& rhs)
{
if (rhs.UseUnsignedInteger())
{
return SubtractNumber(CalculateType(*this, rhs), (unsigned long long int)rhs._llivalue);
}
if (rhs.UseSignedInteger())
{
return SubtractNumber(CalculateType(*this, rhs), (long long int)rhs._llivalue);
}
return SubtractNumber(CalculateType(*this, rhs), rhs._ldvalue);
}
/**
* Default -= function substract the rhs to *this.
* @param const T& rhs the value we are subtracting from *this
* @param *this - rhs.
*/
template<class T>
Any& operator-=(T rhs)
{
*this -= Any(rhs);
return *this;
}
/**
* Specialized -= function substract the rhs to *this.
* @param int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param short rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(short int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_short_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param unsigned short int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(unsigned short int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_unsigned_short_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param unsigned int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(unsigned int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_unsigned_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param long int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(long int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_long_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param unsigned long int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(unsigned long int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_unsigned_long_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param long long int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(long long int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_long_long_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param unsigned long long int rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(unsigned long long int rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Integer_unsigned_long_long_int), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param float rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(float rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Floating_point_float), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param double rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(double rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Floating_point_double), rhs);
}
/**
* Specialized -= function substract the rhs to *this.
* @param float rhs the value we are subtracting from *this
* @param *this - rhs.
*/
Any& operator-=(long double rhs)
{
return SubtractNumber(CalculateType(*this, dynamic::Floating_point_long_double), rhs);
}
/**
* Binary arithmetic operators - substraction
* @param const Any& the item we are subtracting from *this.
* @return Any *this-rhs
*/
Any operator-(const Any& rhs) const
{
// copy the value
Any value = *this;
// substract the rhs
value -= rhs;
// return the result.
return value;
}
/**
* Binary arithmetic operators - substraction
* @param Any the item we are subtracting from *this.
* @param const Any& the item we are subtracting from *this.
* @return Any *this-rhs
*/
template<class T> friend Any operator-( const Any& lhs, const T& rhs) { auto tmp = lhs; tmp -= rhs; return tmp; }
/**
* Binary arithmetic operators - substraction
* @param Any the item we are subtracting from *this.
* @param const Any& the item we are subtracting from *this.
* @return Any *this-rhs
*/
template<class T> friend Any operator-(const T& lhs, const Any& rhs) { auto tmp = Any(lhs); tmp -= rhs; return tmp; }
/**
* substract one from the current value.
* @return Any *this -1
*/
Any& operator--()
{
// save the current type.
dynamic::Type type = NumberType();
// substract an int
// add an int.
if (dynamic::is_type_floating(type))
{