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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#ifndef IDEAL_CPP_HEADER
#define IDEAL_CPP_HEADER
#include <vector>
#include "Poly.h"
#include "kernel/ideals.h"
//base for ideals as well for modules
//doesn't need a destructor, as Polys will destroy itself
template <class poly_type> class IdealBase
{
protected:
std::vector<poly_type> storage;
public:
typedef poly_type value_type;
typedef typename std::vector<poly_type>::size_type size_type;
typedef typename std::vector<poly_type>::iterator iterator;
typedef typename std::vector<poly_type>::difference_type difference_type;
typedef typename std::vector<poly_type>::allocator_type allocator_type;
IdealBase(){}
IdealBase(iterator first,
iterator last,
const typename
std::vector<poly_type>::allocator_type& __a = allocator_type()):
storage(first,last,__a)
{}
ring getRing() const
{
//FIXME: is a hack
if (size()>0)
{
return storage[0].getRing();
}
else
return (ring) NULL;
}
poly_type& operator[] (int n)
{
return storage[n];
}
const poly_type& operator[](int n) const
{
return storage[n];
}
void push_back(const poly_type& p)
{
storage.push_back(p);
}
void push_front(const poly_type& p)
{
storage.push_front(p);
}
iterator begin()
{
return storage.begin();
}
iterator end()
{
return storage.end();
}
size_type size() const
{
return storage.size();
}
iterator
insert(iterator __position, const value_type& __x)
{
return storage.insert(__position,__x);
}
iterator
erase(iterator __position)
{
return storage.erase(__position);
}
iterator
erase(iterator __first, iterator __last)
{
return storage.erase(__first,__last);
}
void insert(iterator __pos, iterator __first, iterator __last)
{
return insert(__pos,__first,__last);
}
};
class Ideal:
public IdealBase<Poly>
{
public:
Ideal(){}
Ideal(ideal i, ring r)
{
for(int j=0;j<IDELEMS(i);j++)
{
storage.push_back(Poly(i->m[j],r));
}
}
Ideal(iterator first,
iterator last,
const allocator_type& __a = allocator_type()):
IdealBase<Poly>(first,last,__a){}
ideal as_ideal() const
{
//no checks for rings
int s=size();
if (s==0) s=1;
ideal result=idInit(s,1);
result->m[0]=NULL;
s=size();
for(int i=0;i<s;i++)
{
result->m[i]=storage[i].as_poly();
}
return result;
}
};
class Module:
public IdealBase<Vector>
{
public:
Module(ideal i, ring r)
{
for(int j=0;j<IDELEMS(i);j++)
{
storage.push_back(Vector(i->m[j],r));
}
}
ideal as_module() const
{
//no checks for rings
int s=size();
if (s==0)
s=1;
ideal result=idInit(s,1);
result->m[0]=NULL;
s=size();
for(int i=0;i<s;i++)
{
result->m[i]=storage[i].as_poly();
}
if (size()==0)
result->rank=0;
else
result->rank=id_RankFreeModule(result,storage[0].getRing());
return result;
}
Module(iterator first,
iterator last,
const allocator_type& __a = allocator_type()):
IdealBase<Vector>(first,last,__a)
{}
Module()
{}
};
#endif
|