Ejemplo n.º 1
0
void logAllSearchResultsFoundIterator(IteratorPtr<LookupResult<T> > pFindResultIter,
		DistanceCalculatorPtr<T> pDistanceCaculator,
		RealCoordinateCalculatorPtr<T> pRealCoordinateCalculator,
		RealCoordinateWriterPtr<T> pRealCoordinateWriter,
		T target,
		double searchTime,
		mreal_t epsilon,
		WriterPtr<T> pWriter,
		std::ostream& outputStream) {

	if(pFindResultIter == NullPtr) {
		return;
	}

	//Collect all results into a vector
	ElementWithDistances<T> results;
	getSortedResults(pFindResultIter, pDistanceCaculator, target, results);

	//Output some general information
	outputStream << "--------------------------" << END_LINE;
	outputStream << "Number of results:" << results.size() << END_LINE;

	CoordinatePtr<T, mreal_t> pQueryCoordinate = NullPtr;
	if(pRealCoordinateCalculator != NullPtr) {
		pRealCoordinateCalculator->calulateElementCoordinate(target, pQueryCoordinate);
		outputStream << "Query coordinate:" << END_LINE;
		pRealCoordinateWriter->writeCoordinate(*pQueryCoordinate, outputStream);
		outputStream << END_LINE;
		_destroy(pQueryCoordinate);
	}

	//Output (log) each result
	for(unsigned int i = 0; i < results.size(); i++) {
		T result = results[i].m_resultElement;
		mreal_t precision = results[i].m_distanceToTarget;

		//outputStream << "Result " << i << END_LINE;

		//Calculate result coordinate
		CoordinatePtr<T, mreal_t> pCoordinate = NullPtr;
		if(pRealCoordinateCalculator != NullPtr) {
			pRealCoordinateCalculator->calulateElementCoordinate(result, pCoordinate);
		}

		//Log result (gate or matrix or anything)
		logSearchResult(target,
				result,
				searchTime,
				precision,
				epsilon,
				pWriter,
				pCoordinate,
				pRealCoordinateWriter,
				outputStream);

		_destroy(pCoordinate);
	}
	outputStream << "Number of results:" << results.size() << END_LINE;
}
Ejemplo n.º 2
0
void SearchSpaceTimerEvaluatorImpl<T>::releaseResultIter(IteratorPtr<LookupResult<T> >& pFindResultIter) {
	while(pFindResultIter != NullPtr && !pFindResultIter->isDone()) {
		T element = pFindResultIter->getObj().m_resultElement;
		pFindResultIter->next();
		_destroy(element);
	}
	_destroy(pFindResultIter);
	pFindResultIter = NullPtr;
}
Ejemplo n.º 3
0
void GateCombinerImpl::combine(GatePtr pGate1, GatePtr pGate2, GatePtr& result) {
	result = NullPtr;

	for(unsigned int i = 0; i< m_combinabilityCheckers.size(); i++) {
		if(!m_combinabilityCheckers[i]->canCombine(pGate1, pGate2)) {
			return;
		}
	}

	MatrixPtr pCombinedMatrix = NullPtr;
	m_pMatrixOperator->multiply(pGate1->getMatrix(), pGate2->getMatrix(), pCombinedMatrix);

	//If combined matrix is actually identity, abort the combination
	if(!checkIdentity(pCombinedMatrix)) {
		_destroy(pCombinedMatrix);
		return;
	}

	cost_t combinedCost = pGate1->getCost() + pGate2->getCost();

	LabelSeq combinedLabel;
	combinedLabel.insert(combinedLabel.end(), pGate1->getLabelSeq().begin(), pGate1->getLabelSeq().end());
	combinedLabel.insert(combinedLabel.end(), pGate2->getLabelSeq().begin(), pGate2->getLabelSeq().end());

	std::string combinedLabelStr = pGate1->getLabelStr() + pGate2->getLabelStr();

	result = GatePtr(new Gate(pCombinedMatrix, combinedCost, combinedLabel, combinedLabelStr));

}
TaskResult<LookupResult<T> > ElementsCombinationVerifyTask<T>::execute() {
	int resultCode = TaskResultCode::TRC_UNKNOWN;
	LookupResult<T> lookupResult;

	T candidate;
	composeCandidate(m_elements, candidate);
	if(candidate != NullPtr) {
		if(m_pDistanceCalculator != NullPtr) {
			mreal_t distanceToTarget = m_pDistanceCalculator->distance(candidate, m_target);
			if(distanceToTarget <= m_epsilon) {
				lookupResult.m_distanceToTarget = distanceToTarget;
				lookupResult.m_resultElement = candidate;
				onCombinationVerified(lookupResult);
				resultCode = TaskResultCode::TRC_POSITIVE;
			}
			else {
				_destroy(candidate);
				resultCode = TaskResultCode::TRC_NEGATIVE;
			}
		}
		else {
			//Store candidate in result for future purpose
			lookupResult.m_resultElement = candidate;
		}
	}

	TaskResult<LookupResult<T> > result;
	result.m_resultCode = resultCode;
	result.m_executeResult = lookupResult;
	result.m_status = TRS_READY;
	return result;
}
void ComposerBasedElementApproximator<T>::releaseBuildingBlocksBuckets(BuildingBlockBuckets<T>& buildingBlockBuckets) {
	for(typename BuildingBlockBuckets<T>::iterator bIter = buildingBlockBuckets.begin(); bIter != buildingBlockBuckets.end();) {
		IteratorPtr<T> pIter = *bIter;
		bIter = buildingBlockBuckets.erase(bIter);
		_destroy(pIter);
	}
}
void ComposerBasedElementApproximator<T>::decomposeQueryIntoBuildingBlocksBuckets(CollectionPtr<T> pCoreCollection,
		T pQuery,
		DistanceCalculatorPtr<T> pDistanceCalculator,
		BuildingBlockBuckets<T>& buildingBlockBuckets) {
	buildingBlockBuckets.clear();

	std::vector<T> partialQueries;
	m_pQueryDecomposer->decomposeElement(pQuery,
			partialQueries,
			m_nbPartialQueries);

	combination_counter_t maximumNbCombinations = 1;
	for(unsigned int i = 0; i < partialQueries.size(); i++) {
		//Get buiding block list for partial query
		IteratorPtr<LookupResult<T> > pLookupIter = getApproximateElementsForPartialQuery(pCoreCollection,
				partialQueries[i],
				m_initialEpsilon);

		//Add found building blocks to the bucket to compose later
		buildingBlockBuckets.push_back(getExtractedElementIterator(pLookupIter,
				&maximumNbCombinations));

		_destroy(pLookupIter);
	}
	std::cout << "Maximum number of combinations " << maximumNbCombinations << "\n";

	//TODO Release elements in partialQueries
}
void releasePointerVector(std::vector<EPtr> vect) {
	for(typename std::vector<EPtr>::iterator bIter = vect.begin(); bIter != vect.end();) {
		EPtr pE = *bIter;
		_destroy(pE);
		bIter = vect.erase(bIter);
	}
}
Ejemplo n.º 8
0
	/**
	 * Delete and add a resource ("dadd").
	 * @param index Resource index.
	 * @param obj Pointer to object data.
	 * @param type Resource type.
	 */
	int ResourceArray::_dadd(unsigned index, void* obj, byte type) {
		if(index&DYNAMIC_PLACEHOLDER_BIT) {
			unsigned pIndex = index&(~DYNAMIC_PLACEHOLDER_BIT);
			TESTINDEX(pIndex, mDynResSize);
			if(mDynRes[pIndex] != NULL) {
				_destroy(index);
			}
			return _add(index, obj, type);
		} else {
			TESTINDEX(index, mResSize);
			if(mRes[index] != NULL) {
				_destroy(index);
			}
			return _add(index, obj, type);
		}
	}
