示例#1
0
/* (non-Javadoc)
 * @see Expression#evaluate(IVariablePool)
 */
EvaluationResult::ConstPointer
AdaptExpression::Evaluate(IEvaluationContext* context) const
{
  if (fTypeName.size() == 0)
    return EvaluationResult::FALSE_EVAL;
  Object::ConstPointer var = context->GetDefaultVariable();
  Object::ConstPointer adapted;
  IAdapterManager* manager = Platform::GetAdapterManager();
  if (Expressions::IsInstanceOf(var.GetPointer(), fTypeName))
  {
    adapted = var;
  }
  else
  {
    if (!manager->HasAdapter(var.GetPointer(), fTypeName))
      return EvaluationResult::FALSE_EVAL;

    adapted = manager->GetAdapter(var.GetPointer(), fTypeName);
  }
  // the adapted result is null but hasAdapter returned TRUE_EVAL check
  // if the adapter is loaded.
  if (adapted.IsNull())
  {
    if (manager->QueryAdapter(var.GetPointer(), fTypeName) == IAdapterManager::NOT_LOADED)
    {
      return EvaluationResult::NOT_LOADED;
    }
    else
    {
      return EvaluationResult::FALSE_EVAL;
    }
  }
  DefaultVariable scope(context, adapted);
  return this->EvaluateAnd(&scope);
}
示例#2
0
  bool
  Expressions::IsInstanceOf(Object::ConstPointer element, const std::string& type)
  {
    // null isn't an instanceof of anything.
    if (element.IsNull())
      return false;

    // TODO Reflection
    // return IsSubtype(element, type)

    return element->GetClassName() == type;
  }