예제 #1
0
bool Journal::PlayNext()
{
   if (_State == PlayState) {
      _start();
      Id id;

      mFile->read(&id);

      Functor* jrn = _create(id);
      AssertFatal(jrn,"Journal: Undefined function found in journal");
      jrn->read(mFile);
      _finish();

      _Dispatching = true;
      jrn->dispatch();
      _Dispatching = false;

      delete jrn;
      if (_Count)
         return true;
      Stop();

      //debugBreak();
   }
   return false;
}
예제 #2
0
int main()
{
	int N;
	cin >> N;
	Functor *f = new FunctorShow;
	Functor *fc = new FunctorCreate;
	mfunc["showall"] = f;
	mfunc["create"] = fc;
	string command;
	vector<string> strvec;
	for (int i = 0; i < N; i++) {
		cin >> command;
		Functor *fctr = mfunc[command];
		if (fctr) {	
			
			int argnum = fctr->getArgNum();
			if (argnum == 2) 
			for (int j = 0; j < argnum; j++) {
				string str;
				cin >> str;
				strvec.push_back(str);
			}
			(*fctr)(strvec);
		}
	}

	return 0;
}
예제 #3
0
void ThreadQueue::dispatchResponseCalls()
{
   lock();
   for(S32 i = 0; i < mResponseCalls.size(); i++)
   {
      Functor *c = mResponseCalls[i];
      c->dispatch(this);
      delete c;
   }
   mResponseCalls.clear();
   unlock();
}
예제 #4
0
파일: functor_virt.cpp 프로젝트: jblunck/a
int main()
{
  Functor t;
  std::cout << t() << std::endl;
  t.set_configuration("two");
  std::cout << t() << std::endl;

  for (int i=0 ; i < 1e9; ++i)
    (void) t();

  return 0;
}
예제 #5
0
void ThreadQueue::dispatchNextCall()
{
   mSemaphore.wait();
   lock();
   if(mThreadCalls.size() == 0)
   {
      unlock();
      return;
   }
   Functor *c = mThreadCalls.first();
   mThreadCalls.pop_front();
   unlock();
   c->dispatch(this);
   delete c;
}
예제 #6
0
	unsigned int __stdcall TaskSchedulerImpl::WorkerProc(void* userdata)
	{
		unsigned int workerID = *static_cast<unsigned int*>(userdata);
		SetEvent(s_doneEvents[workerID]);

		Worker& worker = s_workers[workerID];
		WaitForSingleObject(worker.wakeEvent, INFINITE);

		while (worker.running)
		{
			Functor* task = nullptr;

			if (worker.workCount > 0) // Permet d'éviter d'entrer inutilement dans une section critique
			{
				EnterCriticalSection(&worker.queueMutex);
				if (!worker.queue.empty()) // Nécessaire car le workCount peut être tombé à zéro juste avant l'entrée dans la section critique
				{
					task = worker.queue.front();
					worker.queue.pop();
					worker.workCount = worker.queue.size();
				}
				LeaveCriticalSection(&worker.queueMutex);
			}

			// Que faire quand vous n'avez plus de travail ?
			if (!task)
				task = StealTask(workerID); // Voler le travail des autres !

			if (task)
			{
				// On exécute la tâche avant de la supprimer
				task->Run();
				delete task;
			}
			else
			{
				SetEvent(s_doneEvents[workerID]);
				WaitForSingleObject(worker.wakeEvent, INFINITE);
			}
		}

		// Au cas où un thread attendrait sur WaitForTasks() pendant qu'un autre appellerait Uninitialize()
		// Ça ne devrait pas arriver, mais comme ça ne coûte pas grand chose..
		SetEvent(s_doneEvents[workerID]);

		return 0;
	}
