1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
14 * Szabo, Janos Zoltan – initial implementation
16 ******************************************************************************/
23 #include <openssl/bn.h>
28 #if !defined(LLONG_MAX) || !defined(LLONG_MIN)
29 #define LLONG_MAX 9223372036854775807LL
30 #define LLONG_MIN (-LLONG_MAX-1)
34 #define LLONG_MIN ((long long)(-LLONG_MAX-1))
42 typedef long long Int;
45 // Converts the Common::Int value to string.
46 string Int2string(const Int& i);
48 // Converts the string value to Common::Int. Throws Error_Int if conversion
49 // is not possible (e.g. value is out of range, or s is not a valid integer
51 Int string2Int(const char *s, const Location& loc);
52 inline Int string2Int(const string& s, const Location& loc)
53 { return string2Int(s.c_str(), loc); }
63 // Hide all BIGNUM related stuff here.
64 BIGNUM *to_openssl() const;
65 BIGNUM *get_val_openssl() const;
66 explicit int_val_t(BIGNUM *v) : native_flag(false), val() { val.openssl = v; }
70 int_val_t(const int_val_t& v);
71 int_val_t(const char *s, const Location& loc);
72 explicit int_val_t(Int v) : native_flag(true), val() { val.native = v; }
75 int_val_t operator-() const;
76 int_val_t operator>>(Int right) const;
77 int_val_t operator+(const int_val_t& right) const;
78 int_val_t operator-(const int_val_t& right) const;
79 inline int_val_t operator+(Int right) const { return operator+(int_val_t(right)); }
80 inline int_val_t operator-(Int right) const { return operator-(int_val_t(right)); }
81 int_val_t operator*(const int_val_t& right) const;
82 int_val_t operator/(const int_val_t& right) const;
83 int_val_t operator&(Int right) const;
84 bool operator<(const int_val_t& right) const;
85 inline bool operator<(Int right) const { return *this < int_val_t(right); }
86 inline bool operator>(Int right) const { return *this > int_val_t(right); }
87 inline bool operator>(const int_val_t& right) const { return *this != right && !(*this < right); }
88 inline bool operator<=(Int right) const { return *this == right || *this < right; }
89 inline bool operator>=(Int right) const { return *this == right || *this > right; }
90 inline bool operator<=(const int_val_t& right) const { return *this == right || *this < right; }
91 inline bool operator>=(const int_val_t& right) const { return *this == right || *this > right; }
92 inline bool operator!=(Int right) const { return !(*this == right); }
93 inline bool operator!=(const int_val_t& right) const { return !(*this == right); }
94 bool operator==(const int_val_t& right) const;
95 bool operator==(Int right) const;
96 int_val_t& operator=(const int_val_t& right);
97 int_val_t& operator+=(Int right);
98 int_val_t& operator<<=(Int right);
99 int_val_t& operator>>=(Int right);
100 const Int& get_val() const;
101 Real to_real() const;
102 inline bool is_native_fit() const
103 // It seems to give correct results (-2147483648..2147483647).
104 { return native_flag && val.native == static_cast<RInt>(val.native); }
105 inline bool is_native() const { return native_flag; }
106 inline bool is_openssl() const { return !native_flag; }
107 inline bool is_negative() const
108 { return native_flag ? val.native < 0 : BN_is_negative(val.openssl); }