bool ParticleChannelInt::Spawn(Tab<int>& spawnTable)
{
	SysUtil::NeedToImplementLater(); // optimize the implementation

	int i, checkCount = min(spawnTable.Count(), Count());

	if (isGlobal())
	{
		int newCount = 0;
		for(i=0; i<checkCount; i++)
			if (spawnTable[i] > 0) newCount += spawnTable[i];
		_globalCount() = newCount;
	}
	else
	{
		Tab<int> oldData(data());
		int j, k, newCount = 0;
		for(i=0; i<checkCount; i++)
			if (spawnTable[i] > 0) newCount += spawnTable[i];
		_data().SetCount(newCount);
		for(i=0, j=0; i<checkCount; i++)
			for(k=0; k<spawnTable[i]; k++)
				_data(j++) = oldData[i];
	}
	return true;
}
int ParticleChannelInt::Delete(BitArray& toRemove)
{	
	int checkCount = min(toRemove.GetSize(), Count());

	if (isGlobal())
	{
		// find number of set bit in the "count" range
		int numRemove = 0;
		for(int i=0; i<checkCount; i++)
			if (toRemove[i] != 0) numRemove++;
		_globalCount() -= numRemove;
		return globalCount();
	}
	else
	{
		int i, j;
		for (i = j = 0; i < data().Count(); i++) {
			if (i < checkCount && toRemove[i] != 0)
				continue;
			if (i != j)	_data(j) = data(i);
			j++;
		}
		if (j < data().Count())
			_data().SetCount(j);
		return data().Count();
	}
}
IOResult ParticleChannelInt::Load(ILoad* iload)
{
	ULONG nb;
	IOResult res;
	int num, v;
	Interface_ID id;
	bool isg;

	while (IO_OK==(res=iload->OpenChunk()))
	{
		switch(iload->CurChunkID())
		{
		case IParticleChannel::kChunkCount:
			res=iload->Read(&num, sizeof(int), &nb);
			if (res == IO_OK) _data().SetCount(num);
			break;
		case IParticleChannel::kChunkData:
			num = data().Count();
			DbgAssert(num > 0);
			res=iload->Read(_data().Addr(0), sizeof(int)*num, &nb);
			break;
		case IParticleChannel::kChunkGlobalCount:
			res=iload->Read(&num, sizeof(int), &nb);
			if (res == IO_OK) _globalCount() = num;
			break;
		case IParticleChannel::kChunkGlobalValue:
			res=iload->Read(&v, sizeof(int), &nb);
			if (res == IO_OK) _globalValue() = v;
			break;
		case IParticleChannel::kChunkReadID:
			res=iload->Read(&id, sizeof(Interface_ID), &nb);
			if (res == IO_OK) SetReadID(id);
			break;
		case IParticleChannel::kChunkWriteID:
			res=iload->Read(&id, sizeof(Interface_ID), &nb);
			if (res == IO_OK) SetWriteID(id);
			break;
		case IParticleChannel::kChunkTransferable:
			res=iload->Read(&isg, sizeof(bool), &nb);
			if (res == IO_OK) SetTransferable(isg);
			break;
		case IParticleChannel::kChunkPrivate:
			res=iload->Read(&m_isPrivate, sizeof(bool), &nb);
			break;
		case IParticleChannel::kChunkActionHandle:
			res=iload->Read(&m_creatorHandle, sizeof(ULONG), &nb);
			break;
		case IParticleChannel::kChunkValue1:
			res=iload->Read(&isg, sizeof(bool), &nb);
			if (res == IO_OK) _isGlobal() = isg;
			break;
		}
		iload->CloseChunk();
		if (res != IO_OK)
			return res;
	}

	return IO_OK;
}
matDouble quaternion::returnVectorPart()
{
	matDouble data(3, 1);
	data(1, 1) = _data(2, 1);
	data(2, 1) = _data(3, 1);
	data(3, 1) = _data(4, 1);
	return data; 
}
quaternion::quaternion(double a, double b, double c, double d)
{
	matDouble data(4, 1);
	_data = data; 
	_data(1, 1) = a; 
	_data(2, 1) = b;
	_data(3, 1) = c;
	_data(4, 1) = d;
}
Example #6
0
void *_pktbuf_internal_alloc(size_t size)
{
    _used_t *node = _head(), *old_next, *new_next;

    if ((size == 0) || (size > NG_PKTBUF_SIZE)) {
        return NULL;
    }

    if (node->size == 0) {          /* if head is currently not initialized */
        if (node->next == NULL || (_start_idx(node->next) >= _total_sz(size))) {
            /* if enough space is there */
            node->size = size;  /* just take it */
            node->pkts = 1;

            return _data(node);
        }
        else if (node->next != NULL) {
            /* else go directly to next allocation if it exists */
            node = node->next;
        }
    }

    while ((node->next != NULL)
           /* and if space between current and next allocation is not big enough */
           && ((_start_idx(node->next) - _end_idx(node)) < _total_sz(size))) {
        node = node->next;
    }

    /* jump ahead size of current packet */
    new_next = (_used_t *)(((uint8_t *)node) + __al_total_sz(node));

    if ((((uint8_t *)new_next) + size) > (((uint8_t *)_head()) + NG_PKTBUF_SIZE)) {
        /* new packet does not fit into _pktbuf */
        return NULL;
    }

    old_next = node->next;
    node->next = new_next;
    node->next->next = old_next;

    node = new_next;
    node->size = size;
    node->pkts = 1;

#ifdef DEVELHELP

    if ((_end_idx(node) + 1) > _pktbuf_max_bytes) {
        _pktbuf_max_bytes = _end_idx(node) + 1;
    }

#endif

    return _data(node);
}
void ParticleChannelInt::SetValue(int index, int value)
{
	if (isGlobal())
	{
		if (value == globalValue()) return; // nothing to change
		_isGlobal() = false;
		_data().SetCount(globalCount());
		for(int i=0; i<globalCount(); i++)
			_data(i) = globalValue();
	}
	DbgAssert((index>=0) && (index<data().Count()));
	_data(index) = value;
}
Example #8
0
uint16_t data(uint8_t* buf, ujvalue* v)
{
	uint8_t* bufstart;
	bufstart = buf;
	_data(&buf, v, 0);
	return (uint16_t)(buf - bufstart);
}
bool ParticleChannelInt::SetCount(int n)
{
	if (n < 0) return false;
	if (isGlobal()) _globalCount() = n;
	else _data().SetCount(n);
	return true;
}
Example #10
0
void phdGuiVerFader::onMouseDragged(ofMouseEventArgs & args) {
	argsDrag = args;
	if(!compareMouseEventArgs(argsPress, argsDrag)) {

		if(hitFader == phfSlider || hitFader == phfDuration) {

			phdGuiEventData _data(petOnDrag, this);

			if(hitFader == phfDuration) {

				_data.tag = "DURATION";
				if(fader != NULL) fader->setPosDurationByCoord(args.x, args.y);

			} else if(hitFader == phfSlider) {

				_data.tag = "VALUE";

				if(fader != NULL) {
					fader->setValueByCoord(args.x, args.y);
					value = fader->getValue();
				}
			}

			ofNotifyEvent(guiEvent, _data, this);
		}
		argsPress = argsDrag;
	}
}
Example #11
0
void phdGuiVerSlider::onMouseReleased(ofMouseEventArgs & args) {
	if(!compareMouseEventArgs(argsPress, argsDrag)) { // drag != press => has a click

		phdGuiEventData _data(petOnClick, this);
		ofNotifyEvent(guiEvent, _data, this);

	}
}
Example #12
0
File: sbus.c Project: josvazg/sbus
/**
 Recepción Temporizada (en ms) de datos de SBUS a través de este enlace

 @param libsbus es el enlace SBUS
 @param msgtag contendrá el código identificativo del tipo de mensaje enviado
 @param peerid contendrá el identificativo del enviante del mensaje
 @param data son los datos del mensaje
 @param bytes es el tamaño máximo de data

 @return bytes recibidos, 0 en caso de timeout o -1 en caso de error
*/
int sbus_recv(SBusType sbus, int* pmsgtag, int* pch2peer, char *data, int bytes) {
  int res;
  string _data(data,bytes);
  res=sbus->sbus->recv(pmsgtag,(SBusPeer*)pch2peer,_data);
  if(res>0) {
    memcpy(data,_data.data(),res);
  }
  return res;
}
Example #13
0
CMPIStatus KBase_SetToArgs(
    const KBase* self, 
    CMPIBoolean in,
    CMPIBoolean out,
    CMPIArgs* ca)
{
    KPos pos;

    /* Check parameters */

    if (!ca || !self || self->magic != KMAGIC)
    {
        KReturn(ERR_FAILED);
    }

    /* Set properties */

    KFirst(&pos, self);

    while (KMore(&pos))
    {
        CMPIData cd;
        const KValue* value = (const KValue*)pos.field;

        do
        {
            CMPIStatus st;

            if (!value->exists)
                break;

            cd = _data(value, pos.tag);

            if (in && !(pos.tag & KTAG_IN))
                break;

            if (out && !(pos.tag & KTAG_OUT))
                break;

            if (value->null)
                st = CMAddArg(ca, pos.name, NULL, cd.type);
            else
                st = CMAddArg(ca, pos.name, &cd.value, cd.type);

            if (!KOkay(st))
            {
                printf("%s() failed on %s\n", __FUNCTION__, pos.name);
            }
        }
        while (0);

        KNext(&pos);
    }

    KReturn(OK);
}
Example #14
0
void
Adjoint::construct(const Rotation& R, const Translation& T)
{
  _data = arma::zeros<arma::mat>(6, 6);
  arma::colvec::fixed<3> v;

  v(0) = T.at(0); v(1) = T.at(1); v(2) = T.at(2);
  Skew S(v);
  arma::mat::fixed<3, 3> R2 = S._data*R._data;

  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
    {
      _data(i, j + 3) = R2(i, j);
      _data(i, j) = _data(i + 3, j + 3) = R.at(i, j);
    }
  _R = R;
  _T = T;
}
Example #15
0
static void hd44870_send(unsigned char data, char is_cmd) 
{
  io_delay();
  
  bus4w &=~(_EN|_RW);       
  _rswe();
  //io_delay();
  
  if(is_cmd)
  	 bus4w&=~_RS;  //RS=0,command
  else
  	 bus4w|=_RS;  //RS=1, data
  _rswe();
  io_delay();
  
  /* 4 MSB*/
  bus4w &= ~(_DATA);    
  bus4w |= data&_DATA; 
  _data();
  
  io_delay();
  bus4w |=_EN;  
  _rswe();
  io_delay(); 
  bus4w &=~_EN;   
  _rswe();

  io_delay();
  
  /*send low 4 lsb*/
  bus4w&=~_DATA;         
  bus4w|=(data<<4)&_DATA; 
  _data();
  io_delay();

  bus4w |=_EN;  
  _rswe();
  io_delay(); 
  bus4w &=~_EN;   
  _rswe();
  
  
}
void ParticleChannelInt::SetValue(int value)
{
	if (!isGlobal())
	{
		_isGlobal() = true;
		_globalCount() = data().Count();
		_data().Resize(0);
	}
	_globalValue() = value;
}
Example #17
0
bool
Adjoint::operator ==(const Adjoint& A)
{
  bool isEqual = true;
  for(int i = 0; i < 6; ++i)
    for(int j = 0; j < 6; ++j)
      isEqual = (isEqual && (fabs(_data(i, j) - A._data(i, j)) < 1e-10));

  return isEqual;
}
Example #18
0
CMPIObjectPath* KBase_ToObjectPath(
    const KBase* self, 
    CMPIStatus* st)
{
    KPos pos;
    CMPIObjectPath* cop;

    /* Check parameters */

    if (self->magic != KMAGIC)
    {
        KSetStatus(st, ERR_FAILED);
        return NULL;
    }

    /* Create object path */

    KFirst(&pos, self);

    if (!(cop = CMNewObjectPath(self->cb, KChars(self->ns), pos.classname, 
        st)))
    {
        return NULL;
    }

    /* Set keys */

    while (KMore(&pos))
    {
        CMPIData cd;
        const KValue* value = (const KValue*)pos.field;

        if (value->exists && (pos.tag & KTAG_KEY))
        {
            CMPIStatus st;

            cd = _data(value, pos.tag);

            if (value->null)
                st = CMAddKey(cop, pos.name, NULL, cd.type);
            else
                st = CMAddKey(cop, pos.name, &cd.value, cd.type);

            if (!KOkay(st))
            {
                /* ATTN: log this but do not return! */
            }
        }

        KNext(&pos);
    }

    return cop;
}
// _____________________________________________________________________________
string ResultTable::asDebugString() const {
  std::ostringstream os;
  os << "First (up to) 5 rows of result with size:\n";
  for (size_t i = 0; i < std::min<size_t>(5, _data.size()); ++i) {
    for (size_t j = 0; j < _data.cols(); ++j) {
      os << _data(i, j) << '\t';
    }
    os << '\n';
  }
  return os.str();
}
Example #20
0
void phdGuiVerSlider::onMouseDragged(ofMouseEventArgs & args) {
	argsDrag = args;
	if(!compareMouseEventArgs(argsPress, argsDrag)) {
		value = ofMap(args.y - this->getScreenY(), this->getHeight(), 0.0, 0.0, 1.0, true);

		phdGuiEventData _data(petOnDrag, this);
		ofNotifyEvent(guiEvent, _data, this);

		argsPress = argsDrag;
	}
}
double	quaternion::operator()(const long long  rhs)
{
	if (rhs <= 4 && rhs > 0 )
	{
		return _data(1, rhs);
	}
	else
	{
		error("operator() -> wrong indexing :: Only 1 to 4 ");
		return -10000;
	}
}
bool ParticleChannelInt::AppendNum(int num)
{
	if (num <= 0)	return true;

	if (isGlobal())
	{
		_globalCount() += num;
		return true;
	}

	int oldCount = data().Count();
	int newCount = oldCount + num;

	if (_data().Resize(newCount) == 0) return false;
	_data().SetCount(newCount);

	for(int i=oldCount; i<newCount; i++)
		_data(i) = 0;

	return true;
}
Example #23
0
int ibsPut(const int id, const char* key, const size_t keyLength, const char* data, const size_t dataLength) {
    IBS_CHECK_ID(id);
    DataChunk _key(key, keyLength);
    DataChunk _data(data, dataLength);
    ibs::StatusCode status;
    status = ibs->put(std::move(_key), std::move(_data));
    if (status.ok())
        return 0;
    else {
        return errorCodeFromStatusCode(status);
    }
}
void SnapshotActionDialog::addSnapshotChild(int row, const QModelIndex &parent, char *name)
{
    // flags: extra flags; not used yet, so callers should always pass 0
    virDomainSnapshotPtr snapShot =
            virDomainSnapshotLookupByName(domain, name, 0);
    char *xmlDesc = virDomainSnapshotGetXMLDesc(snapShot, 0);
    QString _desc;
    QString _data(" -- ");
    if ( NULL!=xmlDesc ) {
        QDomDocument doc;
        doc.setContent(QString(xmlDesc));
        free(xmlDesc);
        QDomElement _el = doc
                .firstChildElement("domainsnapshot")
                .firstChildElement("creationTime");
        if ( !_el.isNull() ) {
            _data.clear();
            _data.append(
                  QDateTime::fromMSecsSinceEpoch(
                      _el.text().toULongLong()*1000)
                        .toString("yyyy-MM-dd_HH:mm:ss"));
        };
        _el = doc
                .firstChildElement("domainsnapshot")
                .firstChildElement("description");
        if ( !_el.isNull() ) {
            _desc.clear();
            _desc.append(_el.text());
        };
    };
    // flags: extra flags; not used yet, so callers should always pass 0
    int current = virDomainSnapshotIsCurrent(snapShot, 0);
    if ( NULL!=snapShot ) {
        model->insertRow(row, parent);
        model->setData(model->index(row, 0, parent), name, Qt::DisplayRole);
        model->setData(model->index(row, 0, parent), (current>0), Qt::DecorationRole);
        model->setData(model->index(row, 0, parent), _desc, Qt::ToolTipRole);
        model->setData(model->index(row, 1, parent), _data, Qt::DisplayRole);
        // By default, this command covers only direct children; use flag=0
        int namesLen = virDomainSnapshotNumChildren(snapShot, 0);
        if ( namesLen>0 ) {
            char *names;
            int ret = virDomainSnapshotListChildrenNames(
                        snapShot, &names, namesLen, 0);
            if ( ret>0 ) {
                for (int i = 0; i<ret; i++) {
                    addSnapshotChild(i, model->index(row, 0, parent), (&names)[i]);
                };
            };
        };
        virDomainSnapshotFree(snapShot);
    };
}
Example #25
0
void phdGuiTitleBar::onMouseDragged(ofMouseEventArgs & args) {
	argsDrag = args;
	if(!compareMouseEventArgs(argsPress, argsDrag)) {
		if(getParent() != NULL) {
			float dx = argsDrag.x - argsPress.x;
			float dy = argsDrag.y - argsPress.y;
			getParent()->setPosition(getParent()->getX() + dx, getParent()->getY() + dy);

			phdGuiEventData _data(petOnDrag, this);
			ofNotifyEvent(guiEvent, _data, this);
		}
		argsPress = argsDrag;
	}
}
Example #26
0
int ibsPutTransaction(const int id, const int transactionId, const char* key, const size_t keyLength, const char* data,
                      const size_t dataLength) {
    IBS_CHECK_ID(id);
    std::string transactionUuid;
    bool isValid = ibs::Transaction::getUuidFromId(transactionId, transactionUuid);
    if (isValid) {
        DataChunk _key(key, keyLength);
        DataChunk _data(data, dataLength);
        bool isAlreadyPresent = ibs->put(transactionUuid, std::move(_key), std::move(_data));
        return isAlreadyPresent ? IBS__KEY_ALREADY_ADDED : 0;
    }
    else {
        return IBS__INVALID_TRANSACTION_ID;
    }
}
Example #27
0
BPicture *
FlattenPictureTest::SaveAndRestore(BPicture *picture)
{
	BMallocIO *data = new BMallocIO();
	AutoDelete<BMallocIO> _data(data);
	TEST_AND_RETURN(data == NULL, "BMallocIO could not be allocated for flattening the picture!" , NULL);
	
	picture->Flatten(data);
	
	data->Seek(0, SEEK_SET);
	BPicture *archivedPicture = new BPicture();
	TEST_AND_RETURN(archivedPicture == NULL, "BPicture could not be allocated for unflattening the picture!" , NULL);
	archivedPicture->Unflatten(data);
		
	return archivedPicture;
}
Example #28
0
// write settings to spool folder attribute
void 
PrinterDriver::_WriteSettings(const char* attrName, BMessage* settings)
{
	if (settings == NULL || settings->what != 'okok') return;
	
	size_t size;
	char* data;
	
	size = settings->FlattenedSize();
	data = new char[size];
	auto_ptr<char> _data(data);
	
	if (data != NULL && settings->Flatten(data, size) == B_OK) {
		fSpoolFolder->WriteAttr(attrName, B_MESSAGE_TYPE, 0, data, size);
	}
}
Example #29
0
// read settings from spool folder attribute
bool 
PrinterDriver::_ReadSettings(const char* attrName, BMessage* settings)
{
	attr_info info;
	char*  data;
	ssize_t size;

	settings->MakeEmpty();
	
	if (fSpoolFolder->GetAttrInfo(attrName, &info) == B_OK && info.size > 0) {
		data = new char[info.size];
		auto_ptr<char> _data(data);
		size = fSpoolFolder->ReadAttr(attrName, B_MESSAGE_TYPE, 0, data, info.size);
		if (size == info.size && settings->Unflatten(data) == B_OK) {
			return true;
		}
	}
	return false;
}
Example #30
0
void phdGuiVerFader::onMouseReleased(ofMouseEventArgs & args) {
	if(!compareMouseEventArgs(argsPress, argsDrag)) { // drag != press => has a click

		if(hitFader == phfFadeIn || hitFader == phfFadeOut) {

			phdGuiEventData _data(petOnClick, this);

			if(hitFader == phfFadeIn) {
				_data.tag = "FADEIN";
				if(fader != NULL) fader->fadeIn();
			} else if(hitFader == phfFadeOut) {
				_data.tag = "FADEOUT";
				if(fader != NULL) fader->fadeOut();
			}

			ofNotifyEvent(guiEvent, _data, this);
		}
	}
}