Ejemplo n.º 1
0
FTSelection *FTDistanceLiteral::optimize(FTContext *ftcontext, bool execute) const
{
    XPath2MemoryManager *mm = ftcontext->context->getMemoryManager();

    FTSelection *newarg = arg_->optimize(ftcontext, execute);
    if(newarg == 0) return 0;

    if(newarg->getType() == WORD) {
        return newarg;
    }

    newarg = new (mm) FTDistanceLiteral(newarg, type_, distance_, distance2_, unit_, mm);
    newarg->setLocationInfo(this);
    return newarg;
}
Ejemplo n.º 2
0
FTSelection *FTOrder::optimize(FTContext *ftcontext) const
{
  XPath2MemoryManager *mm = ftcontext->context->getMemoryManager();

  FTSelection *newarg = arg_->optimize(ftcontext);
  if(newarg == 0) return 0;

  if(newarg->getType() == WORD) {
    return newarg;
  }

  newarg = new (mm) FTOrder(newarg, mm);
  newarg->setLocationInfo(this);
  return newarg;
}
Ejemplo n.º 3
0
FTSelection *FTDistance::optimize(FTContext *ftcontext, bool execute) const
{
    XPath2MemoryManager *mm = ftcontext->context->getMemoryManager();

    if(execute || range_.arg1->isConstant()) {
        Result rangeResult = range_.arg1->createResult(ftcontext->context);
        Numeric::Ptr num = (Numeric::Ptr)rangeResult->next(ftcontext->context);
        long distance = ::atol(UTF8(num->asString(ftcontext->context)));

        switch(range_.type) {
        case FTRange::EXACTLY: {
            FTSelection *result = new (mm) FTDistanceLiteral(arg_, FTRange::EXACTLY, distance, 0, unit_, mm);
            result->setLocationInfo(this);
            return result->optimize(ftcontext, execute);
        }
        case FTRange::AT_LEAST: {
            FTSelection *result = new (mm) FTDistanceLiteral(arg_, FTRange::AT_LEAST, distance, 0, unit_, mm);
            result->setLocationInfo(this);
            return result->optimize(ftcontext, execute);
        }
        case FTRange::AT_MOST: {
            FTSelection *result = new (mm) FTDistanceLiteral(arg_, FTRange::AT_MOST, distance, 0, unit_, mm);
            result->setLocationInfo(this);
            return result->optimize(ftcontext, execute);
        }
        case FTRange::FROM_TO: {
            Result rangeResult2 = range_.arg2->createResult(ftcontext->context);
            Numeric::Ptr num2 = (Numeric::Ptr)rangeResult2->next(ftcontext->context);
            long distance2 = ::atol(UTF8(num->asString(ftcontext->context)));

            FTSelection *result = new (mm) FTDistanceLiteral(arg_, FTRange::FROM_TO, distance, distance2, unit_, mm);
            result->setLocationInfo(this);
            return result->optimize(ftcontext, execute);
        }
        }
    }

    FTSelection *newarg = arg_->optimize(ftcontext, execute);
    if(newarg == 0) return 0;

    if(newarg->getType() == WORD) {
        return newarg;
    }

    newarg = new (mm) FTDistance(range_, unit_, newarg, mm);
    newarg->setLocationInfo(this);
    return newarg;
}