Compare commits
3 Commits
master
...
Developmen
| Author | SHA1 | Date |
|---|---|---|
|
|
13880cca63 | |
|
|
a5e4be6a09 | |
|
|
1695e9dc44 |
|
|
@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
|
||||||
# title of most generated pages and in a few other places.
|
# title of most generated pages and in a few other places.
|
||||||
# The default value is: My Project.
|
# 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
|
# 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
|
# 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
|
# entered, it will be relative to the location where doxygen was started. If
|
||||||
# left blank the current directory will be used.
|
# 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-
|
# 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
|
# directories (in 2 levels) under the output directory of each output format and
|
||||||
# will distribute the generated files over these directories. Enabling this
|
# will distribute the generated files over these directories. Enabling this
|
||||||
|
|
@ -89,7 +90,15 @@ ALLOW_UNICODE_NAMES = NO
|
||||||
# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
|
# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
|
||||||
# Ukrainian and Vietnamese.
|
# Ukrainian and Vietnamese.
|
||||||
# The default value is: English.
|
# The default value is: English.
|
||||||
@PROJECT_SOURCE_DIR@/
|
|
||||||
|
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
|
OUTPUT_TEXT_DIRECTION = None
|
||||||
|
|
||||||
# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
|
# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
|
||||||
|
|
@ -134,7 +143,7 @@ ABBREVIATE_BRIEF = "The $name class" \
|
||||||
# description.
|
# description.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
ALWAYS_DETAILED_SEC = NO
|
ALWAYS_DETAILED_SEC = YES
|
||||||
|
|
||||||
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
||||||
# inherited members of a class in the documentation of that class as if those
|
# inherited members of a class in the documentation of that class as if those
|
||||||
|
|
@ -161,7 +170,7 @@ FULL_PATH_NAMES = YES
|
||||||
# will be relative from the directory where doxygen is started.
|
# will be relative from the directory where doxygen is started.
|
||||||
# This tag requires that the tag FULL_PATH_NAMES is set to YES.
|
# 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
|
# 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
|
# 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.
|
# of the file/class/namespace that contains it.
|
||||||
# The default value is: NO.
|
# 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
|
# 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.
|
# 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.
|
# YES the compound reference will be hidden.
|
||||||
# The default value is: NO.
|
# 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
|
# 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.
|
# 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
|
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||||
# Note: If this tag is empty the current directory is searched.
|
# Note: If this tag is empty the current directory is searched.
|
||||||
|
|
||||||
INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/../src/" "@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
|
# 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
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||||
|
|
@ -1065,7 +1076,7 @@ USE_MDFILE_AS_MAINPAGE =
|
||||||
# also VERBATIM_HEADERS is set to NO.
|
# also VERBATIM_HEADERS is set to NO.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
SOURCE_BROWSER = NO
|
SOURCE_BROWSER = YES
|
||||||
|
|
||||||
# Setting the INLINE_SOURCES tag to YES will include the body of functions,
|
# Setting the INLINE_SOURCES tag to YES will include the body of functions,
|
||||||
# classes and enums directly into the documentation.
|
# classes and enums directly into the documentation.
|
||||||
|
|
@ -1084,13 +1095,13 @@ STRIP_CODE_COMMENTS = YES
|
||||||
# entity all documented functions referencing it will be listed.
|
# entity all documented functions referencing it will be listed.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
REFERENCED_BY_RELATION = NO
|
REFERENCED_BY_RELATION = YES
|
||||||
|
|
||||||
# If the REFERENCES_RELATION tag is set to YES then for each documented function
|
# If the REFERENCES_RELATION tag is set to YES then for each documented function
|
||||||
# all documented entities called/used by that function will be listed.
|
# all documented entities called/used by that function will be listed.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
REFERENCES_RELATION = NO
|
REFERENCES_RELATION = YES
|
||||||
|
|
||||||
# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
|
# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
|
||||||
# to YES then the hyperlinks from functions in REFERENCES_RELATION and
|
# to YES then the hyperlinks from functions in REFERENCES_RELATION and
|
||||||
|
|
@ -1941,7 +1952,7 @@ LATEX_HIDE_INDICES = NO
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag GENERATE_LATEX is set to YES.
|
# 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
|
# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
|
||||||
# bibliography, e.g. plainnat, or ieeetr. See
|
# bibliography, e.g. plainnat, or ieeetr. See
|
||||||
|
|
@ -2150,6 +2161,10 @@ DOCBOOK_PROGRAMLISTING = NO
|
||||||
|
|
||||||
GENERATE_AUTOGEN_DEF = NO
|
GENERATE_AUTOGEN_DEF = NO
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
# Configuration options related to Sqlite3 output
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Configuration options related to the Perl module output
|
# Configuration options related to the Perl module output
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
@ -2227,7 +2242,7 @@ SEARCH_INCLUDES = YES
|
||||||
# preprocessor.
|
# preprocessor.
|
||||||
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
|
# 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
|
# 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
|
# patterns (like *.h and *.hpp) to filter out the header-files in the
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
/** @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;
|
||||||
|
|
||||||
|
Account *initializeAccount(char *name, char *description);
|
||||||
|
void updateAccountValue(Account *account, Money *value);
|
||||||
|
void addSubAccountToAccount(Account *account, SubAccount *subaccount);
|
||||||
|
void destroyAccount(Account *account);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
Entry *initializeEntry(char *name, char *description);
|
||||||
|
void setEntryValue(Entry *entry, Money *value);
|
||||||
|
void appendEntry(Entry *entry, Entry *newEntry);
|
||||||
|
void traverseEntry(Entry *entry);
|
||||||
|
void destroyEntry(Entry *entry);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/** @file money.h
|
||||||
|
* Money structure header file used in the program
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MONEY_H
|
||||||
|
#define MONEY_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct money
|
||||||
|
* @brief Struct Holding the Monetary value in a separate form
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct money {
|
||||||
|
int full; ///< The Full part of the monetary value
|
||||||
|
int cents; ///< The Cents parts of the monetary value
|
||||||
|
} Money;
|
||||||
|
|
||||||
|
Money *initalizeMoney(int full, int cents);
|
||||||
|
|
||||||
|
void addMoneyToMoney(Money *dest, Money *src);
|
||||||
|
void subtractMoneyToMoney(Money *dest, Money *src);
|
||||||
|
bool checkOverflow(Money *m);
|
||||||
|
bool checkUnderflow(Money *m);
|
||||||
|
void handleOverflow(Money *m);
|
||||||
|
void handleUnderflow(Money *m);
|
||||||
|
void setMoneyValue(Money *m, int full, int cents);
|
||||||
|
char *getMoneyString(Money *m);
|
||||||
|
void destroyMoney(Money *money);
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
SubAccount *initializeSubAccount(char *name, char *description);
|
||||||
|
void updateSubAccountValue(SubAccount *subaccount, Money *value);
|
||||||
|
void addEntryToSubAccount(SubAccount *subaccount, Entry *entry);
|
||||||
|
void appendSubAccount(SubAccount *subaccount, SubAccount *newSubaccount);
|
||||||
|
void destroySubAccount(SubAccount *subaccount);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
TAccount *initializeTAccount();
|
||||||
|
void destroyTAccount(TAccount *taccount);
|
||||||
|
Account *getListAccountsPointers(TAccount *tAccount);
|
||||||
|
#endif
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
set(SOURCE_FILES main.c)
|
set(SOURCE_FILES main.c taccount.c account.c subaccount.c entry.c money.c)
|
||||||
|
|
||||||
add_executable(Contarius ${SOURCE_FILES})
|
add_executable(Contarius ${SOURCE_FILES})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* @file account.c.c
|
||||||
|
* Implementation file to use the account structure
|
||||||
|
*/
|
||||||
|
#include "account.h"
|
||||||
|
#include "money.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
/**
|
||||||
|
* @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 == NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (entry->value != NULL){
|
||||||
|
destroyMoney(entry->value);
|
||||||
|
entry->value = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry *current = entry-> next;
|
||||||
|
if (current != NULL) {
|
||||||
|
if (current->next == NULL) {
|
||||||
|
destroyMoney(current->value);
|
||||||
|
free(current);
|
||||||
|
} else {
|
||||||
|
destroyEntry(current->next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
21
src/main.c
21
src/main.c
|
|
@ -1,9 +1,30 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "taccount.h"
|
||||||
|
#include "account.h"
|
||||||
|
#include "subaccount.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
TAccount *t1 = initializeTAccount();
|
||||||
|
SubAccount *chainsaw = initializeSubAccount("Chainsaw Sales", "Annual revenue of hte sale of chainsaws");
|
||||||
|
Entry *q1Chainsaw = initializeEntry("Q1 Chainsaw Sales","Sales figures for Q1 of sales of chainsaws");
|
||||||
|
setEntryValue(q1Chainsaw, initalizeMoney(1500000,99));
|
||||||
|
SubAccount *chaps = initializeSubAccount("Chaps Sales", "Annual revenue of hte sale of chaps");
|
||||||
|
Entry *q1Chaps= initializeEntry("Q1 Chap Sales","Sales figures for Q1 of sales of chaps");
|
||||||
|
setEntryValue(q1Chaps, initalizeMoney(1500,99));
|
||||||
|
Entry *q2Chaps= initializeEntry("Q2 Chap Sales","Sales figures for Q2 of sales of chaps");
|
||||||
|
setEntryValue(q2Chaps, initalizeMoney(1500,99));
|
||||||
|
addSubAccountToAccount(t1->credits,chainsaw);
|
||||||
|
addEntryToSubAccount(chainsaw,q1Chainsaw);
|
||||||
|
addSubAccountToAccount(t1->credits,chaps);
|
||||||
|
addEntryToSubAccount(chaps,q1Chaps);
|
||||||
|
addEntryToSubAccount(chaps,q2Chaps);
|
||||||
|
|
||||||
|
|
||||||
|
destroyTAccount(t1);
|
||||||
printf("Contarius is Being Made (SomeHow)...\n");
|
printf("Contarius is Being Made (SomeHow)...\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
/**
|
||||||
|
* @file money.c
|
||||||
|
* Implementation file to use the money structure
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "money.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* @return pointer to the created structure.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Money *initalizeMoney(int full, int cents) {
|
||||||
|
Money *m = malloc(sizeof(Money));
|
||||||
|
m->full = full;
|
||||||
|
m->cents = cents;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the value of the cents is bigger than 100
|
||||||
|
* @param *m the money structure that will be checked
|
||||||
|
* @retval true if the value is bigger than 100
|
||||||
|
* @retval false if the falue is not bigger than 100
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool checkOverflow(Money *m) {
|
||||||
|
if (m->cents >= 100)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
* @retval false if the falue is less than 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool checkUnderflow(Money *m) {
|
||||||
|
if (m->cents < 0)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handles the case of the cents being bigger than 100.
|
||||||
|
*
|
||||||
|
* It adds or subtracks to the full part and do a modulus operation on cents
|
||||||
|
* @param *m The money structure that will be operated on
|
||||||
|
*/
|
||||||
|
void handleOverflow(Money *m) {
|
||||||
|
if (m->full > 0) {
|
||||||
|
m->full += m->cents / 100;
|
||||||
|
} else {
|
||||||
|
m->full -= m->cents / 100;
|
||||||
|
}
|
||||||
|
m->cents = m->cents % 100;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* @param *m The money structure that will be operated on
|
||||||
|
*/
|
||||||
|
void handleUnderflow(Money *m) {
|
||||||
|
m->cents = 100 + m->cents;
|
||||||
|
if (m->full > 0) {
|
||||||
|
m->full -= 1;
|
||||||
|
} else {
|
||||||
|
m->full += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the value for a money structure
|
||||||
|
*
|
||||||
|
* @param *m The money structure that will be set the value
|
||||||
|
* @param full the full value that money structure will set to
|
||||||
|
* @param cents the cent value that money structure will set to
|
||||||
|
*/
|
||||||
|
void setMoneyValue(Money *m, int full, int cents) {
|
||||||
|
m->full = full;
|
||||||
|
m->cents = cents;
|
||||||
|
if (checkOverflow(m)) {
|
||||||
|
handleOverflow(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the value of a money structure as a string
|
||||||
|
* @param *m The money structure that string will be generated from
|
||||||
|
* @returns the values of the money structure as a string
|
||||||
|
*/
|
||||||
|
char *getMoneyString(Money *m) {
|
||||||
|
char *str = malloc(sizeof(char) * 20);
|
||||||
|
char *str_cents = malloc(sizeof(char) * 4);
|
||||||
|
char *str_full = malloc(sizeof(char) * 100);
|
||||||
|
if (m->cents < 10) {
|
||||||
|
sprintf(str_cents, "0%d", m->cents);
|
||||||
|
} else {
|
||||||
|
sprintf(str_cents, "%d", m->cents);
|
||||||
|
}
|
||||||
|
sprintf(str, "%2i,%s", m->full, str_cents);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sums two money structures.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Executes the summing of two money strucutures,
|
||||||
|
* it sums the destination money structure to the source money structure,
|
||||||
|
* altering the the destination money structure.
|
||||||
|
*
|
||||||
|
* @param *dest The money structure that will be altered
|
||||||
|
* @param *src The money srtruture that will used to alter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void addMoneyToMoney(Money *dest, Money *src) {
|
||||||
|
if (dest->full < 0) {
|
||||||
|
if (src->full > 0) {
|
||||||
|
dest->cents = (-1 * dest->cents) + src->cents;
|
||||||
|
dest->full = dest->full + src->full;
|
||||||
|
} else {
|
||||||
|
dest->cents = ((-1 * dest->cents) + (-1 * src->cents)) * -1;
|
||||||
|
|
||||||
|
dest->full = dest->full + src->full;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (src->full > 0) {
|
||||||
|
dest->cents += src->cents;
|
||||||
|
dest->full += src->full;
|
||||||
|
} else {
|
||||||
|
dest->cents = (dest->cents + (-1 * src->cents)) * -1;
|
||||||
|
dest->full = dest->full + src->full;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkOverflow(dest)) {
|
||||||
|
handleOverflow(dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Subtracts two money structures
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Executes the subtraction of two money strucutures,
|
||||||
|
* it subtracts the destination money structure to the source money structure,
|
||||||
|
* altering the the destination money structure.
|
||||||
|
*
|
||||||
|
* @param *dest The money structure that will be altered
|
||||||
|
* @param *src The money srtruture that will used to alter
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void subtractMoneyToMoney(Money *dest, Money *src) {
|
||||||
|
if (dest->full > 0) {
|
||||||
|
if (src->full > 0) {
|
||||||
|
dest->cents = dest->cents - src->cents;
|
||||||
|
dest->full = dest->full - src->full;
|
||||||
|
} else {
|
||||||
|
dest->cents = dest->cents - (-1 * src->cents);
|
||||||
|
dest->full = dest->full - src->full;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (src->full > 0) {
|
||||||
|
dest->cents = -1 * ((-1 * dest->cents) - src->cents);
|
||||||
|
dest->full = dest->full - src->full;
|
||||||
|
} else {
|
||||||
|
dest->cents = dest->cents - src->cents;
|
||||||
|
dest->full = dest->full - src->full;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
/**
|
||||||
|
* @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 == NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (subaccount->value != NULL){
|
||||||
|
destroyMoney(subaccount->value);
|
||||||
|
subaccount->value = NULL;
|
||||||
|
}
|
||||||
|
destroyEntry(subaccount->entries);
|
||||||
|
SubAccount *current = subaccount->next;
|
||||||
|
if (current != NULL) {
|
||||||
|
if (current->next == NULL) {
|
||||||
|
destroyMoney(current->value);
|
||||||
|
destroyEntry(current->entries);
|
||||||
|
free(current);
|
||||||
|
} else {
|
||||||
|
destroySubAccount(current->next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(subaccount);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue