bbd0e313235f12db36e364d94d8179be59cfe44a
[deliverable/titan.core.git] / core / RInt.hh
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
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Kovacs, Ferenc
11 * Raduly, Csaba
12 *
13 ******************************************************************************/
14 #ifndef RInt_HH
15 #define RInt_HH
16
17 struct bignum_st;
18 typedef bignum_st BIGNUM;
19
20 typedef int RInt;
21
22 class int_val_t
23 {
24 private:
25 friend class INTEGER;
26 friend class INTEGER_template;
27
28 bool native_flag;
29 union {
30 RInt native;
31 BIGNUM *openssl;
32 } val;
33
34 public:
35 int_val_t();
36 int_val_t(const int_val_t& v);
37 explicit int_val_t(const char *s);
38 explicit int_val_t(RInt v) : native_flag(true) { val.native = v; }
39 explicit int_val_t(BIGNUM *v) : native_flag(false) { val.openssl = v; }
40 ~int_val_t();
41 /** Returns a newly allocated string. Caller must call Free() */
42 char *as_string() const;
43 const RInt& get_val() const;
44 BIGNUM *get_val_openssl() const;
45 double to_real() const;
46 int_val_t operator&(RInt right) const;
47 bool operator==(const int_val_t& right) const;
48 bool operator<(const int_val_t& right) const;
49
50 inline bool operator!=(const int_val_t& right) const { return !(*this == right); }
51 inline bool operator>(const int_val_t& right) const { return *this != right && !(*this < right); }
52 inline bool operator>=(const int_val_t& right) const { return *this == right || *this > right; }
53 inline bool operator<=(const int_val_t& right) const { return *this == right || *this < right; }
54 inline bool operator==(RInt right) const { return *this == int_val_t(right); }
55 inline bool operator!=(RInt right) const { return !(*this == right); }
56 inline bool operator>(RInt right) const { return *this != right && !(*this < right); }
57 inline bool operator<(RInt right) const { return *this != right && *this < int_val_t(right); }
58 inline bool operator<=(RInt right) const { return *this == right || *this < right; }
59 inline bool operator>=(RInt right) const { return *this == right || *this > right; }
60
61 int_val_t& operator=(const int_val_t& right);
62 int_val_t& operator=(RInt right);
63 int_val_t& operator+=(RInt right);
64 int_val_t& operator<<=(RInt right);
65 int_val_t& operator>>=(RInt right);
66 inline bool is_native() const { return native_flag; }
67 bool is_negative() const;
68 };
69
70 BIGNUM *to_openssl(RInt other_value);
71 RInt string2RInt(const char *s);
72
73 #endif // RInt_HH
This page took 0.031903 seconds and 4 git commands to generate.