Macaulay2 Engine
Loading...
Searching...
No Matches
fromStream.cpp
Go to the documentation of this file.
1// Read an object from the given stream.
2// 'result' must be previously 'init'ed
3// 'i' is incremented to directly past the part read
4// an exception is raised on bad input?
5
34
35#include "RingTest.hpp"
36#include "aring-zzp.hpp"
37#include "ZZp.hpp"
38
39template <typename T>
40std::istream &fromStream(std::istream &i,
41 const T &R,
42 typename T::ElementType &result);
43
44template <typename T>
45bool fromStream(std::istream &i, const T &R, ring_elem &result);
46
47template <>
48std::istream &fromStream<M2::ARingZZp>(std::istream &i,
49 const M2::ARingZZp &R,
51{
52 int a;
53 i >> a;
55 return i;
56}
57
58template <>
59bool fromStream<Z_mod>(std::istream &i, const Z_mod &R, ring_elem &result)
60{
61 while (isspace(i.peek())) i.get();
62
63 if (!isdigit(i.peek()) && i.peek() != '+' && i.peek() != '-') return false;
64
65 int a;
66 i >> a;
67 result = R.from_long(a);
68 return true;
69}
70
71template <>
72bool fromStream<RingZZ>(std::istream &i, const RingZZ &R, ring_elem &result)
73{
74 while (isspace(i.peek())) i.get();
75
76 if (!isdigit(i.peek()) && i.peek() != '+' && i.peek() != '-') return false;
77
78 const int original_s_len = 100;
79 char original_s[original_s_len];
80 char *s_str = original_s;
81 char *s = s_str;
82 // int s_len = original_s_len;
83 // int len = 0;
84 while (isdigit(i.peek()))
85 {
86 // NOT DONE BEING WRITTEN!!!!!!
87 }
88 *s++ = '\0';
89
90 int a;
91 i >> a;
92 result = R.from_long(a);
93 return true;
94}
95
96// Local Variables:
97// compile-command: "make -C $M2BUILDDIR/Macaulay2/e/unit-tests check "
98// indent-tabs-mode: nil
99// End:
Shared gtest fixture for the legacy Ring-based Ring*Test.cpp suite.
Legacy Z_mod — a Ring-derived Z/p with log / exp tables.
M2::ARingZZp — portable Z/p for small primes via log / exp tables.
void set_from_long(elem &result, long a) const
aring-style adapter for Z/p using a discrete-log (Zech) representation: every non-zero residue is its...
Definition aring-zzp.hpp:67
virtual ring_elem from_long(long n) const
Definition ZZ.cpp:110
Engine-side ring of integers, backed by GMP mpz_ptr elements.
Definition ZZ.hpp:77
virtual ring_elem from_long(long n) const
Definition ZZp.cpp:132
Engine-side Z/p ring for small primes (p < 32767), using a discrete-log (Zech) representation.
Definition ZZp.hpp:63
std::istream & fromStream< M2::ARingZZp >(std::istream &i, const M2::ARingZZp &R, M2::ARingZZp::ElementType &result)
bool fromStream< Z_mod >(std::istream &i, const Z_mod &R, ring_elem &result)
std::istream & fromStream(std::istream &i, const T &R, typename T::ElementType &result)
bool fromStream< RingZZ >(std::istream &i, const RingZZ &R, ring_elem &result)
void size_t s
Definition m2-mem.cpp:271
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define T
Definition table.c:13