Ejemplo n.º 9
0
void
Value::resetAsArray(size_t reserved_size)
{
	_destroy();
	m_type = ValueType::ARRAY;
	m_data = new array_type(reserved_size, Value(0));
}
Ejemplo n.º 10
0
 void Window::destroy()
 {
     if(m_status != StatusNull)
     {
     	_destroy();
     	WindowManager::Get().unregisterWindow(getName());
     }
 }
Ejemplo n.º 11
0
// ---------------------------------------------------------------------------
// Destructeur
// -----------
bStdExtLib::~bStdExtLib(){
	if(_destroy&&_inst){
		_destroy(_inst);
	}
	if(_bndl){
		CFRelease(_bndl);
	}
}
Ejemplo n.º 12
0
/**
 * \brief Assignment operator.
 * \param[in] other Another lexeme sequence to assign to the current object.
 * \returns Reference to the original object after assignment.
 */
Lexeme &Lexeme::operator =(const Lexeme &other)
{
    if (this != &other) {
        _destroy();
        _assign(other);
    }
    return *this;
}
Ejemplo n.º 13
0
int ResourceBase::destroy( void )
{
	int c = mRefCounter.deref();
	if( c == 0 ) {
		_destroy();
	}
	return c;
}
Ejemplo n.º 14
0
//--
Personne& Personne::operator=(const Personne& aP)
{
 if (this != &aP)
 {
  _destroy();
  _copy(aP);
 }
 return *this;
}
Ejemplo n.º 15
0
int main(int argc, char *argv[]) {
	_init(argc, argv);

	_do();

	_destroy();

	return 0;
}
Ejemplo n.º 16
0
Character			&Character::operator=(Character const &rhs)
{
	int					i;

	_name = rhs._name;
	_destroy();
	for (i = 0; i < 4; i++)
		_mats[i] = rhs._mats[i];
	return (*this);
}
Ejemplo n.º 17
0
bool LoadableObject::destroy()
{
  if (isInitialized())
  {
    // Call the virtual implementation
    m_bIsInitialized = _destroy();
  }

  return !isInitialized();
}
Ejemplo n.º 18
0
//--
Etudiant& Etudiant::operator=(const Etudiant& anE)
{
 if (this != &anE)
 {
  Personne::operator=(anE);
  _destroy();
  _copy(anE);
 }
 return *this;
}
Ejemplo n.º 19
0
ExtmethodFace::~ExtmethodFace() {
    if (_implementation != nullptr) {
        _destroy(_implementation);
        dlerror(); // Reset errors
        assert(_lib_handle != nullptr);
        if (dlclose(_lib_handle)) {
            cerr << dlerror() << endl;
        }
    }
}
Ejemplo n.º 20
0
void
index_buffer::_move(index_buffer &other_one)
{
  _destroy();

  index_buffer &this_one       = *this;
  this_one.m_index_buffer      = other_one.m_index_buffer;
  this_one.m_number_of_indices = other_one.m_number_of_indices;
  
  other_one.m_index_buffer      = 0;
  other_one.m_number_of_indices = 0;
}
void ElementsCombinationVerifyTask<T>::composeCandidate(const std::vector<T>& elements, T& result) {
	T combined = elements.empty() ? NullPtr : elements[0]->clone();
	for(unsigned int i = 1; i < elements.size() && combined != NullPtr; i++) {
		if(elements[i] != NullPtr) {
			T tmp = NullPtr;
			m_pCombiner->combine(combined, elements[i], tmp);
			_destroy(combined);
			combined = tmp;
		}
	}
	result = combined;
}
Ejemplo n.º 22
0
/*
 * This routine should revert to the persist_state_new() state,
 * e.g. just like the PersistState object wasn't started yet.
 */