예제 #7
0
static Vector AttituteDynamics(const ssfTime &_time, const Vector& _integratingState, Orbit *_Orbit, Attitude *_Attitude, const Matrix &_parameters, const Functor &_forceFunctorPtr)
{
    static Vector stateDot(7);
    static Matrix bMOI(3,3); 
    static Matrix qtemp(4,3); 
    static Vector Tmoment(3);
    static Vector qIn(4); 
    static Vector wIn(3);

    qIn = _integratingState(_(VectorIndexBase,VectorIndexBase + 3));
    wIn = _integratingState(_(VectorIndexBase + 4,VectorIndexBase + 6));
    qIn /= norm2(qIn);

    qtemp(_(VectorIndexBase+0,VectorIndexBase+2),_) = skew(qIn(_(VectorIndexBase+0,VectorIndexBase+2))) + qIn(VectorIndexBase+3) * eye(3);
    qtemp(VectorIndexBase+3, _) = -(~qIn(_(VectorIndexBase+0,VectorIndexBase+2)));

    bMOI = _parameters(_(MatrixIndexBase+0,MatrixIndexBase+2),_(MatrixIndexBase+0,MatrixIndexBase+2));
    Tmoment = _forceFunctorPtr.Call(_time, _Orbit->GetStateObject(), _Attitude->GetStateObject());
    
    stateDot(_(VectorIndexBase,VectorIndexBase + 3)) = 0.5 * qtemp * wIn;
    stateDot(_(VectorIndexBase + 4,VectorIndexBase + 6)) = (bMOI.inverse() * (Tmoment - skew(wIn) * (bMOI * wIn)));

    return stateDot;
}
예제 #8
0
void ITimerManager::waitTo(const mtime& time, Functor<Class,RetType>& func) const {
    wait(time);
    func.call();
}
예제 #9
0
void ITimerManager::waitTo(const mtime& time, Functor<Class,RetType,Param1>& func, Param1& arg1) const {
    wait(time);
    func.call(arg1);
}
예제 #10
0
FloatInputStream::FloatInputStream(const Functor& connectToGetterFunctor)
	: InputStream()
	, connectedFunctor(connectToGetterFunctor.clone())
	//, unreadStack()
{
}
예제 #11
0
void FloatInputStream::connectToFunctor(const Functor& newFunctor)
{
	if (connectedStream != NULL) disconnectFromStream();
	connectedFunctor = newFunctor.clone();
}
BOOST_AUTO_TEST_CASE_TEMPLATE(works, BasisFunctionType, basis_function_types)
{
    typedef BasisFunctionType BFT;
    typedef typename Fiber::ScalarTraits<BFT>::ComplexType RT;
    typedef typename Fiber::ScalarTraits<BFT>::RealType CT;
    GridParameters params;
    params.topology = GridParameters::TRIANGULAR;
    shared_ptr<Grid> grid = GridFactory::importGmshGrid(
                params, "meshes/two_disjoint_triangles.msh",
                false /* verbose */);

    PiecewiseLinearContinuousScalarSpace<BFT> pwiseLinears(grid);
    PiecewiseConstantScalarSpace<BFT> pwiseConstants(grid);

    AssemblyOptions assemblyOptions;
    assemblyOptions.setVerbosityLevel(VerbosityLevel::LOW);
    AccuracyOptions accuracyOptions;
    accuracyOptions.doubleRegular.setAbsoluteQuadratureOrder(5);
    accuracyOptions.doubleSingular.setAbsoluteQuadratureOrder(5);
    NumericalQuadratureStrategy<BFT, RT> quadStrategy(accuracyOptions);

    Context<BFT, RT> context(make_shared_from_ref(quadStrategy), assemblyOptions);

    const RT waveNumber(1.23, 0.31);

    BoundaryOperator<BFT, RT> slpOpConstants = Bempp::helmholtz3dSingleLayerBoundaryOperator<BFT>(
                make_shared_from_ref(context),
                make_shared_from_ref(pwiseConstants),
                make_shared_from_ref(pwiseConstants),
                make_shared_from_ref(pwiseConstants),
                waveNumber);
    BoundaryOperator<BFT, RT> slpOpLinears = helmholtz3dSingleLayerBoundaryOperator<BFT>(
                make_shared_from_ref(context),
                make_shared_from_ref(pwiseLinears),
                make_shared_from_ref(pwiseLinears),
                make_shared_from_ref(pwiseLinears),
                waveNumber);
    BoundaryOperator<BFT, RT> hypOp = helmholtz3dHypersingularBoundaryOperator<BFT>(
                make_shared_from_ref(context),
                make_shared_from_ref(pwiseLinears),
                make_shared_from_ref(pwiseLinears),
                make_shared_from_ref(pwiseLinears),
                waveNumber);

    // Get the matrix repr. of the hypersingular operator
    arma::Mat<RT> hypMat = hypOp.weakForm()->asMatrix();

    // Construct the expected hypersingular operator matrix. For this, we need:

    // * the surface curls of all basis functions (which are constant)
    typedef Fiber::SurfaceCurl3dElementaryFunctor<CT> ElementaryFunctor;
    typedef Fiber::ElementaryBasisTransformationFunctorWrapper<ElementaryFunctor> Functor;
    Functor functor;
    size_t basisDeps = 0, geomDeps = 0;
    functor.addDependencies(basisDeps, geomDeps);

    arma::Mat<CT> points(2, 1);
    points.fill(0.);

    typedef Fiber::PiecewiseLinearContinuousScalarBasis<3, BFT> Basis;
    Basis basis;
    Fiber::BasisData<BFT> basisData;
    basis.evaluate(basisDeps, points, Fiber::ALL_DOFS, basisData);

    Fiber::GeometricalData<CT> geomData[2];
    std::unique_ptr<GridView> view = grid->leafView();
    std::unique_ptr<EntityIterator<0> > it = view->entityIterator<0>();
    it->entity().geometry().getData(geomDeps, points, geomData[0]);
    it->next();
    it->entity().geometry().getData(geomDeps, points, geomData[1]);

    Fiber::DefaultCollectionOfBasisTransformations<Functor> transformations(functor);

    Fiber::CollectionOf3dArrays<BFT> surfaceCurl[2];
    transformations.evaluate(basisData, geomData[0], surfaceCurl[0]);
    transformations.evaluate(basisData, geomData[1], surfaceCurl[1]);

    // * the single-layer potential matrix for constant basis functions
    arma::Mat<RT> slpMatConstants = slpOpConstants.weakForm()->asMatrix();
    // * the single-layer potential matrix for linear basis functions
    arma::Mat<RT> slpMatLinears = slpOpLinears.weakForm()->asMatrix();

    arma::Mat<RT> expectedHypMat(6, 6);
    for (size_t testElement = 0; testElement < 2; ++testElement)
        for (size_t trialElement = 0; trialElement < 2; ++trialElement)
            for (size_t r = 0; r < 3; ++r)
                for (size_t c = 0; c < 3; ++c) {
                    RT curlMultiplier = 0.;
                    for (size_t dim = 0; dim < 3; ++dim)
                        curlMultiplier += surfaceCurl[testElement][0](dim, r, 0) *
                                surfaceCurl[trialElement][0](dim, c, 0);
                    RT valueMultiplier = 0.;
                    for (size_t dim = 0; dim < 3; ++dim)
                        valueMultiplier += geomData[testElement].normals(dim, 0) *
                            geomData[trialElement].normals(dim, 0);
                    expectedHypMat(3 * testElement + r, 3 * trialElement + c) =
                            curlMultiplier * slpMatConstants(testElement, trialElement) -
                            waveNumber * waveNumber * valueMultiplier *
                            slpMatLinears(3 * testElement + r, 3 * trialElement + c);
                }

    BOOST_CHECK(check_arrays_are_close<RT>(expectedHypMat, hypMat, 1e-6));
}
예제 #13
0
void BoolOutputStream::connectToFunctor(const Functor& newFunctor)
{
	connectedFunctors += newFunctor.clone();
}