Macaulay2 Engine
Loading...
Searching...
No Matches

◆ read_poly_n()

TowerPolynomial DPoly::read_poly_n ( char *& str,
int level )
staticprivate

Definition at line 301 of file dpoly.cpp.

302{
303 int len = 0;
304 TowerPolynomial *elems = newarray(TowerPolynomial, 100);
305 TowerPolynomial this_elem = nullptr;
306 if (*str != '[')
307 {
308 fprintf(stderr, "expected '[', got %s\n", str);
309 exit(1);
310 }
311 str++;
312 // Now loop
313 while (*str != ']')
314 {
315 while (isspace(*str)) str++;
316 if (*str == ',')
317 {
318 str++;
319 }
320 else if (*str == '[')
321 {
322 this_elem = read_poly(str, level - 1); // eats ]
323 while (isspace(*str)) str++;
324 if (*str == ',') str++;
325 }
326 else
327 {
328 fprintf(stderr, "expected , or [, but got %s\n", str);
329 exit(1);
330 }
331 elems[len++] = this_elem;
332 this_elem = nullptr;
333 }
334 // the only way to get here is if *str == ']'. Eat that char.
335 str++;
336 TowerPolynomial result = DPoly::alloc_poly_n(len - 1, elems);
337 freemem(elems);
338 return result;
339}
static TowerPolynomial read_poly(char *&str, int level)
Definition dpoly.cpp:383
static TowerPolynomial alloc_poly_n(int deg, TowerPolynomial *elems=nullptr)
Definition dpoly.cpp:265
void freemem(void *s)
Definition m2-mem.cpp:103
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define newarray(T, len)
Definition newdelete.hpp:82

References alloc_poly_n(), freemem(), newarray, read_poly(), and result().

Referenced by read_poly().