Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #54 from jvdcf/Documentation
Browse files Browse the repository at this point in the history
Final documentation and cleanup
  • Loading branch information
guilherme-ds-matos authored Nov 4, 2023
2 parents c273543 + 60ea61f commit d0f4483
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 150 deletions.
10 changes: 10 additions & 0 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ make
- Working directory: `~/AED2324_PRJ1_G23`
3. Run the configuration.


------


# Usage
The _SchedulEd_ interface offers the following options:

Expand Down Expand Up @@ -95,3 +97,11 @@ Some requests may be accepted, rejected or cause conflicts, depending on the cur
| Exits the program safely. The user is prompted to save or not the database before exiting.
- `help`
| Prints a list of all available commands in the terminal.


---

# Notes
- Unfortunately, the maximum capacity of a class is hard coded to 30 students.
- The terminal embedded in CLion can behave a bit differently than the system's terminal.
If possible, use the system's terminal to run the program.
8 changes: 5 additions & 3 deletions src/CSVClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>


/**
* @brief This constructor receives a string containing all the lines of a csv file and creates the AppClass from it.
* Theoretical Complexity: O(n), n being the number of characters in a csv line.
* Theoretical Complexity: O(n), n being the number of lines of the csv file.
* @param csv
*/
CSVClasses::CSVClasses(const std::string& csv) {
Expand Down Expand Up @@ -42,6 +40,10 @@ CSVClasses::CSVClasses(const std::string& csv) {
}
}

