RInt.hh 2.65 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
Lenard Nagy's avatar
Lenard Nagy committed
2
 * Copyright (c) 2000-2017 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
4
5
6
7
8
9
10
11
12
13
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
14
15
16
#ifndef RInt_HH
#define RInt_HH

17
18
#include "Types.h"

19
20
struct bignum_st;
typedef bignum_st BIGNUM;
Elemer Lelik's avatar
Elemer Lelik committed
21
22
23
24
25
26
27
28
29

typedef int RInt;

class int_val_t
{
private:
  friend class INTEGER;
  friend class INTEGER_template;

30
  boolean native_flag;
Elemer Lelik's avatar
Elemer Lelik committed
31
32
33
34
35
36
37
38
39
  union {
    RInt native;
    BIGNUM *openssl;
  } val;

public:
  int_val_t();
  int_val_t(const int_val_t& v);
  explicit int_val_t(const char *s);
40
41
  explicit int_val_t(RInt v) : native_flag(TRUE) { val.native = v; }
  explicit int_val_t(BIGNUM *v) : native_flag(FALSE) { val.openssl = v; }
Elemer Lelik's avatar
Elemer Lelik committed
42
43
44
45
46
47
48
  ~int_val_t();
  /** Returns a newly allocated string. Caller must call Free() */
  char *as_string() const;
  const RInt& get_val() const;
  BIGNUM *get_val_openssl() const;
  double to_real() const;
  int_val_t operator&(RInt right) const;
49
50
  boolean operator==(const int_val_t& right) const;
  boolean operator<(const int_val_t& right) const;
Elemer Lelik's avatar
Elemer Lelik committed
51

52
53
54
55
56
57
58
59
60
61
  inline boolean operator!=(const int_val_t& right) const { return !(*this == right); }
  inline boolean operator>(const int_val_t& right) const { return *this != right && !(*this < right); }
  inline boolean operator>=(const int_val_t& right) const { return *this == right || *this > right; }
  inline boolean operator<=(const int_val_t& right) const { return *this == right || *this < right; }
  inline boolean operator==(RInt right) const { return *this == int_val_t(right); }
  inline boolean operator!=(RInt right) const { return !(*this == right); }
  inline boolean operator>(RInt right) const { return *this != right && !(*this < right); }
  inline boolean operator<(RInt right) const { return *this != right && *this < int_val_t(right); }
  inline boolean operator<=(RInt right) const { return *this == right || *this < right; }
  inline boolean operator>=(RInt right) const { return *this == right || *this > right; }
Elemer Lelik's avatar
Elemer Lelik committed
62
63
64
65
66
67

  int_val_t& operator=(const int_val_t& right);
  int_val_t& operator=(RInt right);
  int_val_t& operator+=(RInt right);
  int_val_t& operator<<=(RInt right);
  int_val_t& operator>>=(RInt right);
68
69
  inline boolean is_native() const { return native_flag; }
  boolean is_negative() const;
Elemer Lelik's avatar
Elemer Lelik committed
70
71
72
73
74
75
};

BIGNUM *to_openssl(RInt other_value);
RInt string2RInt(const char *s);

#endif  // RInt_HH