Use linked list with push front for logs

This commit is contained in:
realaltffour 2020-04-14 17:42:21 +03:00
parent 3a0d35da65
commit aa4d661f66
No known key found for this signature in database
GPG Key ID: 7115CD2AC9A76A56
4 changed files with 6 additions and 4 deletions

View File

@ -2,6 +2,7 @@
#define DATA_H
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
@ -50,7 +51,7 @@ struct Entry {
};
struct Log {
std::vector<Entry>* entries = nullptr;
std::list<Entry>* entries = nullptr;
};
/////////////// EVENT END OF HISTORY SYSTEM STRUCTURES /////////////

View File

@ -26,8 +26,8 @@ void logEntry(const std::string& msg, EntryType type) {
ev.creationDate.year = currentTime->tm_year + 1900;
if (!s_log.entries)
s_log.entries = new std::vector<Entry>();
s_log.entries->push_back(ev);
s_log.entries = new std::list<Entry>();
s_log.entries->push_front(ev);
}
void writeLog(const std::string& loc, bool append) {

View File

@ -18,7 +18,7 @@ void init_create(init_args arg) {
// Mandatory stuff to stop segmantion fault due to
// pointers unintialized.
db.projects = new std::map<std::string, Project>();
db.log.entries = new std::vector<Entry>();
db.log.entries = new std::list<Entry>();
logEntry("Creating database.", EntryType::Creation);
writeDB(db, ".db");

View File

@ -4,6 +4,7 @@
#include <time.h>
#include <ctime>
#include <iostream>
#include <list>
#include <vector>
#include "../data.h"