Ejemplo n.º 1
0
string ofxOscMessage::getArgAsString( int index ) const
{
    if ( getArgType(index) != OFXOSC_TYPE_STRING )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
            char buf[1024];
            sprintf(buf,"%f",((ofxOscArgFloat*)args[index])->get() );
            ofLog(OF_LOG_WARNING, "ofxOscMessage:getArgAsString: converting float to string for argument %i", index );
            return buf;
        }
	    else if ( getArgType( index ) == OFXOSC_TYPE_INT32 )
        {
            char buf[1024];
            sprintf(buf,"%i",((ofxOscArgInt32*)args[index])->get() );
            ofLog(OF_LOG_WARNING, "ofxOscMessage:getArgAsString: converting int32 to string for argument %i", index );
            return buf;
        }
        else
        {
        	ofLog(OF_LOG_ERROR, "ofxOscMessage:getArgAsString: argument %i is not a string", index );
            return "";
        }
	}
	else
        return ((ofxOscArgString*)args[index])->get();
}
Ejemplo n.º 2
0
string ofxOscMessage::getArgAsString( int index ) const
{
    if ( getArgType(index) != OFXOSC_TYPE_STRING )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
            char buf[1024];
            sprintf(buf,"%f",((ofxOscArgFloat*)args[index])->get() );
            fprintf(stderr, "ofxOscMessage:getArgAsString: warning: converting float to string for argument %i\n", index );
            return buf;
        }
	    else if ( getArgType( index ) == OFXOSC_TYPE_INT32 )
        {
            char buf[1024];
            sprintf(buf,"%i",((ofxOscArgInt32*)args[index])->get() );
            fprintf(stderr, "ofxOscMessage:getArgAsString: warning: converting int32 to string for argument %i\n", index );
            return buf;
        }
        else
        {
            fprintf(stderr, "ofxOscMessage:getArgAsString: error: argument %i is not a string\n", index );
            return "";
        }
	}
	else
        return ((ofxOscArgString*)args[index])->get();
}
Ejemplo n.º 3
0
string ofxOscMessage::getArgAsString( int index ) const
{
    if ( getArgType(index) != OFXOSC_TYPE_STRING )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
            char buf[1024];
            sprintf(buf,"%f",((ofxOscArgFloat*)args[index])->get() );
            ofLogWarning("ofxOscMessage") << "getArgAsString(): converting float to string for argument " << index;
            return buf;
        }
	    else if ( getArgType( index ) == OFXOSC_TYPE_INT32 )
        {
            char buf[1024];
            sprintf(buf,"%i",((ofxOscArgInt32*)args[index])->get() );
            ofLogWarning("ofxOscMessage") << "getArgAsString(): converting int32 to string for argument " << index;
            return buf;
        }
        else
        {
        	ofLogError("ofxOscMessage") << "getArgAsString(): argument " << index << " is not a string";
            return "";
        }
	}
	else
        return ((ofxOscArgString*)args[index])->get();
}
Ejemplo n.º 4
0
/* barrier blocks can only be dropped when they are fully excluded.  */
static int
OPTremoveUnusedBlocks(Client cntxt, MalBlkPtr mb)
{
	/* catch and remove constant bounded blocks */
	int i, j = 0, action = 0, block = 0, skip = 0, top =0, skiplist[10];
	InstrPtr p;

	for (i = 0; i < mb->stop; i++) {
		p = mb->stmt[i];
		if (blockStart(p)) {
			block++;
			if (p->argc == 2 && isVarConstant(mb, getArg(p, 1)) &&
					getArgType(mb, p, 1) == TYPE_bit &&
					getVarConstant(mb, getArg(p, 1)).val.btval == 0)
			{
				if (skip == 0)
					skip = block;
				action++;
			}
			// Try to remove the barrier statement itself (when true).
			if (p->argc == 2 && isVarConstant(mb, getArg(p, 1)) &&
					getArgType(mb, p, 1) == TYPE_bit &&
					getVarConstant(mb, getArg(p, 1)).val.btval == 1 && 
					top <10 && OPTsimpleflow(mb,i))
			{
				skiplist[top++]= getArg(p,0);
				freeInstruction(p);
				continue;
			}
		}
		if (blockExit(p)) {
			if (top > 0 && skiplist[top-1] == getArg(p,0) ){
				top--;
				freeInstruction(p);
				continue;
			} 
			if (skip )
				freeInstruction(p);
			else
				mb->stmt[j++] = p;
			if (skip == block)
				skip = 0;
			block--;
			if (block == 0)
				skip = 0;
		} else if (skip)
			freeInstruction(p);
		else
			mb->stmt[j++] = p;
	}
	mb->stop = j;
	for (; j < i; j++)
		mb->stmt[j] = NULL;
	if (action) {
		chkTypes(cntxt->fdout, cntxt->nspace, mb, TRUE);
		return mb->errors ? 0 : action;
	}
	return action;
}
Ejemplo n.º 5
0
float Message::getArgAsFloat(int index, bool typeConvert) const{
	if (getArgType(index) != TYPE_FLOAT){
		if( typeConvert && (getArgType(index) == TYPE_INT32) )
			return (float)((ArgInt32*)args[index])->get();
		else
			throw OscExcInvalidArgumentType();
	}else
        return ((ArgFloat*)args[index])->get();
}
Ejemplo n.º 6
0
str OPTsql_append(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){
	str modnme;
	str fcnnme;
	str msg= MAL_SUCCEED;
	Symbol s= NULL;
	lng t,clk= GDKusec();
	int actions = 0;

	if( p )
		removeInstruction(mb, p);
	OPTDEBUGsql_append mnstr_printf(cntxt->fdout,"=APPLY OPTIMIZER sql_append\n");
	if( p && p->argc > 1 ){
		if( getArgType(mb,p,1) != TYPE_str ||
			getArgType(mb,p,2) != TYPE_str ||
			!isVarConstant(mb,getArg(p,1)) ||
			!isVarConstant(mb,getArg(p,2))
		) {
			throw(MAL, "optimizer.sql_append", ILLARG_CONSTANTS);
		}
		if( stk != 0){
			modnme= *getArgReference_str(stk,p,1);
			fcnnme= *getArgReference_str(stk,p,2);
		} else {
			modnme= getArgDefault(mb,p,1);
			fcnnme= getArgDefault(mb,p,2);
		}
		s= findSymbol(cntxt->nspace, putName(modnme,strlen(modnme)),putName(fcnnme,strlen(fcnnme)));

		if( s == NULL) {
			char buf[1024];
			snprintf(buf,1024, "%s.%s",modnme,fcnnme);
			throw(MAL, "optimizer.sql_append", RUNTIME_OBJECT_UNDEFINED ":%s", buf);
		}
		mb = s->def;
		stk= 0;
	}
	if( mb->errors ){
		/* when we have errors, we still want to see them */
		addtoMalBlkHistory(mb,"sql_append");
		return MAL_SUCCEED;
	}
	actions= OPTsql_appendImplementation(cntxt, mb,stk,p);
	msg= optimizerCheck(cntxt, mb, "optimizer.sql_append", actions, t=(GDKusec() - clk));
	OPTDEBUGsql_append {
		mnstr_printf(cntxt->fdout,"=FINISHED sql_append %d\n",actions);
		printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL );
	}
	DEBUGoptimizers
		mnstr_printf(cntxt->fdout,"#opt_reduce: " LLFMT " ms\n",t);
	QOTupdateStatistics("sql_append",actions,t);
	addtoMalBlkHistory(mb,"sql_append");
	return msg;
}
Ejemplo n.º 7
0
str
MATpackValues(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
{
	int i, type, first = 1;
	bat *ret;
	BAT *bn;

	(void) cntxt;
	type = getArgType(mb,p,first);
	bn = BATnew(TYPE_void, type, p->argc, TRANSIENT);
	if( bn == NULL)
		throw(MAL, "mat.pack", MAL_MALLOC_FAIL);

	if (ATOMextern(type)) {
		for(i = first; i < p->argc; i++)
			BUNappend(bn, stk->stk[getArg(p,i)].val.pval, TRUE);
	} else {
		for(i = first; i < p->argc; i++)
			BUNappend(bn, getArgReference(stk, p, i), TRUE);
	}
	BATseqbase(bn, 0);
	ret= getArgReference_bat(stk,p,0);
	BBPkeepref(*ret = bn->batCacheid);
	return MAL_SUCCEED;
}
Ejemplo n.º 8
0
static int
OPTallConstant(Client cntxt, MalBlkPtr mb, InstrPtr p)
{
	int i;
	(void)cntxt;

	if ( !(p->token == ASSIGNsymbol ||
		   getModuleId(p) == calcRef ||
		   getModuleId(p) == strRef ||
		   getModuleId(p) == mtimeRef ||
		   getModuleId(p) == mmathRef))
		return FALSE;
	if (getModuleId(p) == mmathRef && strcmp(getFunctionId(p), "rand") == 0)
		return FALSE;

	for (i = p->retc; i < p->argc; i++)
		if (isVarConstant(mb, getArg(p, i)) == FALSE)
			return FALSE;
	for (i = 0; i < p->retc; i++) {
		if (isaBatType(getArgType(mb, p, i)))
			return FALSE;
		if ( mb->unsafeProp ) 
			return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 9
0
bool ofxOscMessage::getArgAsBool(int index) const
{
	ofxOscArgType incomingArgType = getArgType( index );
	if(incomingArgType == OFXOSC_TYPE_TRUE or incomingArgType == OFXOSC_TYPE_FALSE)
	{
		return ((ofxOscArgBool*)args[index])->get();
	}
	else if(incomingArgType == OFXOSC_TYPE_INT32)
	{
		return ((ofxOscArgInt32*)args[index])->get() > 0;
	}
	else if(incomingArgType == OFXOSC_TYPE_INT64)
	{
		return ((ofxOscArgInt64*)args[index])->get() > 0;
	}
	else if(incomingArgType == OFXOSC_TYPE_FLOAT)
	{
		return ((ofxOscArgFloat*)args[index])->get() > 0;
	}
	else if(incomingArgType == OFXOSC_TYPE_DOUBLE)
	{
		return ((ofxOscArgDouble*)args[index])->get() > 0;
	}
	else if(incomingArgType == OFXOSC_TYPE_STRING or incomingArgType == OFXOSC_TYPE_SYMBOL)
	{
		return ((ofxOscArgString*)args[index])->get() == "true";
	}
	else
	{
		ofLogError("ofxOscMessage") << "getArgAsBool(): argument " << index << " is not a boolean interpretable value";
		return false;
	}
}
Ejemplo n.º 10
0
str
MATpackValues(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
{
	int i,*ret, type, first = 1;
	BAT *bn;

	(void) cntxt;
	type = getArgType(mb,p,first);
	bn = BATnew(TYPE_void, type, p->argc, TRANSIENT);
	if( bn == NULL)
		throw(MAL, "mat.pack", MAL_MALLOC_FAIL);

	if (ATOMvarsized(type)) {
		for(i = first; i < p->argc; i++)
			BUNappend(bn, stk->stk[getArg(p,i)].val.sval, TRUE);
	} else {
		for(i = first; i < p->argc; i++)
			BUNappend(bn, getArgReference(stk, p, i), TRUE);
	}
    BATsettrivprop(bn);
    BATderiveProps(bn,FALSE);
	ret= (int*) getArgReference(stk,p,0);
	BBPkeepref(*ret = bn->batCacheid);
	return MAL_SUCCEED;
}
Ejemplo n.º 11
0
str
CMDbbpbind(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
	str name;
	ValPtr lhs;
	bat i;
	int ht,tt;
	BAT *b;

	(void) cntxt;
	(void) mb;		/* fool compiler */
	lhs = &stk->stk[pci->argv[0]];
	name = *getArgReference_str(stk, pci, 1);
	if (isIdentifier(name) < 0)
		throw(MAL, "bbp.bind", IDENTIFIER_EXPECTED);
	i = BBPindex(name);
	if (i == 0)
		throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING);
	/* make sure you load the descriptors and heaps */
	b = (BAT *) BATdescriptor(i);
	if (b == 0)
		/* Simple ignore the binding if you can't find the bat */
		throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING);

	/* check conformity of the actual type and the one requested */
	ht= getHeadType(getArgType(mb,pci,0));
	tt= getColumnType(getArgType(mb,pci,0));
	if( b->htype == TYPE_void && ht== TYPE_oid) ht= TYPE_void;
	if( b->ttype == TYPE_void && tt== TYPE_oid) tt= TYPE_void;

	if( ht != b->htype || tt != b->ttype){
		BBPunfix(i);
		throw(MAL, "bbp.bind", SEMANTIC_TYPE_MISMATCH );
	}
	/* make sure we are not dealing with an about to be deleted bat */
	if( BBP_refs(b->batCacheid) == 1 &&
		BBP_lrefs(b->batCacheid) == 0){
		BBPunfix(i);
		throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING);
	}

	BBPkeepref(b->batCacheid);
	lhs->vtype = TYPE_bat;
	lhs->val.bval = i;
	return MAL_SUCCEED;
}
Ejemplo n.º 12
0
float OSCMessage::getArgAsFloat( int index ) const {
    
	if ( getArgType(index) != OSC_TYPE_FLOAT ) {
	    if ( getArgType( index ) == OSC_TYPE_INT32 ) {
            fprintf(stderr, "OSCMessage:getArgAsFloat: warning: converting float to int32 for argument %i\n", index );
            return ((SignalOSCArgInt32*)args[index])->get();
        }
        
        else {
            fprintf(stderr, "OSCMessage:getArgAsFloat: error: argument %i is not a number\n", index );
            return 0;
        }
	}
	else
        return ((SignalOSCArgFloat*)args[index])->get();
    
}
Ejemplo n.º 13
0
int 
OPTmatpackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
	int v, i, j, limit, slimit;
	InstrPtr p,q;
	int actions = 0;
	InstrPtr *old;
	char *packIncrementRef = putName("packIncrement", 13);

	(void) pci;
	(void) cntxt;
	(void) stk;		/* to fool compilers */
	old= mb->stmt;
	limit= mb->stop;
	slimit = mb->ssize;
	if ( newMalBlkStmt(mb,mb->stop) < 0)
		return 0;
	for (i = 0; i < limit; i++) {
		p = old[i];
		if( getModuleId(p) == matRef  && getFunctionId(p) == packRef && isaBatType(getArgType(mb,p,1))) {
			q = newStmt(mb, matRef, packIncrementRef);
			v = getArg(q,0);
			setVarType(mb,v,getArgType(mb,p,1));
			q = pushArgument(mb, q, getArg(p,1));
			q = pushInt(mb,q, p->argc - p->retc);

			for ( j = 2; j < p->argc; j++) {
				q = newStmt(mb,matRef, packIncrementRef);
				q = pushArgument(mb, q, v);
				q = pushArgument(mb, q, getArg(p,j));
				setVarType(mb,getArg(q,0),getVarType(mb,v));
				v = getArg(q,0);
			}
			getArg(q,0) = getArg(p,0);
			freeInstruction(p);
			continue;
		}
		pushInstruction(mb,p);
	} 
	for(; i<slimit; i++)
		if (old[i]) 
			freeInstruction(old[i]);
	GDKfree(old);
	return actions;
}
Ejemplo n.º 14
0
double ofxOscMessage::getArgAsDouble( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_DOUBLE )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_INT32 )
        {
	    	ofLogWarning("ofxOscMessage") << "getArgAsDouble(): converting int32 to double for argument " << index;
            return (double)((ofxOscArgInt32*)args[index])->get();
        }
        else
        {
        	ofLogError("ofxOscMessage") << "getArgAsDouble(): argument " << index << " is not a number";
            return 0;
        }
	}
	else
        return ((ofxOscArgDouble*)args[index])->get();
}
Ejemplo n.º 15
0
uint64_t ofxOscMessage::getArgAsInt64( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_INT64 )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
	    	cout << "getArgAsInt64(): converting int64 to float for argument " << index;
            return ((ofxOscArgFloat*)args[index])->get();
        }
        else
        {
        	cout << "getArgAsInt64(): argument " << index << " is not a number";
            return 0;
        }
	}
	else
        return ((ofxOscArgInt64*)args[index])->get();
}
Ejemplo n.º 16
0
int32_t ofxOscMessage::getArgAsInt32( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_INT32 )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
	    	ofLogWarning("ofxOscMessage") << "getArgAsInt32(): converting int32 to float for argument " << index;
            return ((ofxOscArgFloat*)args[index])->get();
        }
        else
        {
        	ofLogError("ofxOscMessage") << "getArgAsInt32(): argument " << index << " is not a number";
            return 0;
        }
	}
	else
        return ((ofxOscArgInt32*)args[index])->get();
}
Ejemplo n.º 17
0
std::string Message::getArgAsString( int index, bool typeConvert ) const{
    if (getArgType(index) != TYPE_STRING ){
	    if (typeConvert && (getArgType(index) == TYPE_FLOAT) ){
            char buf[1024];
            sprintf(buf,"%f",((ArgFloat*)args[index])->get() );
            return std::string( buf );
        }
	    else if (typeConvert && (getArgType(index) == TYPE_INT32)){
            char buf[1024];
            sprintf(buf,"%i",((ArgInt32*)args[index])->get() );
            return std::string( buf );
        }
        else
            throw OscExcInvalidArgumentType();
	}
	else
        return ((ArgString*)args[index])->get();
}
Ejemplo n.º 18
0
int32_t ofxOscMessage::getArgAsInt32( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_INT32 )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
	    	ofLog(OF_LOG_WARNING, "ofxOscMessage:getArgAsInt32: converting int32 to float for argument %i", index );
            return ((ofxOscArgFloat*)args[index])->get();
        }
        else
        {
        	ofLog(OF_LOG_ERROR, "ofxOscMessage:getArgAsInt32: argument %i is not a number", index );
            return 0;
        }
	}
	else
        return ((ofxOscArgInt32*)args[index])->get();
}
Ejemplo n.º 19
0
float ofxOscMessage::getArgAsFloat( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_FLOAT )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_INT32 )
        {
	    	cout << "getArgAsFloat(): converting float to int32 for argument " << index;
            return ((ofxOscArgInt32*)args[index])->get();
        }
        else
        {
        	cout << "getArgAsFloat(): argument " << index << " is not a number";
            return 0;
        }
	}
	else
        return ((ofxOscArgFloat*)args[index])->get();
}
Ejemplo n.º 20
0
int64_t ofxOscMessage::getArgAsTimetag(int index) const
{
	if ( getArgType(index) != OFXOSC_TYPE_TIMETAG )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_DOUBLE )
        {
	    	ofLogWarning("ofxOscMessage") << "getArgAsTimetag(): converting double to Timetag for argument " << index;
            return (int32_t)((ofxOscArgFloat*)args[index])->get();
        }
        else
        {
        	ofLogError("ofxOscMessage") << "getArgAsTimetag(): argument " << index << " is not a valid number";
            return 0;
        }
	}
	else
        return ((ofxOscArgTimetag*)args[index])->get();
}
Ejemplo n.º 21
0
long ofxOscMessage::getArgAsInt32( int index ) const
{
	if ( getArgType(index) != OFXOSC_TYPE_INT32 )
	{
	    if ( getArgType( index ) == OFXOSC_TYPE_FLOAT )
        {
            fprintf(stderr, "ofxOscMessage:getArgAsInt32: warning: converting int32 to float for argument %i\n", index );
            return ((ofxOscArgFloat*)args[index])->get();
        }
        else
        {
            fprintf(stderr, "ofxOscMessage:getArgAsInt32: error: argument %i is not a number\n", index );
            return 0;
        }
	}
	else
        return ((ofxOscArgInt32*)args[index])->get();
}
Ejemplo n.º 22
0
//--------------------------------------------------------------
std::uint32_t ofxOscMessage::getArgAsMidiMessage(std::size_t index) const{
	if(getArgType(index) == OFXOSC_TYPE_MIDI_MESSAGE){
		return ((ofxOscArgMidiMessage*)args[index])->get();
	}
	else{
		ofLogError("ofxOscMessage") << "getArgAsMidiMessage(): argument "
			<< index << " is not a midi message";
		return 0;
	}
}
Ejemplo n.º 23
0
ofBuffer ofxOscMessage::getArgAsBlob( int index ) const
{
    if ( getArgType(index) != OFXOSC_TYPE_BLOB )
	{
        ofLogError("ofxOscMessage") << "getArgAsBlob(): argument " << index << " is not a blob";
        return ofBuffer();
	}
	else
        return ((ofxOscArgBlob*)args[index])->get();
}
Ejemplo n.º 24
0
//--------------------------------------------------------------
std::uint32_t ofxOscMessage::getArgAsRgbaColor(std::size_t index) const{
	if(getArgType(index) != OFXOSC_TYPE_RGBA_COLOR){
		ofLogError("ofxOscMessage") << "getArgAsRgbaColor(): argument "
			<< index << " is not an rgba color";
		return 0;
	}
	else{
		return ((ofxOscArgRgbaColor*)args[index])->get();
	}
}
Ejemplo n.º 25
0
//--------------------------------------------------------------
std::uint64_t ofxOscMessage::getArgAsTimetag(std::size_t index) const{
	if(getArgType(index) != OFXOSC_TYPE_TIMETAG){
		if(getArgType(index) == OFXOSC_TYPE_DOUBLE){
			// warn about possible conversion issue
			ofLogWarning("ofxOscMessage")
				<< "getArgAsTimetag(): converting double to Timetag "
				<< "for argument " << index;
			return (std::uint64_t)((ofxOscArgDouble*)args[index])->get();
		}
		else{
			ofLogError("ofxOscMessage") << "getArgAsTimetag(): argument "
				<< index << " is not a valid number";
			return 0;
		}
	}
	else{
		return ((ofxOscArgTimetag*)args[index])->get();
	}
}
Ejemplo n.º 26
0
//--------------------------------------------------------------
bool ofxOscMessage::getArgAsTrigger(std::size_t index) const{
	if(getArgType(index) != OFXOSC_TYPE_TRIGGER){
		ofLogError("ofxOscMessage") << "getArgAsTrigger(): argument "
			<< index << " is not a trigger";
		return false;
	}
	else{
		return ((ofxOscArgTrigger*)args[index])->get();
	}
}
Ejemplo n.º 27
0
//--------------------------------------------------------------
bool ofxOscMessage::getArgAsNone(std::size_t index) const{
	if(getArgType(index) != OFXOSC_TYPE_NONE){
		ofLogError("ofxOscMessage") << "getArgAsNone(): argument "
			<< index << " is not a none/nil";
		return false;
	}
	else{
		return ((ofxOscArgNone*)args[index])->get();
	}
}
Ejemplo n.º 28
0
//--------------------------------------------------------------
char ofxOscMessage::getArgAsChar(std::size_t index) const{
	if(getArgType(index) == OFXOSC_TYPE_CHAR){
		return ((ofxOscArgChar*)args[index])->get();
	}
	else{
		ofLogError("ofxOscMessage") << "getArgAsChar(): argument "
			<< index << " is not a char";
		return 0;
	}
}
Ejemplo n.º 29
0
/*
 * Enable incremental packing. The SQL front-end requires
 * fixed oid sequences.
 */
