~danielturcanu/zorba/web_crawler_tutorial

« back to all changes in this revision

Viewing changes to src/functions/func_sequences_impl.cpp

  • Committer: danielturcanu
  • Date: 2011-12-14 14:07:55 UTC
  • mfrom: (10469.2.114 zorba)
  • Revision ID: danielturcanu@gmail.com-20111214140755-woxoovqq4hv5dcw3
Update to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
261
261
  {
262
262
    xs_double dpos = static_cast<const const_expr*>(posExpr)->
263
263
                      get_val()->getDoubleValue().round();
264
 
    long pos = static_cast<long>(dpos.getNumber());
 
264
    xs_integer ipos(dpos.getNumber());
265
265
 
266
266
    xs_double dlen = static_cast<const const_expr*>(lenExpr)->
267
267
                      get_val()->getDoubleValue().round();
268
 
    long len = static_cast<long>(dlen.getNumber());
 
268
    xs_integer ilen(dlen.getNumber());
 
269
 
 
270
    xs_long pos;
 
271
    xs_long len;
 
272
 
 
273
    try
 
274
    {
 
275
      pos = to_xs_long(ipos);
 
276
      len = to_xs_long(ilen);
 
277
    }
 
278
    catch (std::range_error&)
 
279
    {
 
280
      goto done;
 
281
    }
269
282
 
270
283
    const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
271
284
 
272
 
    ulong numSteps = pathExpr->numSteps();
 
285
    csize numSteps = pathExpr->numSteps();
273
286
 
274
287
    if (pos > 0 && len == 1 && numSteps == 2)
275
288
    {
281
294
    }
282
295
  }
283
296
 
 
297
 done:
284
298
  return new FnSubsequenceIterator(aSctx, aLoc, aArgs);
285
299
}
286
300
 
319
333
      lenExpr != NULL &&
320
334
      lenExpr->get_expr_kind() == const_expr_kind)
321
335
  {
322
 
    xs_long pos = static_cast<const const_expr*>(posExpr)->
323
 
                      get_val()->getLongValue();
 
336
    xs_long pos;
 
337
    xs_long len;
324
338
 
325
 
    xs_long len = static_cast<const const_expr*>(lenExpr)->
326
 
                      get_val()->getLongValue();
 
339
    try
 
340
    {
 
341
      pos = static_cast<const const_expr*>(posExpr)->get_val()->getLongValue();
 
342
      len = static_cast<const const_expr*>(lenExpr)->get_val()->getLongValue();
 
343
    }
 
344
    catch (std::range_error&)
 
345
    {
 
346
      goto done;
 
347
    }
327
348
 
328
349
    const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
329
350
 
330
 
    ulong numSteps = pathExpr->numSteps();
 
351
    csize numSteps = pathExpr->numSteps();
331
352
 
332
353
    if (pos > 0 && len == 1 && numSteps == 2)
333
354
    {
367
388
    }
368
389
  }
369
390
 
 
391
 done:
370
392
  return new SubsequenceIntIterator(aSctx, aLoc, aArgs);
371
393
}
372
394
 
402
424
  if (posExpr->get_expr_kind() == const_expr_kind)
403
425
  {
404
426
    store::Item* posItem = static_cast<const const_expr*>(posExpr)->get_val();
405
 
    xs_long pos = posItem->getLongValue();
 
427
 
 
428
    xs_integer pos = posItem->getIntegerValue();;
406
429
 
407
430
    if (inputExpr->get_expr_kind() == relpath_expr_kind)
408
431
    {
409
432
      const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
410
433
 
411
 
      ulong numSteps = pathExpr->numSteps();
 
434
      csize numSteps = pathExpr->numSteps();
412
435
 
413
 
      if (pos > 0 && numSteps == 2)
 
436
      if (pos > Integer(0) && numSteps == 2)
414
437
      {
 
438
        xs_long pos2;
 
439
        try
 
440
        {
 
441
          pos2 = posItem->getLongValue();
 
442
        }
 
443
        catch (std::range_error&)
 
444
        {
 
445
          goto done;
 
446
        }
 
447
 
415
448
        AxisIteratorHelper* input = dynamic_cast<AxisIteratorHelper*>(aArgs[0].getp());
416
449
        assert(input != NULL);
417
450
 
418
 
        if (input->setTargetPos(pos-1))
 
451
        if (input->setTargetPos(pos2 - 1))
419
452
          return aArgs[0];
420
453
      }
421
454
    }
457
490
      return aArgs[0];
458
491
  }
459
492
 
 
493
 done:
460
494
  return new SequencePointAccessIterator(aSctx, aLoc, aArgs);
461
495
}
462
496