QString TWInteger::int2QString(int i)
{
	 QString retValue("");
	 if (i==0)
	 {
	 		retValue.append("0"); 
	 }
	 else
	 {	 
		 int digits=(int) floor(log10((double)i));
		 int u = i;
		 for (int count=0; count<=digits; count++)
		 {
	 			switch(u % 10)
				{
					case 0: retValue.prepend("0"); break;
					case 1: retValue.prepend("1"); break;
					case 2: retValue.prepend("2"); break;
					case 3: retValue.prepend("3"); break;
					case 4: retValue.prepend("4"); break;
					case 5: retValue.prepend("5"); break;
					case 6: retValue.prepend("6"); break;
					case 7: retValue.prepend("7"); break;
					case 8: retValue.prepend("8"); break;
					case 9: retValue.prepend("9"); break;				
				}
				u /= 10;					
		 }		 
	 }
	 return retValue;	 
}
Exemple #2
0
string trim(string &str)
{
	const char* tmp = str.c_str();
	for(;*tmp != '\0';tmp++)
	{
		if(*tmp != 32 && *tmp !=9)
			break;
	}
	if(*tmp == '\0')
	{
		return "";
	}
	else
	{
		const char* end = str.c_str() + str.length() - 1;
		for(;end >= tmp;end--)
		{
			if(*end != 32 && *end != 9)
				break;
		}
		string retValue(tmp,end - tmp + 1);
		return retValue;
	}
	return "";
}
GVectBase<GReal, 2> GAnimTRSNode2D::Scale(const GTimeValue TimePos, const GSpaceSystem Space, GTimeInterval& ValidInterval) const {

	GProperty *tmpProp = Property("transform");

	if (!tmpProp)
		return GVector2(1, 1);

	tmpProp = tmpProp->Property("scale");
	G_ASSERT(tmpProp);
	GTimeInterval tmpValid = G_FOREVER_TIMEINTERVAL;
	GKeyValue xValue, yValue;

	// extract scale
	GProperty *xProp = tmpProp->Property("x");
	GProperty *yProp = tmpProp->Property("y");
	G_ASSERT(xProp != NULL);
	G_ASSERT(yProp != NULL);
	GError xErr = xProp->Value(xValue, tmpValid, TimePos, G_ABSOLUTE_VALUE);
	GError yErr = yProp->Value(yValue, tmpValid, TimePos, G_ABSOLUTE_VALUE);
	if (xErr != G_NO_ERROR || yErr != G_NO_ERROR)
		return GVector2(1, 1);

	ValidInterval = tmpValid;
	// take care of father
	if (gFather && Space == G_WORLD_SPACE) {
		GVectBase<GReal, 2> retValue(xValue.RealValue(), yValue.RealValue());
		retValue += gFather->Scale(TimePos, G_WORLD_SPACE, tmpValid);
		ValidInterval &= tmpValid;
		return retValue;
	}
	return GVectBase<GReal, 2>(xValue.RealValue(), yValue.RealValue());
}
GPoint2 GAnimTRSNode2D::Position(const GTimeValue TimePos, const GSpaceSystem Space, GTimeInterval& ValidInterval) const {

	GProperty *tmpProp = Property("transform");

	if (!tmpProp)
		return GPoint2(0, 0);

	tmpProp = tmpProp->Property("position");
	G_ASSERT(tmpProp);
	GTimeInterval tmpValid = G_FOREVER_TIMEINTERVAL;
	GKeyValue xValue, yValue;

	// extract translation
	GProperty *xProp = tmpProp->Property("x");
	GProperty *yProp = tmpProp->Property("y");
	G_ASSERT(xProp != NULL);
	G_ASSERT(yProp != NULL);
	// build translation factor
	GError xErr = xProp->Value(xValue, tmpValid, TimePos, G_ABSOLUTE_VALUE);
	GError yErr = yProp->Value(yValue, tmpValid, TimePos, G_ABSOLUTE_VALUE);
	if (xErr != G_NO_ERROR || yErr != G_NO_ERROR)
		return GPoint2(0, 0);

	ValidInterval = tmpValid;

	// take care of father
	if (gFather && Space == G_WORLD_SPACE) {
		GPoint2 retValue(xValue.RealValue(), yValue.RealValue());
		retValue += gFather->Position(TimePos, G_WORLD_SPACE, tmpValid);
		ValidInterval &= tmpValid;
		return retValue;
	}
	return GPoint2(xValue.RealValue(), yValue.RealValue());
}
Exemple #5
0
std::pair<Mat,Mat> matlabHelper::gradient(Mat & img, float spaceX, float spaceY)
{

    Mat gradY = gradientY(img,spaceY);
    Mat gradX = gradientX(img,spaceX);
    std::pair<Mat,Mat> retValue(gradX,gradY);
    return retValue;
}
	int Stop(bool Wait) {
		if(!running) return started ? retValue() : -1;
		activ = false;
		if(Wait) {
			pthread_join(thread, &retvar);
		}
		return (int)retvar;
	}
