Updating gitignore

This commit is contained in:
Christopher Sanden
2025-10-23 16:41:45 +02:00
parent 1271906bcb
commit 08a6b25df7
9 changed files with 3 additions and 302 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
*.zip
*.ZIP
*.Zip
*.clang-format
*cmake-build-debug
*.idea

View File

@@ -1,12 +0,0 @@
cmake_minimum_required(VERSION 4.0)
project(assignment1)
set(CMAKE_CXX_STANDARD 20)
add_executable(assignment1 main.cpp
TMovie.h
TMovie.cpp
TMovieList.cpp
TMovieList.h
TMovieNode.cpp
TMovieNode.h)

View File

@@ -1,5 +0,0 @@
//
// Created by csand on 13/10/2025.
//
#include "TMovie.h"

View File

@@ -1,59 +0,0 @@
#ifndef IKT203_TMOVIE_H
#define IKT203_TMOVIE_H
#include <string>
#include <utility>
enum EMovieGenreType{
ACTION = 1 << 0,
COMEDY = 1<< 1,
SCIFI = 1 << 2,
HORROR = 1 << 3,
DRAMA = 1 << 4
};
class TMovie
{
private:
std::string title;
std::string director;
int year;
EMovieGenreType genre;
float score;
public:
TMovie(std::string T, std::string D, int Y, EMovieGenreType G, float S) :
title(std::move(T)), director(std::move(D)), year(Y), genre(G), score(S) {}
// Simple getters - using [[nodiscard]] to give warning if value is not used
[[nodiscard]] std::string GetTitle() const
{
return title;
}
[[nodiscard]] std::string GetDirector() const
{
return director;
}
[[nodiscard]] int GetYear() const
{
return year;
}
[[nodiscard]] EMovieGenreType GetGenre() const
{
return genre;
}
[[nodiscard]] float GetScore() const
{
return score;
}
// Not declaring a destructor since the default compiler destructor is
};
#endif //IKT203_TMOVIE_H

View File

@@ -1,95 +0,0 @@
#include "TMovieList.h"
#include <iostream>
using namespace std;
void TMovieList::Append(TMovie* m)
{
// Time complexity O(1) with using tail and prev nodes
auto* newNode = new TMovieNode(m);
newNode->SetPrevNode(tail);
tail->SetNextNode(newNode);
tail = newNode;
cout << "Appended '" << m->GetTitle() << "' into existing list of movies" <<endl;
}
void TMovieList::Prepend(TMovie* m)
{
auto* newNode = new TMovieNode(m);
auto* old = head->GetNextNode();
newNode->SetNextNode(head->GetNextNode());
head->SetNextNode(newNode);
newNode->SetPrevNode(head);
if (old)
old->SetPrevNode(newNode);
cout << "Prepended '" << m->GetTitle() << "' into list of movies" <<endl;
if (tail == head)
tail = newNode;
}
TMovieNode* TMovieList::NavigateToNode(const int index) const
{
// Negativ index finnes ikke -> ugyldig
if (index < 0)
return nullptr;
auto* node = head->GetNextNode();
int i = 0;
while (node != nullptr && i < index)
{
node = node->GetNextNode();
i++;
}
// Index større enn lista -> ugyldig
if (node == nullptr)
return nullptr;
return node;
}
TMovie* TMovieList::GetAtIndex(const int index) const
{
auto* node = NavigateToNode(index);
return node ? node->GetMovie() : nullptr;
}
void TMovieList::Remove(const int index)
{
auto* node = NavigateToNode(index);
if (node == nullptr)
return;
auto* prev = node->GetPrevNode();
auto* next = node->GetNextNode();
if (prev)
prev->SetNextNode(next);
if (next)
next->SetPrevNode(prev);
else
tail = (prev ? prev : head);
if (head->GetNextNode() == nullptr)
tail = head;
delete node;
}
TMovie *TMovieList::SearchFor(const FCheckMovie check_movie, void *criteria) const
{
auto* node = head->GetNextNode();
while (node != nullptr)
{
if (check_movie(node->GetMovie(), criteria))
{
return node->GetMovie();
}
node = node->GetNextNode();
}
return nullptr;
}

View File

@@ -1,41 +0,0 @@
#ifndef IKT203_TMOVIELIST_H
#define IKT203_TMOVIELIST_H
#include "TMovie.h"
#include "TMovieNode.h"
// typedef to increase flexibility and reduce code recycling
typedef bool (*FCheckMovie)(TMovie* movie, void* criteria);
class TMovieList {
private:
TMovieNode* head;
TMovieNode* tail;
public:
TMovieList() : head(new TMovieNode(nullptr)), tail(head) {}
~TMovieList()
{
TMovieNode* current = head;
while(current)
{
TMovieNode* next = current->GetNextNode();
delete current;
current = next;
}
head = nullptr;
tail = nullptr;
}
void Append(TMovie* m);
void Prepend(TMovie* m);
TMovie* SearchFor(FCheckMovie check_movie, void* criteria) const;
[[nodiscard]] TMovieNode *NavigateToNode(int index) const;
[[nodiscard]] TMovie* GetAtIndex(int index) const;
void Remove(int index);
};
#endif //IKT203_TMOVIELIST_H

View File

@@ -1,6 +0,0 @@
//
// Created by csand on 13/10/2025.
//
#include "TMovieNode.h"

View File

@@ -1,52 +0,0 @@
#ifndef IKT203_TMOVIENODE_H
#define IKT203_TMOVIENODE_H
#include "TMovie.h"
class TMovieNode {
private:
TMovie* movie;
TMovieNode* nextNode;
TMovieNode* prevNode;
public:
// constructor
explicit TMovieNode(TMovie* moviePointer) : movie(moviePointer), nextNode(nullptr), prevNode(nullptr) {}
// destructor
~TMovieNode()
{
delete movie;
movie = nullptr;
}
// getters and setters for next and previous nodes
[[nodiscard]] TMovieNode* GetNextNode() const
{
return nextNode;
}
void SetNextNode(TMovieNode* next)
{
nextNode = next;
}
[[nodiscard]] TMovieNode* GetPrevNode() const
{
return prevNode;
}
void SetPrevNode(TMovieNode* prev)
{
prevNode = prev;
}
[[nodiscard]] TMovie* GetMovie() const
{
return movie;
}
};
#endif //IKT203_TMOVIENODE_H

View File

@@ -1,32 +0,0 @@
#include <iostream>
#include "TMovieList.h"
// specialised versions of SearchFor() from TMovieList
bool SearchByTitle(const TMovie* m, void* c)
{
const auto* title = static_cast<std::string*>(c);
return m->GetTitle() == *title;
}
bool SearchByDirector(const TMovie* m, void* criteria)
{
const auto* director = static_cast<std::string*>(criteria);
return m->GetDirector() == *director;
}
bool SearchByGenre(const TMovie* m, void* criteria)
{
const auto* genre = static_cast<EMovieGenreType*>(criteria);
return m->GetGenre() == *genre;
}
int main()
{
}