Skip to content

Commit

Permalink
Support for C# Pojos added. Fixed wrgon character Bug when closing cl…
Browse files Browse the repository at this point in the history
…asses
  • Loading branch information
ehanoc committed Jun 12, 2012
1 parent 1ac2203 commit 09137f5
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 39 deletions.
Binary file added Debug/cm
Binary file not shown.
24 changes: 24 additions & 0 deletions Debug/cs/subdir.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../cs/cs_model_writer.c

OBJS += \
./cs/cs_model_writer.o

C_DEPS += \
./cs/cs_model_writer.d


# Each subdirectory must supply rules for building sources it contributes
cs/%.o: ../cs/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cross GCC Compiler'
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '


1 change: 1 addition & 0 deletions Debug/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RM := rm -rf
-include sources.mk
-include objc/subdir.mk
-include java/subdir.mk
-include cs/subdir.mk
-include subdir.mk
-include objects.mk

Expand Down
1 change: 1 addition & 0 deletions Debug/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ SUBDIRS := \
objc \
. \
java \
cs \

8 changes: 5 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Clever Models

Small tool to generate model classes from Restful Feeds. ( JSON & XML (planned) ) .
Small tool to generate POJOs model classes from Feeds. ( JSON ) .

Current initial Support, Java models from JSON Feeds.
Current Support, Java, C# & Objective-C models from JSON Feeds.

Install :

Expand All @@ -24,4 +24,6 @@ Supported Language arguments

-l java
or
-l objc
-l' objc
or
-l csharp
Binary file modified Release/cm
Binary file not shown.
24 changes: 24 additions & 0 deletions Release/cs/subdir.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../cs/cs_model_writer.c

OBJS += \
./cs/cs_model_writer.o

C_DEPS += \
./cs/cs_model_writer.d


# Each subdirectory must supply rules for building sources it contributes
cs/%.o: ../cs/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cross GCC Compiler'
gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '


1 change: 1 addition & 0 deletions Release/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RM := rm -rf
-include sources.mk
-include objc/subdir.mk
-include java/subdir.mk
-include cs/subdir.mk
-include subdir.mk
-include objects.mk

Expand Down
1 change: 1 addition & 0 deletions Release/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ SUBDIRS := \
objc \
. \
java \
cs \