Exemple #7
0
T ValueLatch<T>::get()
{
    std::unique_lock<std::mutex> lock(mMutex);
    mCondition.wait(lock, [this]() {
        return (bool)mValue;
    });
    std::unique_ptr<T> retValue(std::move(mValue));
    return T(std::move(*retValue));
}
Exemple #8
0
std::string CTTUtil::getLowerCaseString(const char* str)
{
	std::string retValue(str);
	for (int i=0;i<int(retValue.length());i++)
	{
		if ((retValue[i]>=65)&&(retValue[i]<=90))
			retValue[i]+=32;
	}
	return(retValue);
}
Exemple #9
0
T ValueLatch<T>::get(const unsigned int timeoutMs)
{
    std::unique_lock<std::mutex> lock(mMutex);
    if (mCondition.wait_for(lock, std::chrono::milliseconds(timeoutMs), [this]() {
                                return (bool)mValue;
                            }) ) {
        std::unique_ptr<T> retValue(std::move(mValue));
        return T(std::move(*retValue));
    } else {
        throw UtilsException("Timeout occured");
    }
}
std::string
ActorEditViewCtl::buildSEListEntry(ActorDesc::StateElemListIt itSE)
{
    std::string retValue("");

    retValue.append(itSE->getAccessStr().empty() ? "" : itSE->getAccessStr());
    retValue.append(": "                                                    );
    retValue.append(itSE->getType().empty()      ? "" : itSE->getType()     );
    retValue.append(" "                                                     );
    retValue.append(itSE->getName().empty()      ? "" : itSE->getName()     );

    return retValue;
}
ScriptValuePtr TraceMonkeyValue::getProperty(std::string propertyName)
{
    assert(isValid());

    Logging::log(Logging::DEBUG, "TraceMonkeyValue::getProperty(%s): \r\n", propertyName.c_str()); printJSVAL(value);

    assert(JSVAL_IS_OBJECT(value));
    jsval ret;
    assert(JS_GetProperty(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), propertyName.c_str(), &ret));
    bool success = JS_AddNamedRoot(TraceMonkeyEngine::context, &ret, "TraceMonkeyValue::getProperty temp val"); // Ensure our value won't be GCed
    assert(success);

    Logging::log(Logging::DEBUG, "returning: \r\n"); printJSVAL(ret);

    ScriptValuePtr retValue(new TraceMonkeyValue(engine, true, ret));

    success = JS_RemoveRoot(TraceMonkeyEngine::context, &ret); // Allow GCing, it is already marked in the retValue
    assert(success);

    return retValue;
}
ScriptValuePtr V8Value::call(std::string funcName, ScriptValueArgs& args)
{
    HandleScope handleScope;

    assert(isValid());

    Logging::log(Logging::INFO, "V8V::call(%s, (%d))\r\n", funcName.c_str(), args.args.size());

    printV8Value(value);

    assert(value->IsObject() && !value->IsNull());

    Local<Object> obj = value->ToObject();

    Local<Object> _func = obj->Get(String::New(funcName.c_str()))->ToObject();
    assert(_func->IsFunction());

    Local<Function> func = Function::Cast(*_func);

    int numArgs = args.args.size();
    Handle<Value>* v8Args = new Handle<Value>[numArgs+1]; // +1 for safety in case of 0 args
    for (int i = 0; i < numArgs; i++)
    {
        v8Args[i] = (dynamic_cast<V8Value*>(args.args[i].get()))->value;
    }

    TryCatch tc;
    Handle<Value> ret = func->Call(obj, numArgs, v8Args);
    delete[] v8Args;
    if (ret.IsEmpty())
        handleException(tc);

    Logging::log(Logging::INFO, "returning: \r\n"); printV8Value(ret);

    ScriptValuePtr retValue(new V8Value(engine, ret));

    return retValue;
}
ScriptValuePtr TraceMonkeyValue::call(std::string funcName, ScriptValueArgs& args)
{
    assert(isValid());

    Logging::log(Logging::DEBUG, "TMV::call(%s, (%d))\r\n", funcName.c_str(), args.args.size());

    printJSVAL(value);

    assert(JSVAL_IS_OBJECT(value));

    jsval func;
    bool success = JS_GetProperty(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), funcName.c_str(), &func);
    assert(success);

    assert(JSVAL_IS_OBJECT(func));
    assert(!JSVAL_IS_NULL(func));

    int numArgs = args.args.size();
    jsval jsArgs[numArgs+1]; // +1 for safety in case of 0 args
    for (int i = 0; i < numArgs; i++)
    {
        jsArgs[i] = dynamic_cast<TraceMonkeyValue*>(args.args[i].get())->value;
    }

    jsval ret;
    JS_CallFunctionValue(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), func, numArgs, jsArgs, &ret);
    success = JS_AddNamedRoot(TraceMonkeyEngine::context, &ret, "TraceMonkeyValue::call temp val"); // Ensure our value won't be GCed
    assert(success);
    Logging::log(Logging::DEBUG, "returning: \r\n"); printJSVAL(ret);

    ScriptValuePtr retValue(new TraceMonkeyValue(engine, true, ret));

    success = JS_RemoveRoot(TraceMonkeyEngine::context, &ret); // Allow GCing, it is already marked in the retValue
    assert(success);

    return retValue;
}
void
WrapperPromiseCallback::Call(JSContext* aCx,
                             JS::Handle<JS::Value> aValue)
{
  JSAutoCompartment ac(aCx, mGlobal);
  JS::Rooted<JS::Value> value(aCx, aValue);
  if (!JS_WrapValue(aCx, &value)) {
    NS_WARNING("Failed to wrap value into the right compartment.");
    return;
  }

  ErrorResult rv;

  // If invoking callback threw an exception, run resolver's reject with the
  // thrown exception as argument and the synchronous flag set.
  JS::Rooted<JS::Value> retValue(aCx);
  mCallback->Call(value, &retValue, rv, CallbackObject::eRethrowExceptions);

  rv.WouldReportJSException();

  if (rv.Failed() && rv.IsJSException()) {
    JS::Rooted<JS::Value> value(aCx);
    rv.StealJSException(aCx, &value);

    if (!JS_WrapValue(aCx, &value)) {
      NS_WARNING("Failed to wrap value into the right compartment.");
      return;
    }

    mNextPromise->RejectInternal(aCx, value, Promise::SyncTask);
    return;
  }

  // If the return value is the same as the promise itself, throw TypeError.
  if (retValue.isObject()) {
    JS::Rooted<JSObject*> valueObj(aCx, &retValue.toObject());
    Promise* returnedPromise;
    nsresult r = UNWRAP_OBJECT(Promise, valueObj, returnedPromise);

    if (NS_SUCCEEDED(r) && returnedPromise == mNextPromise) {
      const char* fileName = nullptr;
      uint32_t lineNumber = 0;

      // Try to get some information about the callback to report a sane error,
      // but don't try too hard (only deals with scripted functions).
      JS::Rooted<JSObject*> unwrapped(aCx,
        js::CheckedUnwrap(mCallback->Callback()));

      if (unwrapped) {
        JSAutoCompartment ac(aCx, unwrapped);
        if (JS_ObjectIsFunction(aCx, unwrapped)) {
          JS::Rooted<JS::Value> asValue(aCx, JS::ObjectValue(*unwrapped));
          JS::Rooted<JSFunction*> func(aCx, JS_ValueToFunction(aCx, asValue));

          MOZ_ASSERT(func);
          JSScript* script = JS_GetFunctionScript(aCx, func);
          if (script) {
            fileName = JS_GetScriptFilename(script);
            lineNumber = JS_GetScriptBaseLineNumber(aCx, script);
          }
        }
      }

      // We're back in aValue's compartment here.
      JS::Rooted<JSString*> stack(aCx, JS_GetEmptyString(JS_GetRuntime(aCx)));
      JS::Rooted<JSString*> fn(aCx, JS_NewStringCopyZ(aCx, fileName));
      if (!fn) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return;
      }

      JS::Rooted<JSString*> message(aCx,
        JS_NewStringCopyZ(aCx,
          "then() cannot return same Promise that it resolves."));
      if (!message) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return;
      }

      JS::Rooted<JS::Value> typeError(aCx);
      if (!JS::CreateTypeError(aCx, stack, fn, lineNumber, 0,
                               nullptr, message, &typeError)) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return;
      }

      mNextPromise->RejectInternal(aCx, typeError, Promise::SyncTask);
      return;
    }
  }

  // Otherwise, run resolver's resolve with value and the synchronous flag
  // set.
  if (!JS_WrapValue(aCx, &retValue)) {
    NS_WARNING("Failed to wrap value into the right compartment.");
    return;
  }

  mNextPromise->ResolveInternal(aCx, retValue, Promise::SyncTask);
}
nsresult
WrapperPromiseCallback::Call(JSContext* aCx,
                             JS::Handle<JS::Value> aValue)
{
  JS::ExposeObjectToActiveJS(mGlobal);
  JS::ExposeValueToActiveJS(aValue);

  JSAutoCompartment ac(aCx, mGlobal);
  JS::Rooted<JS::Value> value(aCx, aValue);
  if (!JS_WrapValue(aCx, &value)) {
    NS_WARNING("Failed to wrap value into the right compartment.");
    return NS_ERROR_FAILURE;
  }

  ErrorResult rv;

  // PromiseReactionTask step 6
  JS::Rooted<JS::Value> retValue(aCx);
  JSCompartment* compartment;
  if (mNextPromise) {
    compartment = mNextPromise->Compartment();
  } else {
    MOZ_ASSERT(mNextPromiseObj);
    compartment = js::GetObjectCompartment(mNextPromiseObj);
  }
  mCallback->Call(value, &retValue, rv, "promise callback",
                  CallbackObject::eRethrowExceptions,
                  compartment);

  rv.WouldReportJSException();

  // PromiseReactionTask step 7
  if (rv.Failed()) {
    JS::Rooted<JS::Value> value(aCx);
    { // Scope for JSAutoCompartment
      // Convert the ErrorResult to a JS exception object that we can reject
      // ourselves with.  This will be exactly the exception that would get
      // thrown from a binding method whose ErrorResult ended up with whatever
      // is on "rv" right now.  Do this in the promise reflector compartment.
      Maybe<JSAutoCompartment> ac;
      if (mNextPromise) {
        ac.emplace(aCx, mNextPromise->GlobalJSObject());
      } else {
        ac.emplace(aCx, mNextPromiseObj);
      }
      DebugOnly<bool> conversionResult = ToJSValue(aCx, rv, &value);
      MOZ_ASSERT(conversionResult);
    }

    if (mNextPromise) {
      mNextPromise->RejectInternal(aCx, value);
    } else {
      JS::Rooted<JS::Value> ignored(aCx);
      ErrorResult rejectRv;
      mRejectFunc->Call(value, &ignored, rejectRv);
      // This reported any JS exceptions; we just have a pointless exception on
      // there now.
      rejectRv.SuppressException();
    }
    return NS_OK;
  }

  // If the return value is the same as the promise itself, throw TypeError.
  if (retValue.isObject()) {
    JS::Rooted<JSObject*> valueObj(aCx, &retValue.toObject());
    valueObj = js::CheckedUnwrap(valueObj);
    JS::Rooted<JSObject*> nextPromiseObj(aCx);
    if (mNextPromise) {
      nextPromiseObj = mNextPromise->GetWrapper();
    } else {
      MOZ_ASSERT(mNextPromiseObj);
      nextPromiseObj = mNextPromiseObj;
    }
    // XXXbz shouldn't this check be over in ResolveInternal anyway?
    if (valueObj == nextPromiseObj) {
      const char* fileName = nullptr;
      uint32_t lineNumber = 0;

      // Try to get some information about the callback to report a sane error,
      // but don't try too hard (only deals with scripted functions).
      JS::Rooted<JSObject*> unwrapped(aCx,
        js::CheckedUnwrap(mCallback->Callback()));

      if (unwrapped) {
        JSAutoCompartment ac(aCx, unwrapped);
        if (JS_ObjectIsFunction(aCx, unwrapped)) {
          JS::Rooted<JS::Value> asValue(aCx, JS::ObjectValue(*unwrapped));
          JS::Rooted<JSFunction*> func(aCx, JS_ValueToFunction(aCx, asValue));

          MOZ_ASSERT(func);
          JSScript* script = JS_GetFunctionScript(aCx, func);
          if (script) {
            fileName = JS_GetScriptFilename(script);
            lineNumber = JS_GetScriptBaseLineNumber(aCx, script);
          }
        }
      }

      // We're back in aValue's compartment here.
      JS::Rooted<JSString*> fn(aCx, JS_NewStringCopyZ(aCx, fileName));
      if (!fn) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return NS_ERROR_OUT_OF_MEMORY;
      }

      JS::Rooted<JSString*> message(aCx,
        JS_NewStringCopyZ(aCx,
          "then() cannot return same Promise that it resolves."));
      if (!message) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return NS_ERROR_OUT_OF_MEMORY;
      }

      JS::Rooted<JS::Value> typeError(aCx);
      if (!JS::CreateError(aCx, JSEXN_TYPEERR, nullptr, fn, lineNumber, 0,
                           nullptr, message, &typeError)) {
        // Out of memory. Promise will stay unresolved.
        JS_ClearPendingException(aCx);
        return NS_ERROR_OUT_OF_MEMORY;
      }

      if (mNextPromise) {
        mNextPromise->RejectInternal(aCx, typeError);
      } else {
        JS::Rooted<JS::Value> ignored(aCx);
        ErrorResult rejectRv;
        mRejectFunc->Call(typeError, &ignored, rejectRv);
        // This reported any JS exceptions; we just have a pointless exception
        // on there now.
        rejectRv.SuppressException();
      }
      return NS_OK;
    }
  }

  // Otherwise, run resolver's resolve with value.
  if (!JS_WrapValue(aCx, &retValue)) {
    NS_WARNING("Failed to wrap value into the right compartment.");
    return NS_ERROR_FAILURE;
  }

  if (mNextPromise) {
    mNextPromise->ResolveInternal(aCx, retValue);
  } else {
    JS::Rooted<JS::Value> ignored(aCx);
    ErrorResult resolveRv;
    mResolveFunc->Call(retValue, &ignored, resolveRv);
    // This reported any JS exceptions; we just have a pointless exception
    // on there now.
    resolveRv.SuppressException();
  }
    
  return NS_OK;
}