RInt.hh 2.57 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/******************************************************************************
 * Copyright (c) 2000-2016 Ericsson Telecom AB
 * 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

ebensza's avatar
ebensza committed
17
#include <openssl/ossl_typ.h>
Elemer Lelik's avatar
Elemer Lelik committed
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

typedef int RInt;

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

  bool native_flag;
  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);
  explicit int_val_t(RInt v) : native_flag(true) { val.native = v; }
  explicit int_val_t(BIGNUM *v) : native_flag(false) { val.openssl = v; }
  ~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;
  bool operator==(const int_val_t& right) const;
  bool operator<(const int_val_t& right) const;

  inline bool operator!=(const int_val_t& right) const { return !(*this == right); }
  inline bool operator>(const int_val_t& right) const { return *this != right && !(*this < right); }
  inline bool operator>=(const int_val_t& right) const { return *this == right || *this > right; }
  inline bool operator<=(const int_val_t& right) const { return *this == right || *this < right; }
  inline bool operator==(RInt right) const { return *this == int_val_t(right); }
  inline bool operator!=(RInt right) const { return !(*this == right); }
  inline bool operator>(RInt right) const { return *this != right && !(*this < right); }
  inline bool operator<(RInt right) const { return *this != right && *this < int_val_t(right); }
  inline bool operator<=(RInt right) const { return *this == right || *this < right; }
  inline bool operator>=(RInt right) const { return *this == right || *this > right; }

  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);
  inline bool is_native() const { return native_flag; }
  bool is_negative() const;
};

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

#endif  // RInt_HH