Exemple #1
0
/**
  <summary>
  Releases a valid red black tree
  <summary>
  <param name="tree">The tree to release</param>
  <remarks>
  The tree must have been created using jsw_rbnew
  </remarks>
*/
void jsw_rbdelete ( jsw_rbtree_t *tree )
{
  jsw_rbnode_t *it = tree->root;
  jsw_rbnode_t *save;

  /*
    Rotate away the left links so that
    we can treat this like the destruction
    of a linked list
  */
  while ( it != NULL ) {
    if ( it->link[0] == NULL ) {
      /* No left links, just kill the node and move on */
      save = it->link[1];
      jsw_keyFree( tree, it->key );
      free ( it );
    }
    else {
      /* Rotate away the left link and check again */
      save = it->link[0];
      it->link[0] = save->link[1];
      save->link[1] = it;
    }

    it = save;
  }

  free ( tree );
}
Exemple #2
0
//------------------------------------------------------------------------------
AMemory::~AMemory()
{
	if(mHeap)
	{
		free(mHeap);
		mHeap = 0x0;
	}
}
Exemple #3
0
void jsw_keyFree( jsw_rbtree_t *tree, void *key )
{
    if (tree->type) {
        cx_type keyType = cx_map(tree->type)->keyType;

        if (keyType->reference) {
            cx_free(*(cx_object*)key);
        } else {
            if (keyType->kind == CX_PRIMITIVE) {
                if (cx_primitive(keyType)->kind == CX_TEXT) {
                    free(*(cx_string*)key);
                }
            }
        }
        free(key);
    }
}
// Releases Data for linked objects
void EERIE_LINKEDOBJ_ReleaseData(EERIE_3DOBJ * obj)
{
	if (obj == NULL) return;

	if (obj->linked) free(obj->linked);

	obj->linked = NULL;
	obj->nblinked = 0;
}
Exemple #5
0
//------------------------------------------------------------------------------
void AMemory::Deallocate(void)
{
	if(mHeap)
	{
		free(mHeap);
		mHeap = 0x0;
		mSize = 0;
	}
}
MblMwDataProcessor::~MblMwDataProcessor() {
    delete state;
    state = nullptr;

    free(config);
    config= nullptr;

    if (remove) {
        uint8_t command[3]= { MBL_MW_MODULE_DATA_PROCESSOR, ORDINAL(DataProcessorRegister::REMOVE), header.data_id };
        send_command(owner, command, sizeof(command));
    }
}
int32_t response_handler_packed_data(MblMwMetaWearBoard *board, const uint8_t *response, uint8_t len) {
    try {
        ResponseHeader header(response[0], response[1]);
        auto signal = dynamic_cast<MblMwDataSignal*>(board->module_events.at(header));
        if (signal->handler == nullptr) {
            return MBL_MW_STATUS_WARNING_UNEXPECTED_SENSOR_DATA;
        }

        for(uint8_t i= 2; i < len; i+= CARTESIAN_FLOAT_SIZE) {
            MblMwData* data = data_response_converters.at(signal->interpreter)(false, signal, response + i, len - i);
            data->epoch= duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

            signal->handler(data);

            free(data->value);
            free(data);
        }

        return MBL_MW_STATUS_OK;
    } catch (exception) {
        return MBL_MW_STATUS_WARNING_UNEXPECTED_SENSOR_DATA;
    }
}
MblMwMetaWearBoard::~MblMwMetaWearBoard() {
    logger_state.reset();
    timer_state.reset();
    event_state.reset();
    dp_state.reset();

    for (auto it: module_events) {
        it.second->remove= false;
        delete it.second;
    }

    for (auto it: module_config) {
        free(it.second);
    }
}
void mbl_mw_metawearboard_char_read(MblMwMetaWearBoard *board, const MblMwGattChar *characteristic, const uint8_t *value, uint8_t length) {
    if (characteristic->uuid_high == DEV_INFO_FIRMWARE_CHAR.uuid_high && characteristic->uuid_low == DEV_INFO_FIRMWARE_CHAR.uuid_low) {
        if (board->firmware_revision.empty()) {
            board->firmware_revision.assign(string(value, value + length));
            board->module_discovery_index= -1;
        } else {
            Version current;
            current.assign(string(value, value + length));

            if (board->firmware_revision == current) {
                if (mbl_mw_metawearboard_is_initialized(board)) {
                    board->initialized_timeout->cancel();
                    board->initialized(board, MBL_MW_STATUS_OK);
                } else {
                    board->module_discovery_index = MODULE_DISCOVERY_CMDS.size();
                    service_discovery_completed(board);
                }
                return;
            } else {
                board->logger_state.reset();
                board->timer_state.reset();
                board->event_state.reset();
                board->dp_state.reset();

                for (auto it : board->module_events) {
                    it.second->remove = false;
                    delete it.second;
                }
                board->module_events.clear();

                for (auto it: board->module_config) {
                    free(it.second);
                }
                board->module_config.clear();

                board->module_info.clear();
                board->module_discovery_index= -1;
            }
        }
        queue_next_gatt_char(board);
    } else if (characteristic->uuid_high == DEV_INFO_MODEL_CHAR.uuid_high && characteristic->uuid_low == DEV_INFO_MODEL_CHAR.uuid_low) {
        board->module_number.assign(value, value + length);
        queue_next_gatt_char(board);
    }
}
bool loadCinematic(Cinematic * c, const res::path & file) {
	
	LogInfo << "loading cinematic " << file;
	
	size_t size;
	char * data = resources->readAlloc(file, size);
	if(!data) {
		LogError << "cinematic " << file << " not found";
		return false;
	}
	
	bool ret = parseCinematic(c, data, size);
	free(data);
	if(!ret) {
		LogError << "loading cinematic " << file;
		c->New();
	}
	
	return ret;
}
//*************************************************************************************
//*************************************************************************************
// Removes a linked object Data field from an object
static void EERIE_LINKEDOBJ_Remove(EERIE_3DOBJ * obj, long num)
{
	if (obj == NULL) return;

	if (obj->linked == NULL) return;

	if (num < 0) return;

	if (num >= obj->nblinked) return;

	if (obj->nblinked == 1)
	{
		free(obj->linked);
		obj->linked = NULL;
		obj->nblinked = 0;
		return;
	}

	memcpy(&obj->linked[num], &obj->linked[num+1], sizeof(EERIE_LINKED)*(obj->nblinked - num - 1));
	obj->linked = (EERIE_LINKED *)realloc(obj->linked, sizeof(EERIE_LINKED) * (obj->nblinked - 1));
	obj->nblinked--;
}
Exemple #12
0
/**
  <summary>
  Release a traversal object
  <summary>
  <param name="trav">The object to release</param>
  <remarks>
  The object must have been created with jsw_rbtnew
  </remarks>
*/
void jsw_rbtdelete ( jsw_rbtrav_t *trav )
{
  free ( trav );
}
Exemple #13
0
/**
  <summary>
  Remove a node from a red black tree
  that matches the user-specified data
  <summary>
  <param name="tree">The tree to remove from</param>
  <param name="data">The data value to search for</param>
  <returns>
  1 if the value was removed successfully,
  0 if the removal failed for any reason
  </returns>
  <remarks>
  The most common failure reason should be
  that the data was not found in the tree
  </remarks>
*/
int jsw_rberase ( jsw_rbtree_t *tree, void *key )
{
  if ( tree->root != NULL ) {
    jsw_rbnode_t head = {0, NULL, NULL, {NULL,NULL}}; /* False tree root */
    jsw_rbnode_t *q, *p, *g; /* Helpers */
    jsw_rbnode_t *f = NULL;  /* Found item */
    int dir = 1;

    /* Set up our helpers */
    q = &head;
    g = p = NULL;
    q->link[1] = tree->root;

    /*
      Search and push a red node down
      to fix red violations as we go
    */
    while ( q->link[dir] != NULL ) {
      int last = dir;

      /* Move the helpers down */
      g = p, p = q;
      q = q->link[dir];
      dir = tree->cmp ( tree->type, q->key, key ) < 0;

      /*
        Save the node with matching data and keep
        going; we'll do removal tasks at the end
      */
      if ( tree->cmp ( tree->type, q->key, key ) == 0 )
        f = q;

      /* Push the red node down with rotations and color flips */
      if ( !is_red ( q ) && !is_red ( q->link[dir] ) ) {
        if ( is_red ( q->link[!dir] ) )
          p = p->link[last] = jsw_single ( q, dir );
        else if ( !is_red ( q->link[!dir] ) ) {
          jsw_rbnode_t *s = p->link[!last];

          if ( s != NULL ) {
            if ( !is_red ( s->link[!last] ) && !is_red ( s->link[last] ) ) {
              /* Color flip */
              p->red = 0;
              s->red = 1;
              q->red = 1;
            }
            else {
              int dir2 = g->link[1] == p;

              if ( is_red ( s->link[last] ) )
                g->link[dir2] = jsw_double ( p, last );
              else if ( is_red ( s->link[!last] ) )
                g->link[dir2] = jsw_single ( p, last );

              /* Ensure correct coloring */
              q->red = g->link[dir2]->red = 1;
              g->link[dir2]->link[0]->red = 0;
              g->link[dir2]->link[1]->red = 0;
            }
          }
        }
      }
    }

    /* Replace and remove the saved node */
    if ( f != NULL ) {
      f->key = q->key;
      f->data = q->data;
      p->link[p->link[1] == q] =
        q->link[q->link[0] == NULL];
      free ( q );
    }

    /* Update the root (it may be different) */
    tree->root = head.link[1];

    /* Make the root black for simplified logic */
    if ( tree->root != NULL )
      tree->root->red = 0;

    --tree->size;
  }

  return 1;
}
Exemple #14
0
ConvexHull::~ConvexHull() {
    free(this->points);
}