Added strucutres and the functions that used it, also modified doxygen to print the code.

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2024-04-26 00:59:41 -03:00
parent 1695e9dc44
commit a5e4be6a09
12 changed files with 480 additions and 15 deletions

View File

@ -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

24
include/account.h Normal file
View File

@ -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 of the account
char *description; ///< Description of the account
Money *value; ///< Total of the values of the subaccounts
SubAccount *subaccounts; ///< List of subaccounts
int numberOfSubaccounts; ///< Number of subaccounts on the list
} Account;
#endif

25
include/entry.h Normal file
View File

@ -0,0 +1,25 @@
/**
* @file entry.h
* Entry structure header file used in the program
*
* @todo Add the functions prototypes to this header
*/
#ifndef ENTRY_H
#define ENTRY_H
#include "money.h"
/**
* @struct entry
* @brief Struct representing an entry in the the T-Account
*/
typedef struct entry {
char *name; ///< Name of the entry
char *description; ///< Description of the entry
Money *value; ///< Monetary value of the Entry
struct entry *next; ///< Pointer to the next entry in the list of entries
} Entry;
#endif

View File

@ -19,7 +19,7 @@ typedef struct money {
int cents; ///< The Cents parts of the monetary value
} Money;
Money *InitializeMoney(int full, int cents);
Money *initializeMoney(int full, int cents);
void addMoneyToMoney(Money *dest, Money *src);
void subtractMoneyToMoney(Money *dest, Money *src);

28
include/subaccount.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @file subaccount.h
* Subaccount strucuture header file used in the program
*/
#ifndef SUBACCOUNT_H
#define SUBACCOUNT_H
#include "money.h"
#include "entry.h"
/**
* @struct subaccount
* @brief Struct representing a subaccount on the T-Account
*
*/
typedef struct subaccount {
char *name; ///< Name of the subaccount
char *description; ///< Description of the subaccount
Money *value; ///< Total of the values of the entries
Entry *entries; ///< List of entries
int numberOfEntries; ///< Counter of entries in the subaccount
struct subaccount *next; ///< Reference to the next subaccount
} SubAccount;
#endif

22
include/taccount.h Normal file
View File

@ -0,0 +1,22 @@
/**
* @file taccount.h
* TAccount structure header file used in the program
*/
#ifndef TACCOUNT_H
#define TACCOUNT_H
#include "account.h"
/**
* @struct taccount
* @brief Struct representing an T-Account
*/
typedef struct taccount {
Account *credits; ///< credits account
Account *debits; ///< debits account
} TAccount;
#endif

View File

@ -1,4 +1,4 @@
set(SOURCE_FILES main.c money.c)
set(SOURCE_FILES main.c taccount.c account.c subaccount.c entry.c money.c)
add_executable(Contarius ${SOURCE_FILES})

76
src/account.c Normal file
View File

@ -0,0 +1,76 @@
/**
* @file account.c.c
* Implementation file to use the account structure
*/
#include "account.h"
/**
*
* @brief Initialize account structure,
* sets the name and description according with the parameters and return a pointer to structure created.
*
* @param *name the name of the account to be created
* @param *description the description of the account to be created
*
* @returns pointer to the created structure
*
*/
Account *initializeAccount(char *name, char *description) {
Account *account = malloc(sizeof(Account));
account->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);
}

106
src/entry.c Normal file
View File

@ -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);
}

View File

@ -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
@ -184,3 +184,12 @@ void subtractMoneyToMoney(Money *dest, Money *src) {
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);
}

118
src/subaccount.c Normal file
View File

@ -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);
}

42
src/taccount.c Normal file
View File

@ -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);
}