Пример #1
0
void coroutine::context_function()
{
    CORO_LOG("CORO: starting '", _name, "'");
    try
    {
        _last_checkpoint = "started";
        _function();
        _last_checkpoint = "finished cleanly";
    }
    catch(const channel_closed&)
    {
        _last_checkpoint = "finished after channel close";
    }
    catch(const std::exception& e)
    {
        _last_checkpoint = std::string("uncaught exception: ") + e.what();
        std::cerr << "Uncaught exception in " << _name << " : " << e.what() << std::endl;
        std::terminate();
    }
    catch(...)
    {
        _last_checkpoint = "uncaught exception";
        std::cerr << "Uncaught exception in " << _name << std::endl;
        std::terminate();
    }

    CORO_LOG("CORO: finished cleanly '", _name, "'");

    auto temp = _new_context;
    _new_context = nullptr;// to mark the completion
    boost::context::jump_fcontext(temp, &_caller_context, 0);
}
Пример #2
0
void CallFunc::update(float t)
{
    if (_function != NULL)
    {
        _function();
    }
}
Пример #3
0
void Ticker::handler()
{
    insert_absolute(event.timestamp + _delay);
    if (_function) {
        _function();
    }
}
Пример #4
0
void FunctionPointer::call(void) {
    if (_function) {
        _function();
    } else if (_object) {
        _membercaller(_object, _member);
    }
}
Пример #5
0
void CallFunc::execute() {
    if (_callFunc) {
        (_selectorTarget->*_callFunc)();
    } else if( _function ){
        _function();
    }
}
Пример #6
0
void Rootmenu::insertFunction(const bt::ustring &label,
                              unsigned int function,
                              const std::string &exec,
                              unsigned int id,
                              unsigned int index) {
  unsigned int x = insertItem(label, id, index);
  _funcmap.insert(FunctionMap::value_type(x, _function(function, exec)));
}
void ZFTimer::callTheFunction()
{
    timerIsRunning = false;
    if(_function != NULL)
    {
        _function();
    }
}
Пример #8
0
 R operator()(T&&... args)
 {
     std::size_t hash_value = hash(args...);
     if (_cache.find(hash_value) == _cache.end())
     {
         _cache[hash_value] = _function(std::forward<T>(args)...);
     }
     return _cache[hash_value];
 }
    void Accelerometer::update(float x, float y, float z, long sensorTimeStamp) 
    {
        if (_function)
        {
            _accelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
            _accelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
            _accelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
            _accelerationValue.timestamp = (double)sensorTimeStamp;

            _function(&_accelerationValue);
        }    
    }
