File: ARingElem.hpp

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (81 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download
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
#ifndef _aring_elem_hpp_
#define _aring_elem_hpp_

template<typename RT>  // RT = ring type, a type of ARing, should be a concept
class ARingElem
{
public:
  using Element = typename RT::ElementType;

  ARingElem(const RT* F)
    : mRing(F)
  {
    // init sets it equal to 0 (?)
    mRing->init(mElement);
  }
  ARingElem(const RT* F, const Element& f)
    : mRing(F)
  {
    mRing->init_set(mElement,f);
  }
  ~ARingElem()
  {
    mRing->clear(mElement);
  }
  const ARing& ring() const
  {
    return *mRing;
  }
  Element& operator*()
  {
    return mElement;
  }
  const Element& operator*() const
  {
    return mElement;
  }
  bool operator==(const ARingElem& g) const
  {
    assert(mRing == g.mRing);
    return mRing->is_equal(mElement,*g);
  }
  ARingElem operator+(const ARingElem& g)
  {
    assert(mRing == g.mRing);
    ARingElem result(mRing);
    mRing->add(*result, mElement, *g);
    return result;
  }
  ARingElem operator-(const ARingElem& g)
  {
    assert(mRing == g.mRing);
    ARingElem result(mRing);
    mRing->subtract(*result, mElement, *g);
    return result;
  }
  ARingElem operator-() const
  {
    ARingElem result(mRing);
    mRing->negate(*result, mElement);
    return result;
  }
  ARingElem operator*(const ARingElem& g)
  {
    assert(mRing == g.mRing);
    ARingElem result(mRing);
    mRing->mult(*result, mElement, *g);
    return result;
  }
  // also add operator *= and += etc
  ARingElem operator^(int n)
  {
    ARingElem result(mRing);
    mRing->power(*result, mElement, n);
    return result;
  }
private:
  const RT* mRing;
  Element mElement;
};

#endif