Esempio n. 1
0
void _CollectionOfDaata_v_readText (_CollectionOfDaata* me, MelderReadText text, int formatVersion) {
	if (formatVersion < 0) {
		long l_size;
		autostring8 line = Melder_32to8 (MelderReadText_readLine (text));
		if (! line.peek() || ! sscanf (line.peek(), "%ld", & l_size) || l_size < 0)
			Melder_throw (U"Collection::readText: cannot read size.");
		my _grow (l_size);
		for (long i = 1; i <= l_size; i ++) {
			long itemNumberRead;
			int n = 0, length, stringsRead;
			char klas [200], nameTag [2000];
			do {
				line.reset (Melder_32to8 (MelderReadText_readLine (text)));
				if (! line.peek())
					Melder_throw (U"Missing object line.");
			} while (strncmp (line.peek(), "Object ", 7));
			stringsRead = sscanf (line.peek(), "Object %ld: class %s %s%n", & itemNumberRead, klas, nameTag, & n);
			if (stringsRead < 2)
				Melder_throw (U"Collection::readText: cannot read header of object ", i, U".");
			if (itemNumberRead != i)
				Melder_throw (U"Collection::readText: read item number ", itemNumberRead,
					U" while expecting ", i, U".");
			if (stringsRead == 3 && ! strequ (nameTag, "name"))
				Melder_throw (U"Collection::readText: wrong header at object ", i, U".");
			my at [i] = (Daata) Thing_newFromClassName (Melder_peek8to32 (klas), nullptr).releaseToAmbiguousOwner();
			my size ++;
			if (! Thing_isa (my at [i], classDaata) || ! Data_canReadText (my at [i]))
				Melder_throw (U"Cannot read item of class ", Thing_className (my at [i]), U" in collection.");
			Data_readText (my at [i], text, -1);
			if (stringsRead == 3) {
				if (line [n] == U' ') n ++;   // skip space character
				length = strlen (line.peek()+n);
				if (length > 0 && (line.peek()+n) [length - 1] == '\n')
					(line.peek()+n) [length - 1] = '\0';
				Thing_setName (my at [i], Melder_peek8to32 (line.peek()+n));
			}
		}
	} else {
		int32_t l_size = texgeti4 (text);
		my _grow (l_size);
		for (int32_t i = 1; i <= l_size; i ++) {
			autostring32 className = texgetw2 (text);
			int elementFormatVersion;
			my at [i] = (Daata) Thing_newFromClassName (className.peek(), & elementFormatVersion).releaseToAmbiguousOwner();
			my size ++;
			if (! Thing_isa (my at [i], classDaata) || ! Data_canReadText (my at [i]))
				Melder_throw (U"Cannot read item of class ", Thing_className (my at [i]), U" in collection.");
			autostring32 objectName = texgetw2 (text);
			Thing_setName (my at [i], objectName.peek());
			Data_readText (my at [i], text, elementFormatVersion);
		}
	}
}
void indri::index::DocExtentListMemoryBuilder::flush() {
  if( _locationCountPointer ) {
    // need to terminate document
    bool terminateSpace = (lemur::utility::RVLCompress::compressedSize( _extentFrequency - _lastExtentFrequency ) - 1) <= _listEnd - _list;

    if( !terminateSpace )
      _grow();

    _terminateDocument();
  }

  if( _lists.size() ) {
    _lists.back().data = _list;
    assert( _lists.back().data <= _lists.back().capacity );
  }

  assert( _documentPointer == 0 );
  assert( _locationCountPointer == 0 );

  for( int i=0; i<_lists.size(); i++ ) {
    assert( _lists[i].base <= _lists[i].capacity );
    assert( _lists[i].base <= _lists[i].data );
    assert( _lists[i].data <= _lists[i].capacity );
  }
}
void indri::index::DeletedDocumentList::markDeleted( int documentID ) {
  indri::thread::ScopedLock l( _writeLock );

  if( _bitmap.position() < (documentID/8)+1 ) {
    _grow( documentID );
  }

  _bitmap.front()[documentID/8] |= 1<<(documentID%8);
}
ssize_t VectorImpl::insertArrayAt(const void* array, size_t index, size_t length)
{
    if (index > size())
        return BAD_INDEX;
    void* where = _grow(index, length);
    if (where) {
        _do_copy(where, array, length);
    }
    return where ? index : (ssize_t)NO_MEMORY;
}
ssize_t VectorImpl::insertVectorAt(const VectorImpl& vector, size_t index)
{
    if (index > size())
        return BAD_INDEX;
    void* where = _grow(index, vector.size());
    if (where) {
        _do_copy(where, vector.arrayImpl(), vector.size());
    }
    return where ? index : (ssize_t)NO_MEMORY;
}
Esempio n. 6
0
void _CollectionOfDaata_v_readBinary (_CollectionOfDaata* me, FILE *f, int formatVersion) {
	if (formatVersion < 0) {
		int32 l_size = bingeti4 (f);
		if (l_size < 0)
			Melder_throw (U"Empty collection.");
		my _grow (l_size);
		for (int32_t i = 1; i <= l_size; i ++) {
			char klas [200], name [2000];
			if (fscanf (f, "%s%s", klas, name) < 2)   // BUG
				Melder_throw (U"Cannot read class and name.");
			my at [i] = (Daata) Thing_newFromClassName (Melder_peek8to32 (klas), nullptr).releaseToAmbiguousOwner();
			my size ++;
			if (! Thing_isa (my at [i], classDaata))
				Melder_throw (U"Cannot read item of class ", Thing_className (my at [i]), U".");
			if (fgetc (f) != ' ')
				Melder_throw (U"Cannot read space.");
			Data_readBinary (my at [i], f, -1);
			if (strcmp (name, "?"))
				Thing_setName (my at [i], Melder_peek8to32 (name));
		}
	} else {
		int32_t l_size = bingeti4 (f);
		if (Melder_debug == 44)
			Melder_casual (U"structCollection :: v_readBinary: Reading ", l_size, U" objects");
		my _grow (l_size);
		for (int32_t i = 1; i <= l_size; i ++) {
			autostring8 klas = bingets1 (f);
			if (Melder_debug == 44)
				Melder_casual (U"structCollection :: v_readBinary: Reading object of type ", Melder_peek8to32 (klas.peek()));
			int elementFormatVersion;
			my at [i] = (Daata) Thing_newFromClassName (Melder_peek8to32 (klas.peek()), & elementFormatVersion).releaseToAmbiguousOwner();
			my size ++;
			if (! Thing_isa (my at [i], classDaata) || ! Data_canReadBinary (my at [i]))
				Melder_throw (U"Objects of class ", Thing_className (my at [i]), U" cannot be read.");
			autostring32 name = bingetw2 (f);
			if (Melder_debug == 44)
				Melder_casual (U"structCollection :: v_readBinary: Reading object with name ", name.peek());
			Thing_setName (my at [i], name.peek());
			Data_readBinary (my at [i], f, elementFormatVersion);
		}
	}
}
//Adds user specified int to set if it isn't already an element.
void Set::add(const int add){
  if(!isElement(add)){
    if(!_cardinality==0){
      if((_cardinality)%(_chunk_size)==0){
      _grow();
      }
    }
    _element[_cardinality] = add;
    _cardinality++;
  }
}
ssize_t VectorImpl::insertAt(const void* item, size_t index, size_t numItems)
{
    if (index > size())
        return BAD_INDEX;
    void* where = _grow(index, numItems);
    if (where) {
        if (item) {
            _do_splat(where, item, numItems);
        } else {
            _do_construct(where, numItems);
        }
    }
    return where ? index : (ssize_t)NO_MEMORY;
}
Esempio n. 9
0
void Texture::upload( const int32_t width, const int32_t height,
                      const void* ptr )
{
    _generate();
    _grow( width, height );

    if( _impl->defined )
        glBindTexture( _impl->target, _impl->name );
    else
        resize( _impl->width, _impl->height );

    glTexSubImage2D( _impl->target, 0, 0, 0, width, height,
                     _impl->format, _impl->type, ptr );
}
void indri::index::DocExtentListMemoryBuilder::_growAddLocation( int documentID, int begin, int end, INT64 number, int ordinal, size_t newDataSize ) {
  // have to copy the last document if it's not complete, or if there's not enough room to complete it
  bool documentMismatch = (_lastDocument != documentID);
  bool terminateSpace = (lemur::utility::RVLCompress::compressedSize( _extentFrequency - _lastExtentFrequency ) - 1) <= _listEnd - _list;

  // by terminating the document now, we save a document copy and a bit of space
  if( _locationCountPointer && terminateSpace && documentID != _lastDocument )
    _terminateDocument();

  // grow the list, adding space for a document if necessary
  _grow();

  assert( newDataSize <= size_t(_listEnd - _list) );
  _safeAddLocation( documentID, begin, end, number, ordinal );
}
Esempio n. 11
0
Error BaseAssembler::embed(const void* data, uint32_t size) {
  if (getRemainingSpace() < size) {
    Error error = _grow(size);
    if (error != kErrorOk)
      return setError(error);
  }

  uint8_t* cursor = getCursor();
  ::memcpy(cursor, data, size);
  setCursor(cursor + size);

  if (_logger)
    _logger->logBinary(kLoggerStyleData, data, size);

  return kErrorOk;
}
Esempio n. 12
0
void X3D_swigAppendToMF(X3DNode* node, X3DNode* value)
{
	int num, item;
	if( node != NULL && value != NULL )
	{
		if(isMF(node->type) && isSF(value->type))
		{
			if(node->type == value->type+1)
			{
				num = node->X3D_MFNode.n;
				_grow(node,num,1);
				item = node->X3D_MFNode.n -1; 
				_X3D_setItemMF(node,item,value);
			}
		}
	}
}
Esempio n. 13
0
autoCategories Strings_to_Categories (Strings me) {
	try {
		if (my numberOfStrings < 1) {
			Melder_throw (U"Empty strings.");
		}
		autoCategories thee = Thing_new (Categories);
		thy _grow (my numberOfStrings);

		for (long i = 1; i <= my numberOfStrings; i++) {
			autoSimpleString s = SimpleString_create (my strings [i]);
			thy addItem_move (s.move());
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted.");
	}
}
Esempio n. 14
0
Error Assembler::embed(const void* data, uint32_t size) {
  if (getRemainingSpace() < size) {
    Error error = _grow(size);
    if (error != kErrorOk)
      return setError(error);
  }

  uint8_t* cursor = getCursor();
  ::memcpy(cursor, data, size);
  setCursor(cursor + size);

#if !defined(ASMJIT_DISABLE_LOGGER)
  if (_logger)
    _logger->logBinary(kLoggerStyleData, data, size);
#endif // !ASMJIT_DISABLE_LOGGER

  return kErrorOk;
}
Esempio n. 15
0
void Texture::copyFromFrameBuffer( const GLuint internalFormat,
                                   const fabric::PixelViewport& pvp )
{
    EQ_GL_ERROR( "before Texture::copyFromFrameBuffer" );
    LB_TS_THREAD( _thread );

    _generate();
    _setInternalFormat( internalFormat );
    _grow( pvp.w, pvp.h );

    if( _impl->defined )
        glBindTexture( _impl->target, _impl->name );
    else
        resize( _impl->width, _impl->height );

    glCopyTexSubImage2D( _impl->target, 0, 0, 0, pvp.x, pvp.y, pvp.w, pvp.h );
    EQ_GL_ERROR( "after Texture::copyFromFrameBuffer" );
}
Esempio n. 16
0
void str_map_add(str_map_ptr map, const char *key, void *val)
{
    _hash_t      hash = _hash(key);
    int          prime = _primes[map->prime_idx];
    _hash_t      bucket;
    _node_ptr    current;
    int          len;

    if ( !prime
            || (prime < _MAX_PRIME && map->count > 2*prime/3) ) /* Tweak Me! */
    {
        _grow(map);
        prime = _primes[map->prime_idx];
    }

    bucket = hash % prime;
    current = map->buckets[bucket];

    while (current)
    {
        if ( current->hash == hash
                && strcmp(key, current->key) == 0 )
        {
            if (map->free)
                map->free(current->val);
            current->val = val;
            return;
        }
        current = current->next;
    }

    map->count++;

    current = malloc(sizeof(_node_t));
    current->hash = hash;

    len = strlen(key);
    current->key = malloc(len + 1);
    strcpy(current->key, key);

    current->val = val;
    current->next = map->buckets[bucket];
    map->buckets[bucket] = current;
}
Esempio n. 17
0
void int_map_add(int_map_ptr map, int key, void *val)
{
    _hash_t      hash = _hash(key);
    int             prime = _primes[map->prime_idx];
    _hash_t      bucket;
    _node_ptr    current;

    if ( !prime 
      || (prime < _MAX_PRIME && map->count > 2*prime/3) ) /* Tweak Me! */
    {
        _grow(map);
        prime = _primes[map->prime_idx];
    }

    bucket = hash % prime;
    current = map->buckets[bucket];

    while (current)
    {
        if ( current->hash == hash
          && key == current->key )
        {
            if (map->free)
                map->free(current->val);
            current->val = val;
            return;
        }
        current = current->next;
    }

    map->count++;

    current = malloc(sizeof(_node_t));
    current->hash = hash;
    current->key = key;
    current->val = val;
    current->next = map->buckets[bucket];
    map->buckets[bucket] = current;
}
Esempio n. 18
0
///void FuncTestFloatAssignFloatCommand(ParserEnv* e, SymbolValue* args);
void FunctionClosures_complete(ParserEnv* e, FunctionClosures _self)
{
    switch (_self->status)
    {
    case DeclareInputParamsStatus:
        _self->status = DeclareOutputParamsStatus;
        break;
    case DeclareOutputParamsStatus:
        _self->status = AddCommandsStatus;
        break;
    case AddCommandsStatus:
        _self->status = CompleteStatus;

        {
            ///FunctionClosures_complete_branchs(e, _self);

            VPRINT("\n\n##GET STACK SIZE\n");
            int* ip = (int*)_get_ptr(e, _self->vari_stack_size);
            *ip = ValueAllocator_totel_size(&e->vari_alloc);
            VPRINT("VARI STACK SIZE %d\n", *ip);
            ip = (int*)_get_ptr(e, _self->vari_str_stack_size);
            *ip = ValueAllocator_totel_size(&e->vari_str_alloc);
            VPRINT("VARI STR STACK SIZE %d\n", *ip);
            VPRINT("\n");

            euint n = 0;
            n = array_n(_self->func_arg_op_cmds_type_a_1);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_a_1[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                SymbolValue* sv = &cc->args[1];
                _grow(e, sv);
            }
            n = array_n(_self->func_arg_op_cmds_type_b_1);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_b_1[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                SymbolValue* sv = &cc->args[0];
                _grow(e, sv);
            }
            n = array_n(_self->func_arg_op_cmds_type_c_1);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_c_1[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                {
                    SymbolValue* sv = &cc->args[0];
                    _grow(e, sv);
                }
                {
                    SymbolValue* sv = &cc->args[1];
                    _grow(e, sv);
                }
            }

            n = array_n(_self->func_arg_op_cmds_type_a_2);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_a_2[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                {
                    SymbolValue* sv = &cc->args[1];
                    _grow(e, sv);
                }
                {
                    SymbolValue* sv = &cc->args[2];
                    _grow(e, sv);
                }
            }
            n = array_n(_self->func_arg_op_cmds_type_b_2);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_b_2[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                {
                    SymbolValue* sv = &cc->args[0];
                    _grow(e, sv);
                }
                {
                    SymbolValue* sv = &cc->args[2];
                    _grow(e, sv);
                }
            }
            n = array_n(_self->func_arg_op_cmds_type_c_2);
            for (euint i = 0; i < n; i++) {
                CommandClosures cc = _self->func_arg_op_cmds_type_c_2[i];
                ///
                if (FloatAssignFloatCommand == cc->cmd)
                    cc->cmd = FloatAssignFloatCommand;
                ///
                {
                    SymbolValue* sv = &cc->args[0];
                    _grow(e, sv);
                }
                {
                    SymbolValue* sv = &cc->args[1];
                    _grow(e, sv);
                }
                {
                    SymbolValue* sv = &cc->args[2];
                    _grow(e, sv);
                }
            }
        }
        ValueAllocator_clear(&e->vari_alloc);
        ValueAllocator_clear(&e->vari_str_alloc);
        break;
    default:
        break;
    }
}
Esempio n. 19
0
File: llist.c Progetto: deglingo/los
/* l_list_append:
 */
void l_list_append ( LList *list,
                     LObject *item )
{
  _grow(list, list->_size + 1);
  list->_items[list->_size++] = l_object_ref(item);
}