Пример #10
0
void Accelerometer::update( double x,double y,double z,double timestamp ) 
{
    if (_function)
    {
        _accelerationValue.x            = x;
        _accelerationValue.y            = y;
        _accelerationValue.z            = z;
        _accelerationValue.timestamp = timestamp;

        // Delegate
        _function(&_accelerationValue);
    }    
}
Пример #11
0
void GuiPropertyComponent::render() {
    bool v = _isEnabled;
    ImGui::Begin(name().c_str(), &v, size, 0.5f);
    _isEnabled = v;

    ImGui::Spacing();

    if (_function) {
        std::vector<properties::PropertyOwner*> owners = _function();
        std::sort(
            owners.begin(),
            owners.end(),
            [](properties::PropertyOwner* lhs, properties::PropertyOwner* rhs) {
                return lhs->name() < rhs->name();
            }
        );

        for (properties::PropertyOwner* pOwner : owners) {
            int count = nVisibleProperties(pOwner->propertiesRecursive(), _visibility);

            if (count == 0) {
                continue;
            }

            auto header = [&]() -> bool {
                if (owners.size() > 1) {
                    // Create a header in case we have multiple owners
                    return ImGui::CollapsingHeader(pOwner->name().c_str());
                }
                else {
                    // Otherwise, do nothing
                    ImGui::Text(pOwner->name().c_str());
                    ImGui::Spacing();
                    return true;
                }
            };

            if (header()) {
                renderPropertyOwner(pOwner);
            }
        }
    }

    ImGui::End();
}
Пример #12
0
void NeumannBc::initialize(unsigned global_dim)
{
    DBUG("Create global assembler.");
    _global_assembler.reset(
        new GlobalAssembler(*_local_to_global_index_map));

    auto elementValueLookup = [this](MeshLib::Element const&)
    {
        return _function();
    };

    createLocalAssemblers<LocalNeumannBcAsmData>(
        global_dim, _elements,
        *_local_to_global_index_map, _integration_order,
        _local_assemblers,
        elementValueLookup
        );
}
Пример #13
0
//直角方向行走
void AStar::getBordorPoints(Point core)
{
	_points = PointArray::create(4);	
	for(auto unit : CrossVecs)
	{
		Point p(core);
		p += unit;
		if(_function)
		{
			if(_function(p) == 0)
			{
				_points->addControlPoint(p);
			}			
		}else
		{
			_points->addControlPoint(p);
		}
	}
}
Пример #14
0
vector<Value> NativeProperty::call(const vector<Value>& closure, const vector<Value>& inputs) const
{
	if(closure.size() != _numClosure || inputs.size() != _numInputs)
		wcerr << endl << *this << L" = " << closure.size() << " " << inputs.size() << " " << _numOutputs << endl;
	assert(closure.size() == _numClosure);
	assert(inputs.size() == _numInputs);
	vector<int64_t> closureVec;
	for(const Value& value: closure)
		closureVec.push_back(value.integer());
	vector<int64_t> inputVec;
	for(const Value& value: inputs)
		inputVec.push_back(value.integer());
	vector<int64_t> outputVec;
	outputVec.resize(_numOutputs);
	_function(0, inputVec.data(), outputVec.data());
	vector<Value> outputs;
	for(int64_t value: outputVec)
		outputs.push_back(value);
	return outputs;
}
Пример #15
0
	vector_t
	normal(const vector_t point) const
	{
		constexpr float D = 1e-2;
		constexpr vector_t X {D, 0, 0};
		constexpr vector_t Y {0, D, 0};
		constexpr vector_t Z {0, 0, D};

		return vector_t
		{
			_function(point + X) - _function(point - X),
			_function(point + Y) - _function(point - Y),
			_function(point + Z) - _function(point - Z)
		};
	}
Пример #16
0
/**
 * The main loop for the implementation thread
 *
 * This owns the actual implementation scope (which needs to be created on this
 * child thread) and has essentially two transition paths:
 *
 * Standard: ProxyRequest -> ImplResponse
 *   Invoke _function. Serialize exceptions to _status.
 *
 * Shutdown: Shutdown -> _
 *   break out of the loop and return.
 */
