1 | #include "mod2.h" |
---|
2 | |
---|
3 | #ifdef HAVE_WRAPPERS |
---|
4 | |
---|
5 | #include "PolyWrapper.h" |
---|
6 | #include "CanonicalPoly.h" |
---|
7 | #include "Wrappers.h" |
---|
8 | #include <iostream> |
---|
9 | #include "febase.h" |
---|
10 | |
---|
11 | PolyWrapper PolyWrapper::operator+ (const PolyWrapper& p) const |
---|
12 | { |
---|
13 | +prpr > "PolyWrapper::operator+ called"; |
---|
14 | prpr+1; |
---|
15 | +prpr > "first argument = " < this->toString(); |
---|
16 | +prpr > "second argument = " < p.toString(); |
---|
17 | prpr-1; |
---|
18 | PolyWrapper q(this->getInternPoly()->deepCopy()); // deep copy of given PolyWrapper |
---|
19 | q.getInternPoly()->add(p.getInternPoly()); |
---|
20 | return q; |
---|
21 | } |
---|
22 | |
---|
23 | PolyWrapper& PolyWrapper::operator+= (const PolyWrapper& p) |
---|
24 | { |
---|
25 | +prpr > "PolyWrapper::operator+= called"; |
---|
26 | prpr+1; |
---|
27 | +prpr > "first argument = " < this->toString(); |
---|
28 | +prpr > "second argument = " < p.toString(); |
---|
29 | prpr-1; |
---|
30 | if (this->getInternPoly()->isShared()) |
---|
31 | { |
---|
32 | m_pInternPoly->decrement(); |
---|
33 | m_pInternPoly = m_pInternPoly->deepCopy(); |
---|
34 | } |
---|
35 | this->getInternPoly()->add(p.getInternPoly()); |
---|
36 | return *this; |
---|
37 | } |
---|
38 | |
---|
39 | const RingWrapper& PolyWrapper::getRing () const |
---|
40 | { |
---|
41 | return m_pInternPoly->getRing(); |
---|
42 | } |
---|
43 | |
---|
44 | PolyWrapper::PolyWrapper (): m_pInternPoly(0) |
---|
45 | { |
---|
46 | assume(false); // the default constructor, i.e. the one |
---|
47 | // without arguments should never be called |
---|
48 | } |
---|
49 | |
---|
50 | PolyWrapper::PolyWrapper (InternPoly* ip): m_pInternPoly(ip) |
---|
51 | { |
---|
52 | +prpr > "PolyWrapper constructor with argument InternPoly*"; |
---|
53 | } |
---|
54 | |
---|
55 | PolyWrapper::~PolyWrapper () |
---|
56 | { |
---|
57 | +prpr > "PolyWrapper destructor, object = " < this->toString(); |
---|
58 | InternPoly* p_ip = this->getInternPoly(); |
---|
59 | p_ip->decrement(); |
---|
60 | if (p_ip->getCounter() == 0) delete p_ip; |
---|
61 | } |
---|
62 | |
---|
63 | PolyWrapper::PolyWrapper (const PolyWrapper& p) |
---|
64 | { |
---|
65 | +prpr > "creating a shallow copy of PolyWrapper, argument = " < p.toString(); |
---|
66 | m_pInternPoly = p.getInternPoly(); |
---|
67 | m_pInternPoly->increment(); |
---|
68 | } |
---|
69 | |
---|
70 | PolyWrapper& PolyWrapper::operator= (const PolyWrapper& p) |
---|
71 | { |
---|
72 | +prpr > "assignment operator of PolyWrapper, argument = " < p.toString(); |
---|
73 | prpr+1; |
---|
74 | +prpr > "working with PolyWrapper " < this->toString(); |
---|
75 | prpr+1; |
---|
76 | m_pInternPoly->decrement(); |
---|
77 | if (m_pInternPoly->getCounter() == 0) delete m_pInternPoly; |
---|
78 | m_pInternPoly = p.getInternPoly(); |
---|
79 | prpr-1; |
---|
80 | +prpr > "working with PolyWrapper " < this->toString(); |
---|
81 | prpr+1; |
---|
82 | m_pInternPoly->increment(); |
---|
83 | prpr-2; |
---|
84 | +prpr > "assignment of PolyWrapper completed"; |
---|
85 | return *this; |
---|
86 | } |
---|
87 | |
---|
88 | void PolyWrapper::print () const |
---|
89 | { |
---|
90 | PrintS(this->toString()); |
---|
91 | } |
---|
92 | |
---|
93 | void PolyWrapper::printLn () const |
---|
94 | { |
---|
95 | PrintS(this->toString()); |
---|
96 | PrintLn(); |
---|
97 | } |
---|
98 | |
---|
99 | char* PolyWrapper::toString () const |
---|
100 | { |
---|
101 | InternPoly* pip = this->getInternPoly(); |
---|
102 | return pip->toString(); |
---|
103 | } |
---|
104 | |
---|
105 | InternPoly* PolyWrapper::getInternPoly () const |
---|
106 | { |
---|
107 | return m_pInternPoly; |
---|
108 | } |
---|
109 | |
---|
110 | PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) { |
---|
111 | +prpr > "creating a new PolyWrapper (internal type: CanonicalPoly)"; |
---|
112 | m_pInternPoly = new CanonicalPoly(i, r); |
---|
113 | } |
---|
114 | |
---|
115 | #endif // HAVE_WRAPPERS |
---|