From a5e4be6a091316de03d67ed7b7d39e4eaad036a0 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Fri, 26 Apr 2024 00:59:41 -0300 Subject: [PATCH] Added strucutres and the functions that used it, also modified doxygen to print the code. --- docs/Doxyfile.in | 33 ++++++++---- include/account.h | 24 +++++++++ include/entry.h | 25 +++++++++ include/money.h | 2 +- include/subaccount.h | 28 ++++++++++ include/taccount.h | 22 ++++++++ src/CMakeLists.txt | 2 +- src/account.c | 76 ++++++++++++++++++++++++++++ src/entry.c | 106 ++++++++++++++++++++++++++++++++++++++ src/money.c | 17 +++++-- src/subaccount.c | 118 +++++++++++++++++++++++++++++++++++++++++++ src/taccount.c | 42 +++++++++++++++ 12 files changed, 480 insertions(+), 15 deletions(-) create mode 100644 include/account.h create mode 100644 include/entry.h create mode 100644 include/subaccount.h create mode 100644 include/taccount.h create mode 100644 src/account.c create mode 100644 src/entry.c create mode 100644 src/subaccount.c create mode 100644 src/taccount.c diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index 8a6a9de..4aa3b2a 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "Contarius" +PROJECT_NAME = Contarius # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -58,7 +58,8 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = "@PROJECT_SOURCE_DIR@/build/docs" +OUTPUT_DIRECTORY = @PROJECT_SOURCE_DIR@/build/docs + # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and # will distribute the generated files over these directories. Enabling this @@ -90,6 +91,14 @@ ALLOW_UNICODE_NAMES = NO # Ukrainian and Vietnamese. # The default value is: English. +OUTPUT_LANGUAGE = English + +# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all generated output in the proper direction. +# Possible values are: None, LTR, RTL and Context. +# The default value is: None. + OUTPUT_TEXT_DIRECTION = None # If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member @@ -161,7 +170,7 @@ FULL_PATH_NAMES = YES # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH ="@PROJECT_SOURCE_DIR@" +STRIP_FROM_PATH = "@PROJECT_SOURCE_DIR@" # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which @@ -237,7 +246,7 @@ INHERIT_DOCS = YES # of the file/class/namespace that contains it. # The default value is: NO. -SEPARATE_MEMBER_PAGES = NO +SEPARATE_MEMBER_PAGES = YES # The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen # uses this value to replace tabs by spaces in code fragments. @@ -599,7 +608,7 @@ HIDE_SCOPE_NAMES = NO # YES the compound reference will be hidden. # The default value is: NO. -HIDE_COMPOUND_REFERENCE = NO +HIDE_COMPOUND_REFERENCE= NO # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. @@ -855,7 +864,9 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/../src/" "@CMAKE_CURRENT_SOURCE_DIR@/../include" "@CMAKE_CURRENT_SOURCE_DIR@/../docs" +INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/../include" \ + "@CMAKE_CURRENT_SOURCE_DIR@/../docs" \ + "@CMAKE_CURRENT_SOURCE_DIR@/../src/" # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -1204,7 +1215,7 @@ IGNORE_PREFIX = # If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. -GENERATE_HTML = NO +GENERATE_HTML = NO # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of @@ -1941,7 +1952,7 @@ LATEX_HIDE_INDICES = NO # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_SOURCE_CODE = NO +LATEX_SOURCE_CODE = YES # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See @@ -2150,6 +2161,10 @@ DOCBOOK_PROGRAMLISTING = NO GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# Configuration options related to Sqlite3 output +#--------------------------------------------------------------------------- + #--------------------------------------------------------------------------- # Configuration options related to the Perl module output #--------------------------------------------------------------------------- @@ -2227,7 +2242,7 @@ SEARCH_INCLUDES = YES # preprocessor. # This tag requires that the tag SEARCH_INCLUDES is set to YES. -INCLUDE_PATH = "@PROJECT_SOURCE_DIR@/include" +INCLUDE_PATH = @PROJECT_SOURCE_DIR@/include # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the diff --git a/include/account.h b/include/account.h new file mode 100644 index 0000000..c5fb6a5 --- /dev/null +++ b/include/account.h @@ -0,0 +1,24 @@ +/** @file account.h + * Account structure header file used in the program +*/ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include "subaccount.h" +#include "money.h" + +/** + * @struct account + * @brief Struct representing an Account in the the T-Account +*/ +typedef struct account { + char *name; ///name = name; + account->description = description; + account->value = initalizeMoney(0, 0); + account->subaccounts = NULL; + account->numberOfSubaccounts = 0; + return account; +} +/** + * @brief Updates the total value of the account + * + * @param *account Pointer to the account that will updated + * @param *value Money structure that will be summed to the total value of the account + * +*/ +void updateAccountValue(Account *account, Money *value) { + addMoneyToMoney(account->value, value); +} + + +/** + * @brief Add an subaccount to an account + * + * Calls the @link subaccount::appendSubAccount appendSubAccount @endlink and adds the subaccount to the account, + * if the entries list is empty the subaccount passed as parameter will be the first one + * + * + * @param *account Pointer to the account that will be added on + * @param *subaccount Pointer to the subaccount that will be added on the account +*/ +void addSubAccountToAccount(Account *account, SubAccount *subaccount) { + if (account->subaccounts == NULL) { + account->subaccounts = subaccount; + } else { + appendSubAccount(account->subaccounts, subaccount); + } + updateAccountValue(account, subaccount->value); + account->numberOfSubaccounts++; +} + +/** + * + * @brief Frees the memory used by the account structure + * @details Checks if the members are freed, if so it'll traverse the list of subaccounts and free it untill the end of list + * and then the passed account will be free completely. + * + * @param *account account structure to be freed. + * +*/ +void destroyAccount(Account *account){ + if (account->value != NULL){ + destroyMoney(account->value); + account->value = NULL; + } + destroySubAccount(account->subaccounts); + free(account); + +} diff --git a/src/entry.c b/src/entry.c new file mode 100644 index 0000000..9496ae6 --- /dev/null +++ b/src/entry.c @@ -0,0 +1,106 @@ +/** + * @file entry.c + * Implementation file for the entry strutucture + * @todo Add method to delete the whole list of entries freeing the memory + * @todo Add methodo to remove one item in the list and relink it +*/ + +#include "entry.h" + +/** + * + * @brief Initialize entry structure, + * sets the name and description according with the parameters and return a pointer to structure created. + * + * @param *name the name of the entry to be created + * @param *description the description of the entry to be created + * + * @returns pointer to the created structure + * +*/ +Entry *initializeEntry(char *name, char *description) { + Entry *entry = malloc(sizeof(Entry)); + entry->name = name; + entry->description = description; + entry->next = NULL; + return entry; +} + +/** + * @brief Set a monetary value to the entry structure + * + * Set a the value member of the entry structure with the given money structure given as the parameter of the function. + * @param *entry pointer to the entry to be modified + * @param *money pointer to the money structured to be used as the value + * +*/ +void setEntryValue(Entry *entry, Money *value) { + + entry->value = value; + if (checkOverflow(entry->value)) { + handleOverflow(entry->value); + } +} + +/** + * @brief Adds a pointer to reference to the next entry + * Adds the pointer to the next member of entry strucuture, + * if the member of the current entry is not empty it will iterate till it finds a next ember thats is null. + * + * @param *entry Pointer to entry structure that will iterated and appended. + * @param *newEntry Pointer to entry structure that will be added to the next member. + * + * +*/ + +void appendEntry(Entry *entry, Entry *newEntry) { + Entry *current = entry; + if (current == NULL) { + current = newEntry; + } else { + while (current->next != NULL) { + current = current->next; + } + current->next = newEntry; + } +} + +/** + * + * @brief Traverse the list of entries and prints its informations + * @param *entry Pointer to the entry structure that will be traversed + * +*/ +void traverseEntry(Entry *entry) { + Entry *current = entry; + while (current != NULL) { + printf("Entry Data:\n\nName: %s\nDescription: %s\nValue: %s\n\n", + current->name, current->description, getMoneyString(current->value)); + current = current->next; + } +} +/** + * + * @brief Frees the memory used by the entry structure + * @details Checks if the members are freed, if so it'll traverse the list of entries and free it untill the end of list + * and then the passed entry will be free completely. + * + * @param *entry Entry structure to be freed. + * +*/ +void destroyEntry(Entry *entry){ + if (entry->value != NULL){ + destroyMoney(entry->value); + entry->value = NULL; + } + + Entry *current = entry-> next; + + if (current->next == NULL){ + destroyMoney(current->value); + free(current); + }else{ + destroyEntry(current->next); + } + free(entry); +} diff --git a/src/money.c b/src/money.c index 46a63c6..a5d5374 100644 --- a/src/money.c +++ b/src/money.c @@ -8,8 +8,9 @@ /** * * @brief Initialize a money structure, sets the value according to the parameters and return a pointer to the structure created -* @param full the full value for the structure that will be created -* @param cents the cents value the structure that will be created +* @param full the full value for the structure that will be created. +* @param cents the cents value the structure that will be created. +* @return pointer to the created structure. * */ @@ -34,7 +35,6 @@ bool checkOverflow(Money *m) { }; /** -* @deprecated * @brief Check if the value of the cents is less than 0 * @param *m the money structure that will be checked * @retval true if the value is less than 0 @@ -63,7 +63,7 @@ void handleOverflow(Money *m) { }; /** -* @deprecated +* * @brief Handles the case of the cents being less than 0. * * It adds or subtracks to the full part and do a modulus operation on cents @@ -183,4 +183,13 @@ void subtractMoneyToMoney(Money *dest, Money *src) { if (checkUnderflow(dest)) { handleUnderflow(dest); } +} + +/** + * @brief Frees the Memory used by a money structure + * @param *money The money structure that will be freed +*/ + +void destroyMoney(Money *money){ + free(money); } \ No newline at end of file diff --git a/src/subaccount.c b/src/subaccount.c new file mode 100644 index 0000000..32fbaa4 --- /dev/null +++ b/src/subaccount.c @@ -0,0 +1,118 @@ +/** + * @file subbacount.c + * Implementation file for the subaccount strutucture +*/ + +#include "subaccount.h" +#include "money.h" +#include "entry.h" + +/** + * + * @brief Initialize subaccount structure, + * sets the name and description according with the parameters and return a pointer to structure created. + * + * @param *name the name of the subaccount to be created + * @param *description the description of the subaccount to be created + * + * @returns pointer to the created structure + * +*/ + +SubAccount *initializeSubAccount(char *name, char *description) { + SubAccount *subaccount = malloc(sizeof(SubAccount)); + subaccount->name = name; + subaccount->description = description; + subaccount->value = initalizeMoney(0, 0); + subaccount->entries = NULL; + subaccount->numberOfEntries = 0; + subaccount->next = NULL; + + return subaccount; +} + +/** + * @brief Updates the total value of the subaccount + * + * @param *subaccount Pointer to the subaccount that will updated + * @param *value Money structure that will be summed to the total value of the subaccount + * +*/ +void updateSubAccountValue(SubAccount *subaccount, Money *value) { + addMoneyToMoney(subaccount->value, value); +} + +/** + * @brief Add an entry to a subaccount + * + * Calls the @link entry::appendEntry apendlink @endlink and adds the entry to the subaccount, + * if the entries list is empty the entry passed as parameter will be the first one + * + * + * @param *subaccount Pointer to the subaccount that will be added on + * @param *entry Pointer to the entry that will be added on the subaccount +*/ +void addEntryToSubAccount(SubAccount *subaccount, Entry *entry) { + if (subaccount->entries == NULL) { + subaccount->entries = entry; + + } else { + appendEntry(subaccount->entries, entry); + } + updateSubAccountValue(subaccount, entry->value); + subaccount->numberOfEntries++; +} + +/** + * @brief Appends a pointer reference of subaccount to the member next of a subaccount + * + * Appends the pointer of a subaccount to the next member of the subaccount, + * if the next member is null the passed subaccount will be the first one in the list, + * if not the code will traverse till it finds a null next to be appended + * + * @param *subaccount Pointer to subaccount that will be added onto + * @param *newSubaccount Pointer to the subaccount that will added into the list +*/ + +void appendSubAccount(SubAccount *subaccount, SubAccount *newSubaccount) { + SubAccount *current = subaccount; + if (current->next == NULL) { + current->next = newSubaccount; + } else { + while (current->next != NULL) { + current = current->next; + } + current->next = newSubaccount; + } +} + + +/** + * + * @brief Frees the memory used by the subaccount structure + * @details Checks if the members are freed, if so it'll traverse the list of entries and free it untill the end of list + * and then the passed subaccount will be free completely. + * + * @param *subaccount subaccount structure to be freed. + * +*/ +void destroySubAccount(SubAccount *subaccount){ + + if (subaccount->value != NULL){ + destroyMoney(subaccount->value); + subaccount->value = NULL; + } + + SubAccount *current = subaccount->next; + + if (current->next == NULL){ + destroyMoney(current->value); + destroyEntry(current->entries); + free(current); + }else{ + destroySubAccount(current->next); + } + free(subaccount); + + +} \ No newline at end of file diff --git a/src/taccount.c b/src/taccount.c new file mode 100644 index 0000000..20d6b52 --- /dev/null +++ b/src/taccount.c @@ -0,0 +1,42 @@ +/** + * @file taccount.c + * Implementation file for the taccount strutucture +*/ + +#include "taccount.h" + +/** + * + * @brief Initialize taccount structure, + * Return a pointer to structure created. + * + * + * @returns pointer to the created structure + * +*/ + +TAccount *initializeTAccount() { + TAccount *taccount = malloc(sizeof(TAccount)); + taccount->credits = initializeAccount("Credit Account", "Credit Account"); + taccount->debits = initializeAccount("Debit Account", "Debit Account"); + return taccount; +} + +/** + * + * @brief Frees the memory used by the taccount structure + * @details Checks if the members are freed, if so it'll traverse the list of credit accounts and the list of debit accounts and free it untill the end of list + * and then the passed taccount will be free completely. + * + * @param *subaccount taccount structure to be freed. + * +*/ +void destroyTAccount(TAccount *taccount){ + if (taccount->credits != NULL){ + destroyAccount(taccount->credits); + } + if (taccount->debits != NULL){ + destroyAccount(taccount->debits); + } + free(taccount); +} \ No newline at end of file