bool isNumber(const char *s) {
        str.assign(s);

		trim(str, ' ');
		if (str.length() == 0) return false;

		int idxE = str.find('e');
		bool isE = idxE != str.npos;
		if (isE) {
			string first = str.substr(0, idxE);
			string second = str.substr(idxE + 1);
			if (first.length() == 0 || second.length() == 0) return false;
			trimSign(first);
			trimSign(second);
			bool ok = checkInt(first) || checkIntOrFloat(first);
			if (!ok) return false;
			ok = checkInt(second);
			if (!ok) return false;
		} else {
			trimSign(str);
			bool ok = checkIntOrFloat(str);
			if (!ok) return false;
		}

		return true;
    }
void *fullQueueWriterTask(void* ptr) {
    TaskContext* ctx = (TaskContext*)ptr;
    SensorEventQueue* queue = ctx->queue;
    ctx->success = true;
    int totalWaits = 0;
    int totalWrites = 0;
    sensors_event_t* buffer;

    while (totalWrites < FULL_QUEUE_EVENT_COUNT) {
        pthread_mutex_lock(&mutex);
        if (queue->waitForSpace(&mutex)) {
            totalWaits++;
            printf(".");
        }
        int writableSize = queue->getWritableRegion(FULL_QUEUE_CAPACITY, &buffer);
        queue->markAsWritten(writableSize);
        totalWrites += writableSize;
        for (int i = 0; i < writableSize; i++) {
            printf("w");
        }
        pthread_cond_broadcast(&dataAvailableCond);
        pthread_mutex_unlock(&mutex);
    }
    printf("\n");

    ctx->success =
            checkInt("totalWrites", FULL_QUEUE_EVENT_COUNT, totalWrites) &&
            checkInt("totalWaits", FULL_QUEUE_EVENT_COUNT - FULL_QUEUE_CAPACITY, totalWaits);
    return NULL;
}
int *posToInt(char *input[], int pos){

	if(input[pos])
		return checkInt(input[pos]); //Credo che sia possibile aggiungere controlli di sicurezza..

	return NULL;
}
Beispiel #4
0
TEST(Inline, baseline_prom_1) {
  BasicBlock f0, f1, p0;

  p0 << BC::loadenv
     << BC::load << a << BC::force
     << BC::leave_prom
     << BC::ret;

  f1 << BC::enter_fun     << 1
     << BC::store         << b
     << BC::load          << b
     << BC::force
     << BC::leave_fun
     << BC::ret;

  f0 << BC::enter_fun      << (int)0
     << BC::mkclosure      << f1.code()    << L({b})
     << BC::mkprom         << p0.code()
     << BC::push           << C(42)
     << BC::store          << a
     << BC::call_generic   << 1
     << BC::push           << C(1)
     << BC::add
     << BC::leave_fun
     << BC::ret;

  checkInt(f0.code(), 43);
}
Beispiel #5
0
// f1 is inline into f0, f1 closure is still materialized
TEST(Inline, inline_1) {
  BasicBlock f0, f1;

  f1 << BC::enter_fun     << 2
     << BC::add
     << BC::leave_fun
     << BC::ret;

  f0 << BC::enter_fun      << (int)0
     << BC::mkclosure      << f1.code()     << L({a, a})
     << BC::push           << C(1)
     << BC::push           << C(1)

     // f1 inlined verbatim
     << BC::enter_fun     << 2
     << BC::add
     << BC::leave_fun

     << BC::push           << C(1)
     << BC::add
     << BC::leave_fun
     << BC::ret;

  checkInt(f0.code(), 3);
}
Beispiel #6
0
Int8::Int8(const std::string &string)
{
  if (!checkInt(string))
    throw new SyntaxException;
  __int128	n = atol(string.c_str());
  if (n > 127)
    throw new OverflowException;
  if (n < -128)
    throw new UnderflowException;
  this->data = (char)n;
}
//Funzioni pubbliche. Utilizzare queste funzioni
int *flagToInt(char *input[], char *flag){

	int i=0;

	while (input[i]){
		if(strcmp(input[i],flag)==0){ //Flag trovato!
			if(input[i+1])        //Controllo anzi tutto che ci sia qualcosa dopo di lui
				return (int*) checkInt(input[i+1]); //Poi controllo che sia un Int, e in caso lo restituisco
		} else i++; //Flag non trovato, procedo...
	}

	return NULL; //Se sono arrivato qui, il flag non e' stato trovato.
}
Beispiel #8
0
int main(int argc, char *argv[])
{
	int ia[5] = {1,2,3,4,5};
	char hello[] = "Hello world";
	char seq[] = "ACGT";
        int word;
        char *str;

	checkInt("reverse_int(1)", 1, ia[0]);
	reverse_int(ia,5);
	checkInt("reverse_int(2)", 5, ia[0]);

	checkStr("reverse_seq(1)", "Hello world", hello);
	reverse_seq(hello);
	checkStr("reverse_seq(2)", "dlrow olleH", hello);

	word = str2word(seq, 4);
	checkInt("str2word(1)", 27, word);
	str = word2str(228, 4);
	checkStr("word2str(1)", "TGCA", str);

	return 0;
}
void test(const char * str){
	bool bInt = checkInt(str);
	bool bFloat = checkFloat(str);

	std::cout << "str: " << str << std::endl;

	if(bInt){
		int i = convertStr2Int(str);
		std::cout << "int: " << i << std::endl;
	}

	else if(bFloat){
		double f = convertStr2Float(str);
		std::cout << "float: "<< std::fixed << f << std::endl;
	}

}
Beispiel #10
0
int main(int argc, char** argv) {
	struct timeval start, end;
	gettimeofday(&start, NULL);
	
	if (argc < 2) {
		fprintf(stderr,"Not enough arguments\n");
		return 0;
	}
	else if (argc > 2) {
		fprintf(stderr,"Too many arguments\n");
		return 0;
	}
	if (strcmp(argv[1],"-h") == 0) {
		printf("Usage: formula <positive integer>\n");
		return 0;
	}	
		
	curr_state = mightBeDecFirstNum;
	if (checkInt(argv[1]) == 1) {
		fprintf(stderr,"Input not in positive integer form\n");
		return 0;
	}	
	int n = atoi(argv[1]);
	
	if (factorial(n) == 0) {
		fprintf(stderr,"Overflow detected\n");
		return 0;
	}
	
	printf("(1 + x)^%d = 1",n);
	
	int i = 1, fact;
	for (i; i <= n; i++) {
		fact = nCr(n,i);
		printf(" + %d*x^%d",fact,i);
	}
	printf("\n");
	gettimeofday(&end, NULL);
	
	printf("%ld microseconds\n", ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));

	return 0;
}
Beispiel #11
0
// fastcall inlined -> no f1 codeobject needed anymore
TEST(Inline, inline_fastcall_1) {
  BasicBlock f0;

  f0 << BC::enter_fun      << (int)0
     << BC::push           << C(1)
     << BC::push           << C(1)
     << BC::pushenv

     // f1 copied verbatim
     << BC::mkenv
     << BC::add
     << BC::leave

     << BC::push           << C(1)
     << BC::add
     << BC::leave_fun
     << BC::ret;

  checkInt(f0.code(), 3);
}
void* fullQueueReaderTask(void* ptr) {
    TaskContext* ctx = (TaskContext*)ptr;
    SensorEventQueue* queue = ctx->queue;
    int totalReads = 0;
    while (totalReads < FULL_QUEUE_EVENT_COUNT) {
        pthread_mutex_lock(&mutex);
        // Only read if there are events,
        // and either the queue is full, or if we're reading the last few events.
        while (!fullQueueReaderShouldRead(queue->getSize(), totalReads)) {
            pthread_cond_wait(&dataAvailableCond, &mutex);
        }
        queue->dequeue();
        totalReads++;
        printf("r");
        pthread_mutex_unlock(&mutex);
    }
    printf("\n");
    ctx->success = ctx->success && checkInt("totalreads", FULL_QUEUE_EVENT_COUNT, totalReads);
    return NULL;
}
Beispiel #13
0
// closure is not materialized, we use fastcall
TEST(Inline, baseline_fastcall_1) {
  BasicBlock f0, f1;

  f1 << BC::mkenv
     << BC::add
     << BC::leave
     << BC::ret;

  f0 << BC::enter_fun      << (int)0
     << BC::push           << C(1)
     << BC::push           << C(1)
     << BC::pushenv
     << BC::call_fast      << f1.code()

     << BC::push           << C(1)
     << BC::add
     << BC::leave_fun
     << BC::ret;

  checkInt(f0.code(), 3);
}
Beispiel #14
0
// f0 calling f1
TEST(Inline, baseline_1) {
  BasicBlock f0, f1;

  f1 << BC::enter_fun     << 2
     << BC::add
     << BC::leave_fun
     << BC::ret;

  f0 << BC::enter_fun      << (int)0
     << BC::mkclosure      << f1.code()     << L({a, a})
     << BC::push           << C(1)
     << BC::push           << C(1)
     << BC::call_generic   << 2

     << BC::push           << C(1)
     << BC::add
     << BC::leave_fun
     << BC::ret;

  checkInt(f0.code(), 3);
}
Beispiel #15
0
int main(int argc, char *argv[])
{
  switch(toInt(argv[argc-1]))
    {
    case 1: 
      printf("%i\n", checkInt(argv[1]));
      break;
    case 2: 
      printf("%f\n", checkFl(argv[1]));
      break;
    case 3: 
      intParse(argv[1]);
      break;
    case 4: 
      printf("%s\n", toUpper(argv[1]));
      break;
    case 5: 
      printf("%s\n", toLower(argv[1]));
      break;
    case 6: 
      reverseString(argv[1]);
      break;
    case 7: 
      isPalindrome(argv[1]);
      break;
    case 8: 
      reverseWords(argv[1]);
      break;
    case 9: 
      subsetCheck(argv[1], argv[2]);
      break;
    case 10: 
      partialCopy(argv[1], argv[2]);
      break;
    default:
      printf("Error: Your selection did not match any of the available.\n");
      break;
    }
  return 0;
}
Beispiel #16
0
Type checkIntParam(Type t)
{
	return checkInit(checkKonst(checkInt(t)));
}
void ReportReader::read(std::string filepath, ReportEntity& entity)
{
	std::cout <<filepath<<std::endl;

	static char buff[LINE_BUFF_LEN] = {0};	
	std::ifstream fs(filepath);

	//read header
	if(fs.good())
	{
		memset(buff, 0, sizeof(buff));
		fs.getline(buff, LINE_BUFF_LEN);
		std::string header(buff);

		std::vector< std::string > ret;
		split(header, ";", ret);


		entity.headerAddField("Line num");
		for(std::vector< std::string>::iterator iter = ret.begin();
			iter != ret.end(); ++iter)
		{
			//std::cout << *iter << "|";
			entity.headerAddField(*iter);
		}

		//std::cout << std::endl;
	}

	int linenum = 0;
	while(fs.good())
	{
		memset(buff, 0, sizeof(buff));
		fs.getline(buff, LINE_BUFF_LEN);
		std::string content(buff);

		linenum +=1;
		ReportEntity::ReportRow row;
		ReportEntity::rowAddField(row, linenum);
		//row.push_back(ReportEntity::shareRow(new DataBase(linenum)));

		std::vector< std::string > ret;
		split(content, ";", ret);
		for(std::vector< std::string>::iterator iter = ret.begin();
			iter != ret.end(); ++iter)
		{
			const char *char_str = iter->c_str();
			if(checkInt(char_str)){
				int i = convertStr2Int(char_str);
				ReportEntity::rowAddField(row, i);

			}else if(checkFloat(char_str)){
				double d = convertStr2Float(char_str);
				ReportEntity::rowAddField(row, d);

			} else if(checkNil(char_str)){
				ReportEntity::rowAddField(row, NilData);

			} else {
				ReportEntity::rowAddField(row, *iter);
			}

			//std::cout << *iter << "|";
		}

		entity.contentAddRow(row);
		//std::cout << std::endl;
	}
}