From 551bf2cd510f57f9b92c68c7dbc106ecbea290ef Mon Sep 17 00:00:00 2001 From: klmp200 Date: Tue, 5 Jun 2018 00:26:48 +0200 Subject: [PATCH] On test les objets, attention, les listes ne sont pas fonctionelles --- .gitignore | 229 +++++++++++++++++++++++++++++++++++ .idea/LO41.iml | 2 + .idea/codeStyles/Project.xml | 29 +++++ .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + CMakeLists.txt | 7 ++ List/Element.c | 37 ++++++ List/Element.h | 30 +++++ List/List.c | 23 ++++ List/List.h | 29 +++++ Objects.c | 12 ++ Objects.h | 53 ++++++++ main.c | 12 ++ 14 files changed, 481 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/LO41.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt create mode 100644 List/Element.c create mode 100644 List/Element.h create mode 100644 List/List.c create mode 100644 List/List.h create mode 100644 Objects.c create mode 100644 Objects.h create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..250b842 --- /dev/null +++ b/.gitignore @@ -0,0 +1,229 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Vim template +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] + +# Session +Session.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ +### C template +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +### Emacs template +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el +### SublimeText template +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + diff --git a/.idea/LO41.iml b/.idea/LO41.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/LO41.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b1353e7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0f6d9b1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.9) +project(LO41 C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + +add_executable(LO41 main.c List/List.h List/List.c Objects.h List/Element.c List/Element.h Objects.c) \ No newline at end of file diff --git a/List/Element.c b/List/Element.c new file mode 100644 index 0000000..b33b45e --- /dev/null +++ b/List/Element.c @@ -0,0 +1,37 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// + +#include +#include "List.h" + +GETTER(Element, Element*, next) +GETTER(Element, Element*, previous) +GETTER(Element, void*, data) + +void set_previous_Element(THIS(Element), Element *previous){ + this->previous = previous; +} + +void set_next_Element(THIS(Element), Element *next){ + this->next = next; +} + +void $_free__Element(THIS(Element)){ + free(this); +} + +Element *_init_element(void *data, size_t size, List *list){ + Element *el = (Element*) malloc_or_die(sizeof(Element)); + void *newData = malloc_or_die(sizeof(size)); + + memcpy(newData, data, size); + el->list = list; + el->data = newData; + el->previous = NULL; + el->next = NULL; + + LINK_ALL(Element, el, get_next, get_previous, get_data, set_next, set_previous) + + return el; +} diff --git a/List/Element.h b/List/Element.h new file mode 100644 index 0000000..3ce4888 --- /dev/null +++ b/List/Element.h @@ -0,0 +1,30 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// + +#ifndef LO41_ELEMENT_H +#define LO41_ELEMENT_H + +typedef struct o_List List; + +#include "List.h" + +struct o_Element { + List *list; + void *data; + struct o_Element *next; + struct o_Element *previous; + + struct o_Element *(*get_next)(O_THIS(Element)); + struct o_Element *(*get_previous)(O_THIS(Element)); + void *(*get_data)(O_THIS(Element)); + + void (*set_previous)(O_THIS(Element), struct o_Element *previous); + void (*set_next)(O_THIS(Element), struct o_Element *next); + + void (*$_free_)(O_THIS(Element)); +}; + +Element *$_init_Element(void *data, size_t size, List *list); + +#endif //LO41_ELEMENT_H diff --git a/List/List.c b/List/List.c new file mode 100644 index 0000000..b40b351 --- /dev/null +++ b/List/List.c @@ -0,0 +1,23 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// +#include "List.h" + +GETTER(List, Element*, head) +GETTER(List, Element*, tail) +GETTER(List, int, size) + +void $_free__List(THIS(List)){ + free(this); +} + +List *$_init_List(){ + List *l = (List*) malloc_or_die(sizeof(List)); + l->size = 0; + l->head = NULL; + l->tail = NULL; + + LINK_ALL(List, l, get_head, get_tail, get_size) + return l; +} + diff --git a/List/List.h b/List/List.h new file mode 100644 index 0000000..a47851e --- /dev/null +++ b/List/List.h @@ -0,0 +1,29 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// + +#ifndef LO41_LIST_H +#define LO41_LIST_H + +#include "../Objects.h" + +typedef struct o_Element Element; + +#include "Element.h" + +#define WRONG_ELEMENT CRASH("This element is not within the list\n") + +struct o_List { + Element *head; + Element *tail; + int size; + + Element *(*get_head)(O_THIS(List)); + Element *(*get_tail)(O_THIS(List)); + int (*get_size)(O_THIS(List)); + void (*$_free_)(O_THIS(List)); +}; + +List *$_init_List(); + +#endif //LO41_LIST_H diff --git a/Objects.c b/Objects.c new file mode 100644 index 0000000..4fd490a --- /dev/null +++ b/Objects.c @@ -0,0 +1,12 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// + +#include "Objects.h" + +void *malloc_or_die(size_t size){ + void *ptr = malloc(size); + if (ptr == NULL) + perror("Error allocating object"); + return ptr; +} diff --git a/Objects.h b/Objects.h new file mode 100644 index 0000000..c502895 --- /dev/null +++ b/Objects.h @@ -0,0 +1,53 @@ +// +// Created by Antoine Bartuccio on 22/05/2018. +// + +#ifndef LO41_OBJECTS_H +#define LO41_OBJECTS_H + +#include +#include + +#define NEW(type, ...) $_init_##type(__VA_ARGS__) +#define DELETE(obj) obj->$_free_(obj) +#define THIS(type) type *this +#define O_THIS(type) struct o_##type *this +#define CRASH(message) perror(message) + +#define SYNCHRONIZE + +#define LINK(type, obj, method) obj->method = method##_##type; +#define GETTER(obj_type, variable_type, variable) variable_type get_##variable##_##obj_type(obj_type *this){\ + return this->variable; } + +void * malloc_or_die(size_t size); + +/* Link all method from variadic list, support max 20 args */ +#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) +#define VA_NUM_ARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, N, ...) N +#define LINK_NB_(N) LINK_ALL_##N +#define LINK_NB(N) LINK_NB_(N) +#define LINK_ALL(type, obj, ...) LINK(type, obj, $_free_) LINK_NB(VA_NUM_ARGS(__VA_ARGS__))(type, obj, __VA_ARGS__) +#define LINK_ALL_1(type, obj, method, ...) LINK(type, obj, method) +#define LINK_ALL_2(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_1(type, obj, __VA_ARGS__) +#define LINK_ALL_3(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_2(type, obj, __VA_ARGS__) +#define LINK_ALL_4(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_3(type, obj, __VA_ARGS__) +#define LINK_ALL_5(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_4(type, obj, __VA_ARGS__) +#define LINK_ALL_6(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_5(type, obj, __VA_ARGS__) +#define LINK_ALL_7(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_6(type, obj, __VA_ARGS__) +#define LINK_ALL_8(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_7(type, obj, __VA_ARGS__) +#define LINK_ALL_9(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_8(type, obj, __VA_ARGS__) +#define LINK_ALL_10(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_9(type, obj, __VA_ARGS__) +#define LINK_ALL_11(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_10(type, obj, __VA_ARGS__) +#define LINK_ALL_12(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_11(type, obj, __VA_ARGS__) +#define LINK_ALL_13(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_12(type, obj, __VA_ARGS__) +#define LINK_ALL_14(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_13(type, obj, __VA_ARGS__) +#define LINK_ALL_15(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_14(type, obj, __VA_ARGS__) +#define LINK_ALL_16(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_15(type, obj, __VA_ARGS__) +#define LINK_ALL_17(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_16(type, obj, __VA_ARGS__) +#define LINK_ALL_18(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_17(type, obj, __VA_ARGS__) +#define LINK_ALL_19(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_18(type, obj, __VA_ARGS__) +#define LINK_ALL_20(type, obj, method, ...) LINK(type, obj, method) LINK_ALL_19(type, obj, method, __VA_ARGS__) + + +#endif //LO41_OBJECTS_H diff --git a/main.c b/main.c new file mode 100644 index 0000000..39136f5 --- /dev/null +++ b/main.c @@ -0,0 +1,12 @@ +#include +#include "Objects.h" +#include "List/List.h" + +int main() { + List *l = NEW(List); + printf("La taille est de %d\n", l->get_size(l)); + DELETE(l); + + printf("Hello, World!\n"); + return 0; +} \ No newline at end of file