6 changes: 3 additions & 3 deletions clever_models.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ unsigned int write_json_class_model(char name[], char json[], int language_code,

FILE* implementation_file = 0;
FILE* header_file = 0;
printf("writting class files ! \n");
printf("writting class files ! language_code : %d \n", language_code);
create_class_files(name, path, language_code, class_headers, &implementation_file, &header_file);
write_class_header(name, language_code, implementation_file, header_file);
printf("wrote class files ! \n");
Expand Down Expand Up @@ -145,14 +145,14 @@ unsigned int write_json_class_model(char name[], char json[], int language_code,
if(OBJC == language_code)
fprintf(implementation_file, "@end");
else
fprintf(implementation_file, "@end");
fprintf(implementation_file, "}");

fclose(implementation_file);
if (NULL != header_file) {
if(OBJC == language_code)
fprintf(header_file, "@end");
else
fprintf(header_file, "@end");
fprintf(header_file, "}");
fclose(implementation_file);
}
//free(mutable_json);
Expand Down
131 changes: 131 additions & 0 deletions cs/cs_model_writer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* cs_model_writer.c
*
* Created on: Jun 12, 2012
* Author: bmartins
*/

#include <stdio.h>
#include "cs_model_writer.h"
#include "../helper_functions.h"
#include "../clever_models.h"

int32_t cs_write_class_header(FILE* fp, char class_name[]) {
int32_t result = -1;
class_name[0] = toupper(class_name[0]);
char* singular_class_name = str_plural_to_singular(class_name);
fprintf(fp, "\n using System;");
fprintf(fp, "\n using System.Collections.Generic;");
result = fprintf(fp, "\n public class %s { \n", singular_class_name);
return result;
}

int32_t cs_write_attribute(FILE* fp, char attribute_name[], u_int16_t type) {
u_int32_t result = -1;

char c = toupper(attribute_name[0]);

char* object_type_name = malloc(strlen(attribute_name));
strncpy(object_type_name, attribute_name, strlen(attribute_name));
object_type_name[strlen(attribute_name)] = '\0';

*object_type_name = c;
object_type_name = str_plural_to_singular(object_type_name);

if (TYPE_OBJECT == type)
result = fprintf(fp, "\tprivate %s %s; \n", object_type_name,
attribute_name);
else if (TYPE_LIST == type)
result = fprintf(fp, "\tprivate List<%s> %s; \n", object_type_name,
attribute_name);
else if (TYPE_INTEGER == type)
result = fprintf(fp, "\tprivate int %s; \n", attribute_name);
else if (TYPE_STRING == type)
result = fprintf(fp, "\tprivate string %s; \n", attribute_name);
else if (TYPE_BOOLEAN == type)
result = fprintf(fp, "\tprivate bool %s; \n", attribute_name);
else
result = fprintf(fp, "\tprivate string %s; \n", attribute_name);


free(object_type_name);
return result;
}

int cs_write_getters(FILE* fp, int nr_attributes, char attributes[50][100], int attr_types[]) {
int i;
for (i = 0; i < nr_attributes; ++i) {

char* uppercase_attribute_name = malloc(sizeof(attributes[i]));
strncpy(uppercase_attribute_name, attributes[i], sizeof(attributes[i]));
uppercase_attribute_name[strlen(uppercase_attribute_name)] = '\0';
uppercase_attribute_name[0] = toupper(uppercase_attribute_name[0]);

char* object_type_name = malloc(sizeof(uppercase_attribute_name));
strncpy(object_type_name, uppercase_attribute_name, sizeof(uppercase_attribute_name));
object_type_name[strlen(uppercase_attribute_name)] = '\0';

object_type_name = str_plural_to_singular(object_type_name);

if (TYPE_OBJECT == attr_types[i])
fprintf(fp, "\n\tpublic %s get%s() { \n", object_type_name, uppercase_attribute_name);
else if (TYPE_LIST == attr_types[i])
fprintf(fp, "\n\tpublic List<%s> get%s() { \n", object_type_name, uppercase_attribute_name);
else if (TYPE_INTEGER == attr_types[i])
fprintf(fp, "\n\tpublic int get%s() { \n", uppercase_attribute_name);
else if (TYPE_STRING == attr_types[i])
fprintf(fp, "\n\tpublic string get%s() { \n", uppercase_attribute_name);
else if (TYPE_BOOLEAN == attr_types[i])
fprintf(fp, "\n\tpublic bool get%s() { \n", uppercase_attribute_name);
else
fprintf(fp, "\n\tpublic string get%s() { \n", uppercase_attribute_name);



fprintf(fp, "\t\t return %s; \n", attributes[i]);
fprintf(fp, "\t} \n");

free(object_type_name);
free(uppercase_attribute_name);
}

return i;
}

int cs_write_setters(FILE* fp, int nr_attributes, char attributes[50][100], int attr_types[]) {
int i;
for (i = 0; i < nr_attributes; ++i) {

char* uppercase_attribute_name = malloc(sizeof(attributes[i]));
strncpy(uppercase_attribute_name, attributes[i], sizeof(attributes[i]));
uppercase_attribute_name[strlen(uppercase_attribute_name)] = '\0';
uppercase_attribute_name[0] = toupper(uppercase_attribute_name[0]);

char* object_type_name = malloc(sizeof(uppercase_attribute_name));
strncpy(object_type_name, uppercase_attribute_name, sizeof(uppercase_attribute_name));
object_type_name[strlen(uppercase_attribute_name)] = '\0';

object_type_name = str_plural_to_singular(object_type_name);

if (TYPE_OBJECT == attr_types[i])
fprintf(fp, "\n\tpublic void set%s(%s %s) { \n", uppercase_attribute_name, object_type_name, attributes[i]);
else if (TYPE_LIST == attr_types[i])
fprintf(fp, "\n\tpublic void set%s(List<%s> %s) { \n", uppercase_attribute_name, object_type_name, attributes[i]);
else if (TYPE_INTEGER == attr_types[i])
fprintf(fp, "\n\tpublic void set%s(int %s) { \n", uppercase_attribute_name, attributes[i]);
else if (TYPE_STRING == attr_types[i])
fprintf(fp, "\n\tpublic void set%s(string %s) { \n", uppercase_attribute_name, attributes[i]);
else if (TYPE_BOOLEAN == attr_types[i])
fprintf(fp, "\n\tpublic void set%s(bool %s) { \n", uppercase_attribute_name, attributes[i]);
else
fprintf(fp, "\n\tpublic void set%s(string %s) { \n", uppercase_attribute_name, attributes[i]);

fprintf(fp, "\t\t this.%s = %s; \n", attributes[i], attributes[i]);
fprintf(fp, "\t} \n");

free(object_type_name);
free(uppercase_attribute_name);
}

return i;
}
21 changes: 21 additions & 0 deletions cs/cs_model_writer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* cs_model_writer.h
*
* Created on: Jun 12, 2012
* Author: bmartins
*/

#ifndef CS_MODEL_WRITER_H_
#define CS_MODEL_WRITER_H_

#include <stdlib.h>
#include <stdio.h>
#include "../constants.h"

int32_t cs_write_class_header(FILE* fp, char class_name[]);
int32_t cs_write_attribute(FILE* fp, char attribute_name[], u_int16_t type);
int cs_write_getters(FILE* fp, int nr_attributes, char attributes[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH], int attr_types[]);
int cs_write_setters(FILE* fp, int nr_attributes, char attributes[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH], int attr_types[]);


#endif /* CS_MODEL_WRITER_H_ */
12 changes: 7 additions & 5 deletions languages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <stdlib.h>

const static int JAVA = 0;
const static int PHP = 1;
const static int CSHARP = 2;
const static int CPP = 3;
const static int OBJC = 4;
enum {
JAVA = 0,
PHP = 1,
CSHARP = 2,
CPP = 3,
OBJC = 4
};

int get_language_code(char* language);

Expand Down
Loading

0 comments on commit 09137f5

Please sign in to comment.