str
MATpackIncrement(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
{
	bat *ret = getArgReference_bat(stk,p,0);
	int	pieces;
	BAT *b, *bb, *bn;
	size_t newsize;

	(void) cntxt;
	b = BATdescriptor( stk->stk[getArg(p,1)].val.ival);
	if ( b == NULL)
		throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING);

	if ( getArgType(mb,p,2) == TYPE_int){
		/* first step, estimate with some slack */
		pieces = stk->stk[getArg(p,2)].val.ival;
		bn = BATnew(TYPE_void, b->ttype?b->ttype:TYPE_oid, (BUN)(1.2 * BATcount(b) * pieces), TRANSIENT);
		if (bn == NULL)
			throw(MAL, "mat.pack", MAL_MALLOC_FAIL);
		/* allocate enough space for the vheap, but not for strings,
		 * since BATappend does clever things for strings */
		if ( b->T->vheap && bn->T->vheap && ATOMstorage(b->ttype) != TYPE_str){
			newsize =  b->T->vheap->size * pieces;
			if (HEAPextend(bn->T->vheap, newsize, TRUE) != GDK_SUCCEED)
				throw(MAL, "mat.pack", MAL_MALLOC_FAIL);
		}
		BATseqbase(bn, b->H->seq);
		BATseqbase(BATmirror(bn), b->T->seq);
		BATappend(bn,b,FALSE);
		assert(!bn->H->nil || !bn->H->nonil);
		assert(!bn->T->nil || !bn->T->nonil);
		bn->H->align = (pieces-1);
		BBPkeepref(*ret = bn->batCacheid);
		BBPunfix(b->batCacheid);
	} else {
		/* remaining steps */
		bb = BATdescriptor(stk->stk[getArg(p,2)].val.ival);
		if ( bb ){
			if (BATcount(b) == 0)
				BATseqbase(b, bb->H->seq);
			if (BATcount(b) == 0)
				BATseqbase(BATmirror(b), bb->T->seq);
			BATappend(b,bb,FALSE);
		}
		b->H->align--;
		if(b->H->align == 0)
			BATsetaccess(b, BAT_READ);
		assert(!b->H->nil || !b->H->nonil);
		assert(!b->T->nil || !b->T->nonil);
		BBPkeepref(*ret = b->batCacheid);
		if( bb) 
			BBPunfix(bb->batCacheid);
	}
	return MAL_SUCCEED;
}
Ejemplo n.º 30
0
char ofxOscMessage::getArgAsChar(int index) const
{
    if ( getArgType(index) == OFXOSC_TYPE_CHAR )
	{
		return ((ofxOscArgChar*)args[index])->get();
	}
	else
    {
		ofLogError("ofxOscMessage") << "getArgAsSymbol(): argument " << index << " is not a symbol (string)";
		return NULL;
	}
}