Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Data/Inventory.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BID,NAME,AUTHOR,COPIES,RENTED,LINK
B123456,FirstBook,AUTHOR Name,0100,0022,LINK
B222222,SecondBook,AUTHOR Name,0120,0021,LINK
B333333,ThirdBook,AUTHOR Name,0120,0004,LINK
B444444,FoursBook,AUTHOR Name,9999,0000,LINK
B123456,FirstBook,AUTHOR Name,0100,0028,LINK
B222222,SecondBook,AUTHOR Name,0120,0022,LINK
B333333,ThirdBook,AUTHOR Name,0120,0002,LINK
B444444,FoursBook,AUTHOR Name,9999,0001,LINK
B555555,FifthBook,AUTHOR Name,0025,0020,LINK
B666666,SixthBook,AUTHOR Name,0025,0022,LINK
B666666,SixthBook,AUTHOR Name,0025,0023,LINK
Binary file modified LSMS.exe
Binary file not shown.
121 changes: 66 additions & 55 deletions src/Book.cpp
Original file line number Diff line number Diff line change
@@ -1,72 +1,83 @@
#include "Book.h"

Book::Book(csv::Row* _ptr_row){
init(_ptr_row);
}

Book::Book(csv::Row* _ptr_row, csv::CSVParser* _ptr_parser) : Book(_ptr_row){
if (!_ptr_parser)
throw csv::Error("Book: Parser points to nullptr");
mptr_parser = _ptr_parser;
}

void Book::init(csv::Row *_ptr_row)
namespace LSMS
{
if (!_ptr_row)
throw csv::Error("Book: Row points to nullptr");
mptr_info = _ptr_row;
}

Book::~Book(){
delete mptr_info;
}

size_t Book::increase_rented(){
size_t currently_rented = 0;
int rented_length = 4;
std::string currently_rented_s(rented_length--, '0');
Book::Book(csv::Row *_ptr_row)
{
init(_ptr_row);
}

try
Book::Book(csv::Row *_ptr_row, csv::CSVParser *_ptr_parser) : Book(_ptr_row)
{
currently_rented = std::stoi(mptr_info->getvalue("RENTED").data());
++currently_rented;
//Format string to 0001
for (int val = (currently_rented < 0) ? -currently_rented : currently_rented; rented_length >= 0 && val != 0; --rented_length, val /= 10)
currently_rented_s[rented_length] = '0' + val % 10;
if (rented_length >= 0 && currently_rented < 0)
currently_rented_s[0] = '-';
if (!_ptr_parser)
throw csv::Error("Book: Parser points to nullptr");
mptr_parser = _ptr_parser;
}

void Book::init(csv::Row *_ptr_row)
{
if (!_ptr_row)
throw csv::Error("Book: Row points to nullptr");
mptr_info = _ptr_row;
}
catch (const std::invalid_argument &e)

Book::~Book()
{
return csv::npos;
delete mptr_info;
}

if(mptr_info->change_value_in_to("RENTED", currently_rented_s))
if(mptr_parser->updateRow(mptr_info))
return currently_rented;
else
size_t Book::increase_rented()
{
size_t currently_rented = 0;
int format_length = 4;
std::string currently_rented_s(format_length--, '0');

try
{
currently_rented = std::stoi(mptr_info->getvalue("RENTED").data());
++currently_rented;
//Format string to 0001
for (int val = (currently_rented < 0) ? -currently_rented : currently_rented; format_length >= 0 && val != 0; --format_length, val /= 10)
currently_rented_s[format_length] = '0' + val % 10;
if (format_length >= 0 && currently_rented < 0)
currently_rented_s[0] = '-';
}
catch (const std::invalid_argument &e)
{
return csv::npos;
else
return csv::npos;
}
}

bool Book::is_available(){
try{
int copies = std::stoi(mptr_info->getvalue("COPIES").data());
int rented = std::stoi(mptr_info->getvalue("RENTED").data());
return copies - rented;
if (mptr_info->change_value_in_to("RENTED", currently_rented_s))
if (mptr_parser->updateRow(mptr_info))
return currently_rented;
else
return csv::npos;
else
return csv::npos;
}
catch(const std::invalid_argument &){

bool Book::is_available()
{
try
{
int copies = std::stoi(mptr_info->getvalue("COPIES").data());
int rented = std::stoi(mptr_info->getvalue("RENTED").data());
return copies - rented;
}
catch (const std::invalid_argument &)
{
return false;
}
return false;
}
return false;
}

std::string_view Book::get_BID(){
return mptr_info->getvalue(0);
}
std::string_view Book::get_BID()
{
return mptr_info->getvalue(0);
}

csv::Row &Book::get_Row()
{
return *mptr_info;
}

csv::Row &Book::get_Row(){
return *mptr_info;
}
38 changes: 22 additions & 16 deletions src/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
#include "CSVParser.h"
#include <string>

class Book{
private:
csv::Row* mptr_info = nullptr;
csv::CSVParser* mptr_parser = nullptr;
public:
Book() = delete;
Book(csv::Row*);
Book(csv::Row*, csv::CSVParser*);
~Book();

void init(csv::Row*);
namespace LSMS
{
class Book
{
private:
csv::Row *mptr_info = nullptr;
csv::CSVParser *mptr_parser = nullptr;

size_t increase_rented();
public:
Book() = delete;
Book(csv::Row *);
Book(csv::Row *, csv::CSVParser *);
~Book();

bool is_available();
std::string_view get_BID();
csv::Row& get_Row();
};
void init(csv::Row *);

size_t increase_rented();

bool is_available();
std::string_view get_BID();
csv::Row &get_Row();
};

}
Loading