Top100
Your Personal Movie List (C++17 CLI + library)
Loading...
Searching...
No Matches
top100.h
1// SPDX-License-Identifier: Apache-2.0
2//-------------------------------------------------------------------------------
3// Top100 — Your Personal Movie List
4//
5// File: lib/top100.h
6// Purpose: Declarations for Top100 container and operations.
7// Language: C++17 (header)
8//
9// Author: Andy McCall, mailme@andymccall.co.uk
10// Date: September 18, 2025
11//-------------------------------------------------------------------------------
12#pragma once
13
14#include <vector>
15#include <string>
16#include "Movie.h"
17
24// Enum to define the sort order
25enum class SortOrder {
26 DEFAULT,
27 BY_YEAR,
28 ALPHABETICAL,
29 BY_USER_RANK, // 1..N ascending (unranked last)
30 BY_USER_SCORE // high to low
31};
32
41class Top100 {
42public:
43 Top100(const std::string& filename);
44 ~Top100();
45
47 void addMovie(const Movie& movie);
49 void removeMovie(const std::string& title);
51 bool removeByImdbId(const std::string& imdbID);
53 std::vector<Movie> getMovies(SortOrder order = SortOrder::DEFAULT) const;
54
55 // Duplicate handling helpers
57 int findIndexByImdbId(const std::string& imdbID) const; // returns index or -1
59 int findIndexByTitleYear(const std::string& title, int year) const; // returns index or -1
61 void replaceMovie(size_t index, const Movie& movie);
62 // Direct update access for ranking adjustments (bounds-checked)
64 bool updateMovie(size_t index, const Movie& movie);
65
72 bool mergeFromOmdbByImdbId(const Movie& omdbMovie);
73
74 // Recompute 1-based userRank from userScore (descending). Unranked (-1) if list empty.
76 void recomputeRanks();
77
78private:
79 void load();
80 void save();
81
82 std::string filename;
83 std::vector<Movie> movies;
84};
Persistent container for up to 100 movies, with ranking.
Definition top100.h:41
std::vector< Movie > getMovies(SortOrder order=SortOrder::DEFAULT) const
Return a copy of movies in the requested sort order.
Definition top100.cpp:44
bool updateMovie(size_t index, const Movie &movie)
Update movie at index; returns false if index invalid.
Definition top100.cpp:126
int findIndexByTitleYear(const std::string &title, int year) const
Definition top100.cpp:113
void removeMovie(const std::string &title)
Remove by title (first match). No-op if not found.
Definition top100.cpp:30
void replaceMovie(size_t index, const Movie &movie)
Replace movie at index (bounds-checked internally).
Definition top100.cpp:120
void addMovie(const Movie &movie)
Add a movie; replaces existing title+year duplicates.
Definition top100.cpp:26
bool mergeFromOmdbByImdbId(const Movie &omdbMovie)
Merge updated metadata into an existing movie by IMDb ID. Copies all metadata fields from the provide...
Definition top100.cpp:149
int findIndexByImdbId(const std::string &imdbID) const
Definition top100.cpp:105
void recomputeRanks()
Recompute 1-based userRank from userScore descending.
Definition top100.cpp:132
bool removeByImdbId(const std::string &imdbID)
Remove by IMDb ID (preferred precise delete).
Definition top100.cpp:36
SortOrder
Sort orders for listing movies.
Definition top100.h:25
Movie domain model and metadata.
Definition Movie.h:27