Exemple #1
0
IOIMAGE_API IoImage *IoImage_newWithImage_(void *state, Image* image)
{
	IoImage* self = IoImage_new(state);
	DATA(self)->image = image;
	DATA(self)->buffer = IoSeq_newWithData_length_(state, Image_data(image), Image_sizeInBytes(image));
	Image_setExternalUArray_(image, IoSeq_rawUArray(DATA(self)->buffer));
	return self;
}
Exemple #2
0
IO_METHOD(IoNumber, asUint32Buffer)
{
	/*doc Number asUint32Buffer
	Returns a Sequence containing a 4 byte representation of the uint32 value of the receiver.
	*/
	
	uint32_t i = (int)DATA(self);
	return IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&i, sizeof(uint32_t));
}
Exemple #3
0
IO_METHOD(IoNumber, asCharacter)
{
	/*doc Number asCharacter
	Returns a String containing a single character whose
	value is the value of the first byte of the receiver.
	Returns nil if the number has no valid UCS mapping.
	*/
	
	double d =DATA(self);
	long ld = d;
	
	if (d < 0 || d != ld)
	{
		return IONIL(self);
	}
	else
	{	
		uint32_t i = io_uint32InBigEndian((uint32_t)d);
		int bytes = countBytes(ld);
		IoSeq *s;
		
		if (bytes == 0) 
		{ 
			bytes = 1;
		}
		
		if (bytes == 3) 
		{ 
			bytes = 4;
		}
		
		if (bytes > 4) 
		{
			// no valid UCS encoding for this value
			return IONIL(self);
		}
		
		s = IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&i, bytes);
		
		{
			UArray *u = IoSeq_rawUArray(s);
			int e = CENCODING_ASCII;
			
			switch (bytes)
			{
				case 1: e = CENCODING_ASCII; break;
				case 2: e = CENCODING_UCS2; break;
				case 4: e = CENCODING_UCS4; break;
			}
			
			UArray_setEncoding_(u, e);
		}
		
		return s;
	}
}
Exemple #4
0
IoObject *IoTagDB_symbolForId(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB symbolForId(aNumber)
	Returns the TagDB symbol for aNumber.
	*/
	
	symbolid_t id = IoMessage_locals_sizetArgAt_(m, locals, 0);
	Datum *d = TagDB_symbolForId_(DATA(self), id);
	IoSeq *s = IoSeq_newWithData_length_(IOSTATE, Datum_data(d), Datum_size(d));
	Datum_free(d);
	return s;
}
Exemple #5
0
IoObject *IoTagDB_keyAtIndex(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB keyAtIndex(indexNumber)
	Returns the key at the specified index of nil if the index is out of range.
	*/
	
	TagDB *tdb = DATA(self);
	IoNumber *index = IoMessage_locals_numberArgAt_(m, locals, 0);
	Datum *key = TagDB_keyAtIndex_(tdb, CNUMBER(index));
	
	if (!key) 
	{
		return IONIL(self);
	}
	
	return IoSeq_newWithData_length_(IOSTATE, (void *)(key->data), key->size);
}
Exemple #6
0
IO_METHOD(IoNumber, asBuffer)
{
	/*doc Number asBuffer(optionalNumberOfBytes)
	Returns a Buffer containing a the number of bytes specified by
	optionalNumberOfBytes (up to the size of a double on the platform) of the reciever.
	If no optionalNumberOfBytes is specified, it is assumed to be the number of bytes
	in a double on the host platform.
	*/
	IoNumber *byteCount = IoMessage_locals_valueArgAt_(m, locals, 0);
	int bc = sizeof(double);

	if (!ISNIL(byteCount))
	{
		bc = DATA(byteCount);
	}
	return IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&(DATA(self)), bc);
}
Exemple #7
0
IoObject *IoTagDB_tagsAtKey(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB tagsAtKey(key)
	Returns the tags for the specified key.
	*/
	
	TagDB *tdb = DATA(self);
	IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
	symbolid_t keyid = TagDB_idForSymbol_size_(tdb, CSTRING(key), IoSeq_rawSize(key));
	IoList *tagNames = IoList_new(IOSTATE);
	Uint64Array *tags = TagDB_tagsAtKey_(tdb, keyid);
	int i;

	//printf("IoTagDB_tagsAt self = %p\n", (void *)self);

	if (!tags) 
	{
		//printf("IoTagDB_tagsAtKey: no tags found for key\n");
		return IONIL(self);
	}
	
	for (i = 0; i < Uint64Array_size(tags); i ++)
	{
		uint64_t tagid = Uint64Array_at_(tags, i);
		Datum *name = TagDB_symbolForId_(tdb, tagid);
		//printf("tagid %i = %i\n", i, (int)tagid);
		//printf("name '%s'\n", (char *)name->data);

		if (!name)
		{
			printf("IoTagDB_tagsAtKey: no datum returned for TagDB_symbolForId_\n");
		}
		else
		{
			IoList_rawAppend_(tagNames, IoSeq_newWithData_length_(IOSTATE, name->data, name->size));
			Datum_free(name);
		}
	}

	//Uint64Array_free(tags);

	return tagNames;
}
IoObject *IoTokyoCabinetPrefixCursor_value(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor value
	Returns current cursor value or nil.
	*/
	
	int size;
	char *value;

	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	value = tcbdbcurval(TokyoCabinetPrefixCursor(self), &size);

	if (value)
	{
		IoSeq *s = IoSeq_newWithData_length_(IOSTATE, (unsigned char *)value, size);
		free(value);
		return s;
	}

	return IONIL(self);
}
Exemple #9
0
IoSeq *IoSeq_newWithCString_length_(void *state, const char *s, size_t length)
{
	return IoSeq_newWithData_length_(state, (unsigned char *)s, length);
}
Exemple #10
0
IoSeq *IoSeq_newWithCString_(void *state, const char *s)
{
	return IoSeq_newWithData_length_(state, (unsigned char *)s, strlen(s));
}