Ejemplo n.º 1
0
void Calc::Minimum(const ValueList& args, KValueRef result)
{
	if (args.at(0)->IsList())
	{
		KListRef list = args.at(0)->ToList();

		double *arr = NULL;

		arr = new double[list->Size()];

		for (unsigned int c = 0; c < list->Size(); c++)
		{
			KValueRef d = list->At(c);
			arr[c] = d->ToDouble();
		}

		double low = Min(arr, list->Size());

		result->SetDouble(low);

		delete [] arr;

   } else {
		throw ValueException::FromString("Minimum takes an array");
   }

}
Ejemplo n.º 2
0
double KObject::GetDouble(const char* name, double defaultValue)
{
    KValueRef prop = this->Get(name);
    if (prop->IsDouble())
    {
        return prop->ToDouble();
    }
    else
    {
        return defaultValue;
    }
}
Ejemplo n.º 3
0
 void convert (Statement &select, KValueRef arg)
 {
     if (arg->IsString())
     {
         std::string *s = new std::string(arg->ToString()); 
         select , use(*s);
         strings.push_back(s);
     }
     else if (arg->IsInt())
     {
         int *i = new int(arg->ToInt());
         select , use(*i);
         ints.push_back(i);
     }
     else if (arg->IsDouble())
     {
         double *d = new double(arg->ToDouble());
         select , use(*d);
         doubles.push_back(d);
     }
     else if (arg->IsBool())
     {
         bool *b = new bool(arg->ToBool());
         select , use(*b);
         bools.push_back(b);
     }
     else if (arg->IsNull() || arg->IsUndefined())
     {
         // in this case, we bind a null string (dequoted)
         std::string *s = new std::string("null");
         select , use(s);
         strings.push_back(s);
     }
     else
     {
         throw ValueException::FromFormat("Unsupport type for argument: %s",
             arg->GetType().c_str());
     }
 }