ZE-Standard-Libraries/stack/stack_expand.c

63 lines
1.5 KiB
C
Raw Normal View History

2018-08-23 16:57:38 +00:00
#include <type.h>
#include <stack/stack.h>
#include <stack/stack_expand.h>
2018-06-12 11:07:12 +00:00
SNode *snodeWithInt(int temp) {
SNode *p_snode = initSNode();
2018-08-07 04:10:55 +00:00
int *p_temp = (int *)malloc(sizeof(int));
if(p_temp == NULL){
return NULL;
}
2018-06-12 11:07:12 +00:00
*p_temp = temp;
2018-07-23 04:59:16 +00:00
initMallocValueForSNode(p_snode, INT, p_temp);
2018-06-12 11:07:12 +00:00
return p_snode;
}
SNode *snodeWithDouble(double temp) {
SNode *p_snode = initSNode();
2018-08-07 04:10:55 +00:00
double *p_temp = (double *)malloc(sizeof(double));
if(p_temp == NULL){
return NULL;
}
2018-06-12 11:07:12 +00:00
*p_temp = temp;
2018-07-23 04:59:16 +00:00
initMallocValueForSNode(p_snode, DOUBLE, p_temp);
2018-06-12 11:07:12 +00:00
return p_snode;
}
SNode *snodeWithString(char *temp) {
SNode *p_snode = initSNode();
2018-08-07 04:10:55 +00:00
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
if(p_temp == NULL){
return NULL;
}
2018-07-23 04:59:16 +00:00
strcpy(p_temp, temp);
initMallocValueForSNode(p_snode, STRING, p_temp);
2018-06-12 11:07:12 +00:00
return p_snode;
}
SNode *snodeWithPointer(void *temp) {
SNode *p_snode = initSNode();
2018-07-23 04:59:16 +00:00
initMallocValueForSNode(p_snode, POINTER, temp);
2018-06-12 11:07:12 +00:00
return p_snode;
}
int getValueByIntForSNode(SNode *p_snode) {
2018-07-23 04:59:16 +00:00
if (p_snode->type == INT) return *(int *)p_snode->value;
2018-06-12 11:07:12 +00:00
else return -1;
}
double getValueByDoubleForSNode(SNode *p_snode) {
2018-07-23 04:59:16 +00:00
if (p_snode->type == DOUBLE) return *(double *)p_snode->value;
2018-06-12 11:07:12 +00:00
else return -1;
}
char *getValueByStringForSNode(SNode *p_snode) {
2018-07-23 04:59:16 +00:00
if (p_snode->type == STRING) return (char *)p_snode->value;
2018-06-12 11:07:12 +00:00
else return NULL;
}
void *getValueByPointerForSNode(SNode *p_snode) {
2018-07-23 04:59:16 +00:00
if (p_snode->type == POINTER) return (void *)p_snode->value;
2018-06-12 11:07:12 +00:00
else return NULL;
2018-07-23 04:59:16 +00:00
}