Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
156 lines (126 sloc) 3.64 KB
//
// model_builder.c
// CleverModels
//
// Created by Bruno Martins on 3/29/12.
// Copyright (c) 2012. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include "languages.h"
#include "model_builder.h"
#include "clever_models.h"
#include "helper_functions.h"
#include "java/java_model_writer.h"
#include "objc/objc_model_writer.h"
#include "cs/cs_model_writer.h"
int write_setters(FILE* implementation_file, FILE* header_file, int language_code, char attributes[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH], int attr_types[], int nr_attributes)
{
int result = -1;
switch (language_code) {
case JAVA:
result = java_write_setters(implementation_file, nr_attributes, attributes, attr_types);
break;
case CSHARP:
result = cs_write_setters(implementation_file, nr_attributes, attributes, attr_types);
break;
default:
break;
}
return result;
}
int write_getters(FILE* implementation_file, FILE* header_file, int language_code, char attributes[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH], int attr_types[], int nr_attributes)
{
int result = -1;
switch (language_code) {
case JAVA:
result = java_write_getters(implementation_file, nr_attributes, attributes, attr_types);
break;
case CSHARP:
result = cs_write_getters(implementation_file, nr_attributes, attributes, attr_types);
break;
default:
break;
}
return result;
}
int write_class_header(char class_name[], int16_t language, FILE* implementation_file, FILE* header_file) {
int result = -1;
switch (language) {
case JAVA:
result = java_write_class_header(implementation_file, class_name);
break;
case OBJC:
result = objc_write_class_header(implementation_file, header_file, class_name);
break;
case CSHARP:
result = cs_write_class_header(implementation_file, class_name);
break;
default:
break;
}
return result;
}
int write_attribute(char attribute_name[], int16_t type, int16_t language,
FILE* implementation_file, FILE* header_file) {
int result = -1;
switch (language) {
case JAVA:
result = java_write_attribute(implementation_file, attribute_name, type);
break;
case OBJC:
result = objc_write_attribute(implementation_file, header_file, attribute_name, type);
break;
case CSHARP:
result = cs_write_attribute(implementation_file, attribute_name, type);
break;
default:
break;
}
return result;
}
void create_class_files(char name[], char path[], int language_code, char class_headers[] , FILE** implementation, FILE** header) {
char file_path[255]; //implementation file
char header_file_path[255]; // header, if needed
strcpy(file_path, path);
strcpy(header_file_path, path);
name[0] = toupper(name[0]);
char* singular_class_name = str_plural_to_singular(name);
strcat(file_path, singular_class_name);
strcat(file_path, ".");
strcat(header_file_path, singular_class_name);
strcat(header_file_path, ".");
*header = NULL;
switch (language_code) {
case JAVA:
strcat(file_path, "java");
break;
case OBJC:
strcat(file_path, "m");
strcat(header_file_path, "h");
*header = fopen(header_file_path, "w+");
if (NULL == *header) {
perror("failed in creating header file \n");
exit(-1);
}
break;
case CSHARP:
strcat(file_path, "cs");
break;
default:
break;
}
*implementation = fopen(file_path, "w+");
if (NULL == *implementation) {
perror("failed creating implementation file \n");
exit(-1);
}
fprintf(*implementation, "// Class generated by Clever Models \n");
if (0 != class_headers) {
fprintf(*implementation, "%s\n\n", class_headers);
if(NULL != *header) {
printf("no no no no! \n");
fprintf(*header, "%s\n\n", class_headers);
}
}
}
Something went wrong with that request. Please try again.