/*
Author:	Martin RobinSon
Project:	No Idea
Idea:		Provide maximum functionnality to the standar ANSI C while using no librairy
			by browsing wikipédia computer science we can see multiple possibility in
			programming that C does not support
How:		By building all necessary logic that is up to the user to add interface
			C syntax provide unsafe memory mannipulation and array , we can exploit
			these way to create all that does not depend on file timer data...
*/

/*
Files:		noidea.thing.c
Function:	give abstraction to the value type when putting then in an array
Idea:			replacing value by structure that is aware of it's type can make abstraction
				of type when managing it and consider type only when needed
Purpose:		
Feature:		
lack:			type conversion
function list:

*/

#define NULL 0
#define BOOL 1
#define INT 31
#define FLOAT 32
#define STR 255

#define TRUE 1
#define FALSE 0
#define YES 1
#define NO 0
#define ONE 1
#define ZERO 0

char yes[] = "YES";
char no[] = "NO";

typedef char bool;
typedef int NOIDEA_type;
typedef int NOIDEA_size;

typedef struct NOIDEA_thing
{
    NOIDEA_type type;
    NOIDEA_size size;
    void * it;
    float number;
}NOIDEA_thing;


NOIDEA_type NOIDEA_gettype (NOIDEA_thing * this)
{
  return this->type;
}

NOIDEA_size NOIDEA_getsize (NOIDEA_thing * this)
{
  return this->size;
}

void NOIDEA_setbool (NOIDEA_thing * this, bool it)
{
  this->type = BOOL;
  this->size = sizeof(bool);
  this->it = (void*)(int) it;
  return;
}

void NOIDEA_setstr (NOIDEA_thing * this,int cnt, char * it)
{
  this->type = STR;
  this->size = sizeof(char) * cnt;
  this->it = (void*)(int)it;
  return;
}

void NOIDEA_setint (NOIDEA_thing * this, int it)
{
  this->type = INT;
  this->size = sizeof(int);
  this->number =(float) it;
  return;
}

void NOIDEA_setfloat (NOIDEA_thing * this, float it)
{
  this->type = FLOAT;
  this->size = sizeof(float);
  this->number = (float) it;
  return;
}




bool NOIDEA_getbool (NOIDEA_thing * this)
{
	NOIDEA_type this_type = NOIDEA_gettype(this);
  	if (this_type == BOOL)
    {
      return (bool)(int) this->it;
    }
  	return NO;
}

char *  NOIDEA_getstr (NOIDEA_thing * this)
{
	NOIDEA_type this_type = NOIDEA_gettype(this);
  	if (this_type == STR)
    {
      return (char *) this->it;
    }
  	else
  	{
  		if (this_type == BOOL)
  		{
  			if (NOIDEA_getbool(this) == YES)
  			{
  				return (char *)&yes;
  			}
  			else
  			{
  				return (char *) &no;
  			}
  		}
  		if (this_type == INT)
  		{
  		}
  		if (this_type == FLOAT)
  		{
  		}
  	}
  	return 0;
}

int NOIDEA_getint (NOIDEA_thing * this)
{
	NOIDEA_type this_type = NOIDEA_gettype(this);
  	if ((this_type == FLOAT)||(this_type == INT))
   {
      return (int) this->number;
   }
   else
   {
   	if (this_type == BOOL)
   	{
   		return (int) this->it;
   	}
   	if (this_type == STR)
   	{
   	}
   }
  	return 0;
}

float NOIDEA_getfloat (NOIDEA_thing * this)
{
	NOIDEA_type this_type = NOIDEA_gettype(this);
  	if ((this_type == FLOAT)||(this_type == INT))
   {
      return (float) this->number;
   }
   else
   {
   	if (this_type == BOOL)
   	{
   		return (float)(int) this->it;
   	}
   	if (this_type == STR)
   	{
   	}
   }
  	return 0;
}



void NOIDEA_copy (NOIDEA_thing * src, NOIDEA_thing * dest)
{
  dest->type = src->type;
  dest->size = src->size;
  dest->it = src->it;
  dest->number = src->number;
  return;
}

void NOIDEA_xchg (NOIDEA_thing * src, NOIDEA_thing * dest)
{
  NOIDEA_thing tmp;
  tmp.type = src->type;
  tmp.size = src->size;
  tmp.it = src->it;
  tmp.number = src->number;
  src->type = dest->type;
  src->size = dest->size;
  src->it = dest->it;
  src->number = dest->number;
  dest->type = tmp.type;
  dest->size = tmp.size;
  dest->it = tmp.it;
  dest->number = tmp.number;
  return;
}