/**
* @brief Default constructor.
* @details Creates an empty class. Avoid using this constructor when possible.
*/
CSVClasses::CSVClasses() {
this->entries = {};
}
Expand Down
5 changes: 1 addition & 4 deletions src/CSVClassesPerUC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
/**
* @brief This constructor receives a string containing all the lines of a csv
* file and creates the AppClassPerUC from it.
* @details The cap parameter is the capacity of each class (30 by default).
* Theoretical complexity: O(n), where n is the number of lines in the csv file.
* @details Theoretical complexity: O(n), where n is the number of lines in the csv file.
* @param csv
* @param cap
*/
CSVClassPerUC::CSVClassPerUC(const std::string &csv) {

// CSV file into memory
std::ifstream file = std::ifstream(csv);
std::string contents;
Expand Down
1 change: 0 additions & 1 deletion src/CSVClassesPerUC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class CSVClassPerUC {
void display();
void sort();
std::vector<ClassPerUC>* get_classes();
uint8_t get_cap() const;
};


Expand Down
21 changes: 20 additions & 1 deletion src/CSVStudentsClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <vector>

/**
* This constructor receives a string containing all the lines of a csv file and
* @brief This constructor receives a string containing all the lines of a csv file and
* creates the AppSudentClass from it.
* @details Theoretical Complexity: O(n), n being the number of lines of the csv file.
* @param csv
*/
CSVStudentsClasses::CSVStudentsClasses(const std::string &csv) {
Expand Down Expand Up @@ -45,6 +46,10 @@ CSVStudentsClasses::CSVStudentsClasses(const std::string &csv) {
}
}

/**
* @brief Default constructor.
* @details Creates an empty class. Avoid using this constructor when possible.
*/
CSVStudentsClasses::CSVStudentsClasses() { this->entries = {}; }

/**
Expand All @@ -70,16 +75,30 @@ std::vector<StudentsClasses> *CSVStudentsClasses::get_students() {
return &this->entries;
}

/**
* @brief Setter for the vector of StudentsClasses.
* @details Useful to later save into a file.
* @param entries
*/
void CSVStudentsClasses::set_students(
const std::vector<StudentsClasses> &entries) {
this->entries = entries;
}

/**
* @brief Saves the contents of the class into a file.
* @details Theoretical Complexity: O(n), n being the number of lines of the csv file.
*/
void CSVStudentsClasses::write_to_file() {
std::ofstream ofs(this->filename);
ofs << this->display();
}

/**
* @brief Setter for the filename.
* @details Indicates where the class will now be saved.
* @param name
*/
void CSVStudentsClasses::set_filename(const std::string& name) {
this->filename = name;
}
Expand Down
9 changes: 0 additions & 9 deletions src/CSVStudentsClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,13 @@ class CSVStudentsClasses {
std::string filename;

public:
// Constructor
CSVStudentsClasses(const std::string &csv);
CSVStudentsClasses();

// Getter
std::vector<StudentsClasses> *get_students();

// Setter
void set_students(const std::vector<StudentsClasses> &entries);

// Methods
void sort();
void write_to_file();
void set_filename(const std::string& name);

// Contents
std::string display() const;
};

Expand Down
45 changes: 19 additions & 26 deletions src/ClassSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file ClassSchedule.cpp
*/
#include "ClassSchedule.hpp"
#include <cstdint>
#include <cstdio>
#include <sstream>
#include <vector>
Expand All @@ -20,20 +19,24 @@ ClassSchedule::ClassSchedule(uint16_t uc_code, uint16_t class_code) {
this->students = {};
}


/**
* @brief Add one student to the list.
* @details Theoretical complexity: O(n log n), where n is the number of students in the vector.
* @param student_code
*/
void ClassSchedule::add_student(uint32_t s) {
students.push_back(s);
void ClassSchedule::add_student(uint32_t student_code) {
students.push_back(student_code);
std::sort(this->students.begin(), this->students.end());
}

/**
* @brief Remove one student from the list.
* @details Theoretical complexity: O(n), where n is the number of students in the vector.
* @param student_code
*/
void ClassSchedule::remove_student(uint32_t s) {
void ClassSchedule::remove_student(uint32_t student_code) {
for (auto itr = students.begin(); itr != students.end(); ++itr) {
if (*itr == s) {
if (*itr == student_code) {
students.erase(itr);
break;
}
Expand All @@ -54,23 +57,6 @@ bool ClassSchedule::add_entry(Lesson* c) {
return true;
}

/**
* @deprecated
* @brief Remove a Lesson to the vector of this class.
* @param c
* @return bool (If the action is valid or not.)
*/
bool ClassSchedule::remove_entry(Lesson* c) {
// Probably unecessary
for (std::vector<Lesson*>::iterator itr = this->classes.begin(); itr != this->classes.end(); ++itr) {
if (*itr == c) {
this->classes.erase(itr);
return true;
}
}
return false;
}

/**
* @brief Getter for student_count.
* @return student_count
Expand All @@ -80,17 +66,25 @@ uint64_t ClassSchedule::get_student_count() const {
}

/**
* @brief Getter for class_schedule.
* @return class_schedule
* @brief Getter for classes vector.
* @return classes
*/
const std::vector<Lesson*> & ClassSchedule::get_class_schedule() {
return this->classes;
}

/**
* @brief Getter for students vector.
* @return students
*/
const std::vector<uint32_t>& ClassSchedule::get_students_enrolled() {
return this->students;
}

/**
* @brief Sort all of the lesson pointers inside of the vector classes.
* @details Theoretical complexity: O(n log n), where n is the number of lessons in the vector.
*/
void ClassSchedule::sort() {
std::sort(this->classes.begin(), this->classes.end(), [](Lesson *a, Lesson *b) {
if (a->get_day() == b->get_day()) {
Expand Down Expand Up @@ -121,4 +115,3 @@ std::string ClassSchedule::display() const {
s << std::endl;
return s.str();
}

4 changes: 1 addition & 3 deletions src/ClassSchedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define CLASSSCHEDULE_H
#include <cstdint>
#include <vector>
#include <string>
#include "ClassesPerUC.hpp"
#include "Lesson.hpp"

Expand All @@ -22,15 +23,12 @@ class ClassSchedule : public ClassPerUC {
public:
ClassSchedule(uint16_t uc_code, uint16_t class_code);
bool add_entry(Lesson* entry);
bool remove_entry(Lesson* entry);
void add_student(uint32_t s);
void remove_student(uint32_t s);
uint64_t get_student_count() const;
const std::vector<uint32_t>& get_students_enrolled();
const std::vector<Lesson*> & get_class_schedule();

void sort();

std::string display() const;
};

Expand Down
4 changes: 0 additions & 4 deletions src/ClassesPerUC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
*/
#include "ClassesPerUC.hpp"
#include "Utils.hpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

Expand Down
1 change: 0 additions & 1 deletion src/Lesson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
#include "Lesson.hpp"
#include "Utils.hpp"
#include <iomanip>
#include <sstream>
using namespace std;

Expand Down
19 changes: 4 additions & 15 deletions src/Lesson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


/**
* Since it is quicker to compare numbers instead of strings and there are only 7 days in a week, we decided to store
* @brief The days of the week stored in a single byte.
* @details Since it is quicker to compare numbers instead of strings and there are only 7 days in a week, we decided to store
* the days as objects of this class.
* This allows us to store the string value of the week day into a single byte.
*/
Expand All @@ -27,7 +28,8 @@ enum class WeekDay {
};

/**
* Since it is quicker to compare numbers instead of strings and there are only 3 types of classes, we decided to store
* @brief The types of classes stored in a single byte.
* @details Since it is quicker to compare numbers instead of strings and there are only 3 types of classes, we decided to store
* the types as objects of this class.
* This allows us to store the string value of the class type into a single byte.
*/
Expand All @@ -53,27 +55,14 @@ class Lesson : public ClassPerUC {

public:
Lesson(std::string line); // Constructor

// Getters:
WeekDay get_day() const;

double get_start_hour() const;

double get_duration() const;

Type get_type() const;

// Parsers:
WeekDay parse_day(std::string day);

Type parse_type(std::string type);

// To String:
void day_to_str(std::string &out) const;

void type_to_str(std::string &out) const;

// Other Methods:
std::string display() const override;
};

Expand Down
12 changes: 6 additions & 6 deletions src/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @brief Constructs a request of a certain type.
* This request is not yet completed, as the operands are still to be added.
* @details This request is not yet completed, as the operands are still to be added.
* Theoretical Complexity: O(1).
* @param t
*/
Expand All @@ -15,7 +15,7 @@ Process::Process(TypeOfRequest t) {

/**
* @brief Adds a string to the operands vector
* Theoretical Complexity: O(1).
* @details Theoretical Complexity: O(1).
* @param op
*/
void Process::add_operand(std::string op) {
Expand All @@ -24,17 +24,17 @@ void Process::add_operand(std::string op) {

/**
* @brief Accesses the type of request.
* Theoretical Complexity: O(1).
* @return
* @details Theoretical Complexity: O(1).
* @return TypeOfRequest
*/
TypeOfRequest Process::get_type() {
return type;
}

/**
* @brief Accesses the vector of operands.
* Theoretical Complexity: O(1).
* @return
* @details Theoretical Complexity: O(1).
* @return Pointer to the vector of operands.
*/
std::vector<std::string>& Process::get_ops() {
return operands;
Expand Down
Loading

0 comments on commit d0f4483

Please sign in to comment.