void
persist_state_cancel(PersistState *self)
{
  gchar *commited_filename, *temp_filename;
  commited_filename = g_strdup(self->commited_filename);
  temp_filename = g_strdup(self->temp_filename);

  _destroy(self);

  memset(self, 0, sizeof(*self));

  _init(self, commited_filename, temp_filename);
}
Ejemplo n.º 23
0
void
vertex_buffer::_move(vertex_buffer &this_one, vertex_buffer &other_one)
{
  _destroy();

  this_one.m_vertex_buffer   = other_one.m_vertex_buffer;
  this_one.m_buffer_size     = other_one.m_buffer_size;
  this_one.m_number_entries  = other_one.m_number_entries;

  other_one.m_vertex_buffer  = 0;
  other_one.m_buffer_size    = 0;
  other_one.m_number_entries = 0;
}
Ejemplo n.º 24
0
void WorldSynthesis::_setFftLength(int fftLength)
{
    _destroy();
    _fftLength = fftLength;
    if(!fftLength)
    {
        return;
    }
    _minimumPhase = new MinimumPhaseAnalysis;
    InitializeMinimumPhaseAnalysis(fftLength, _minimumPhase);
    _spectrum = new fft_complex[fftLength / 2 + 1];
    _impulse = new double[fftLength];
    _plan = new fft_plan;
    *_plan = fft_plan_dft_c2r_1d(fftLength, _spectrum, _impulse, FFT_BACKWARD);
}
Ejemplo n.º 25
0
	/**
	 * Destructor.
	 */
	ResourceArray::~ResourceArray() {
		// Destroy static resources
		for(unsigned i=1; i<mResSize; ++i) {
			LOGD("RA %i\n", i);
			_destroy(i);
		}
		delete[] mRes;
		delete[] mResTypes;

		// Destroy dynamic resources.
		for(unsigned i=1; i<mDynResSize; ++i) {
			LOGD("DA %i\n", i);
			if (RT_NIL != mDynResTypes[i]) {
				_destroy(i | DYNAMIC_PLACEHOLDER_BIT);
			}
		}
		if(mDynRes) {
			delete[] mDynRes;
			delete[] mDynResTypes;
		}
		if(mDynResPool) {
			delete[] mDynResPool;
		}
	}