void MozJSProxyScope::implThread() {
    if (hasGlobalServiceContext())
        Client::initThread("js");

    std::unique_ptr<MozJSImplScope> scope;

    // This will leave _status set for the first noop runOnImplThread(), which
    // captures the startup exception that way
    try {
        scope.reset(new MozJSImplScope(_engine));
        _implScope = scope.get();
    } catch (...) {
        _status = exceptionToStatus();
    }

    while (true) {
        stdx::unique_lock<stdx::mutex> lk(_mutex);
        _condvar.wait(
            lk, [this] { return _state == State::ProxyRequest || _state == State::Shutdown; });

        if (_state == State::Shutdown)
            break;

        try {
            _function();
        } catch (...) {
            _status = exceptionToStatus();
        }

        int exitCode;
        if (_implScope && _implScope->getQuickExit(&exitCode)) {
            scope.reset();
            quickExit(exitCode);
        }

        _state = State::ImplResponse;

        _condvar.notify_one();
    }
}
Пример #17
0
/* statement */
static int _statement(State * state)
	/* ( function | [ space [ instruction ] ] ) newline */
{
	int ret;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	if(_parser_in_set(state, TS_FUNCTION))
		/* function */
		ret = _function(state);
	else if(_parser_in_set(state, TS_SPACE))
	{
		/* space [ instruction ] */
		ret = _space(state);
		if(_parser_in_set(state, TS_INSTRUCTION))
			ret |= _instruction(state);
	}
	else if(!_parser_in_set(state, TS_NEWLINE))
		return _parser_recover(state, AS_CODE_NEWLINE, "Statement");
	ret |= _newline(state);
	return ret;
}
Пример #18
0
void FunctionSimple::evaluate(PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info, void * /*context*/) const
{
  _function(result, time, argc, argv, info);
}
Пример #19
0
void DataServeriOS::CallCustomFunction()
{
  _function(atoi(port));
}
Пример #20
0
Variable NativeFunction::operator()(AVM &avm) {
	return _function(avm);
}
Пример #21
0
 double operator()(double r) const { return 2.*M_PI*r*_function(r); }
Пример #22
0
	bool
	inside(const vector_t& point) const
	{
		return _function(point) >= 0.f;
	}
Пример #23
0
	rendering::hits_t::iterator
	hit(const rendering::ray_t& ray, rendering::hits_t::iterator hits) const
	{
		const auto function1 = [this, &ray](const float distance) -> float
		{
			const vector_t point = ray.origin + ray.direction * distance;
			return _function(point);
		};

		const auto function = [&ray, &function1](const float distance) -> boost::math::tuple<float, float>
		{
			constexpr float h = 1e-2f;

			return boost::math::make_tuple
			(
				function1(distance),
				(function1(distance + h) - function1(distance - h)) / (2.f * h)
			);
		};

		const auto test = [this, &ray, &hits, &function, &function1](const value_t& value)
		{
			constexpr float a = 1e-4f;

			const box_t& box = value.first;
			const point_t point = geo::return_centroid<point_t>(box);

			float distance = length((const vector_t&) point - ray.origin);

			if (ray.min > distance || distance > ray.max)
				return;

			boost::uintmax_t max = 100;
			distance = boost::math::tools::newton_raphson_iterate
			(
				function,
				distance - _distance + std::numeric_limits<float>::epsilon(),
				distance - _distance,
				distance + _distance,
				std::numeric_limits<float>::digits,
				max
			);

			if (std::abs(function1(distance)) < a)
			{
				const vector_t point = ray.origin + ray.direction * distance;

				if (geo::intersects(box, to_point(point)))
				{
					hits->distance = distance;
					hits->normal = normal(point);
					++hits;
				}
			}
		};

		const segment_t segment = to_segment(ray);
		_rtree.query(geo::index::intersects(segment), boost::make_function_output_iterator(test));

		return hits;
	}
Пример #24
0
 virtual float apply(float value) const {
     return _function(value);
 }
bool OsmAnd::LambdaQueryController::isAborted() const
{
    return _function();
}
Пример #26
0
void CreateNodeAction::createNode()
{
    std::cerr << "CreateNode\n";
    if(_function) _function( QPointF((float)io::GetCursorX(), (float)io::GetCursorY()) );
}
Пример #27
0
void Ticker::handler() {
    insert(event.timestamp + _delay);
    _function();
}
Пример #28
0
/** HasFunctions **/
Function& Namespace::addFunction(string name) {
	Function _function(name, *this);	
	std::multimap<string,Function>::iterator it = this->_functions.insert( pair<string, Function>(name, _function) );
	Function& ref = it->second;
	return ref;
}
Пример #29
0
	/**
	 * Gives the current rate according to the original rate function
	 * @return The rate of the node
	 */
	virtual Rate getCurrentRate() const override {
		return _function(_current_time);
	}
void GroupBeginRenderCommand::execute()
{
	_function();
}