Ejemplo n.º 26
0
const bool DestructableLayer::damage(const int x, const int y, const int hp) {
    const int i = _w * y + x;
    if (i < 0 || i >= _w * _h)
        return false;
    //LOG_DEBUG(("damage %d to cell %d (hpdata[] = %d)", hp, i, _hp_data[i]));
    if (_hp_data[i] <= 0)
        return false;
    //LOG_DEBUG(("damage %d to cell %d (hpdata[] = %d)", hp, i, _hp_data[i]));

    _hp_data[i] -= hp;
    if (_hp_data[i] > 0)
        return false;

    _destroy(x, y);
    return true;
}
Ejemplo n.º 27
0
CMyProblem& CMyProblem::operator= (const CMyProblem &src)
{
	if (this == &src)
		return *this;

	if (src.n!=n)
		_destroy();

	if (src.IsInvalid())
	{
		n=0;
		return *this;
	}

	_alloc(src.n);
	_copy(src);
	return *this;
}
Ejemplo n.º 28
0
bool
index_buffer::load_index_buffer(const std::vector<uint32_t> &index)
{
  if(m_index_buffer)
  {
    _destroy();
  }
  
  m_number_of_indices = static_cast<uint32_t>(index.size());

  glGenBuffers(1, &m_index_buffer);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(index), &index[0], GL_STATIC_DRAW);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  check_and_log_error("index_buffer::load_index_buffer - loading buffer.");

  return  (is_valid() ? true : false);
}
Ejemplo n.º 29
0
Archivo: main.c Proyecto: lparam/BBBlfs
int
main(int argc, const char *argv[]) {
    int rc;
    libusb_context *ctx = NULL;
    libusb_hotplug_callback_handle handles[3];

    _init(ctx);

    if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
        printf("Hotplug not supported by this build of libusb\n");
        libusb_exit (NULL);
        return EXIT_FAILURE;
    }

    rc = libusb_hotplug_register_callback(ctx,
      LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
      0, ROMVID, ROMPID, LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL, &handles[0]);

    rc = libusb_hotplug_register_callback(ctx,
      LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
      0, SPLVID, SPLPID, LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL, &handles[1]);

    rc = libusb_hotplug_register_callback(ctx,
      LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
      0, UBOOTVID, UBOOTPID, LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL, &handles[2]);

    if (LIBUSB_SUCCESS != rc) {
        fprintf(stderr, "Error registering callback 0\n");
        libusb_exit(NULL);
        return EXIT_FAILURE;
    }

    while (!finished) {
        rc = libusb_handle_events(ctx);
        if (rc) {
			printf("libusb_handle_events() failed: %s\n", libusb_error_name(rc));
        }
    }

    _destroy(ctx);

    return 0;
}
void ParallelGateCoordinateAdditionBasedComposerContainerImpl::overrideCoordinateAdditionalBasedGateComposer() {
	_destroy(m_pGateCoordinateComposer);

	RealCoordinate<GatePtr> epsilonRealCoordinate;
	GateCoordinateAdditionBasedComposerContainerImpl::initEpsilonRealCoordinate(epsilonRealCoordinate, m_coordinateAdditionalBasedComposerConfig.m_primaryCoordinateComparatorConfig.m_coordinateEpsilon);

	std::vector<GateRealCoordinate> epsilonRealCoordinates;
	for(unsigned int i = 0; i < m_coordinateAdditionalBasedComposerConfig.m_secondaryCoordinateComparatorConfigs.size(); i++) {
		RealCoordinate<GatePtr> secondaryEpsilonRealCoordinate;
		GateCoordinateAdditionBasedComposerContainerImpl::initEpsilonRealCoordinate(secondaryEpsilonRealCoordinate, m_coordinateAdditionalBasedComposerConfig.m_secondaryCoordinateComparatorConfigs[i].m_coordinateEpsilon);
		epsilonRealCoordinates.push_back(secondaryEpsilonRealCoordinate);
	}
	m_pGateCoordinateComposer = ComposerPtr<GateRealCoordinate>(new ParallelMultipleComparatorCoordinateAdditionBasedGateComposer(m_pPrimaryRealCoordinateComparator,
			m_pGateCoordinateCombiner,
			epsilonRealCoordinate,
			m_parallelConfig.m_taskFutureBufferSize,
			m_secondaryRealCoordinateComparators,
			epsilonRealCoordinates,
			m_pTaskExecutor));
}