School Commit Init
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Playlist", "Playlist\Playlist.vcxproj", "{7E0162AB-8678-4BD6-B928-6A2486926936}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Debug|x64.Build.0 = Debug|x64
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Debug|x86.Build.0 = Debug|Win32
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Release|x64.ActiveCfg = Release|x64
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Release|x64.Build.0 = Release|x64
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Release|x86.ActiveCfg = Release|Win32
|
||||
{7E0162AB-8678-4BD6-B928-6A2486926936}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
#include "Repository.h"
|
||||
#include "Song.h"
|
||||
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
virtual ~Action() = default;
|
||||
virtual void executeUndo() = 0;
|
||||
virtual void executeRedo() = 0;
|
||||
};
|
||||
|
||||
class AddAction : public Action
|
||||
{
|
||||
private:
|
||||
Repository& repo;
|
||||
Song addedSong;
|
||||
public:
|
||||
AddAction(Repository& repo, const Song& addedSong) : repo{ repo }, addedSong{ addedSong } {}
|
||||
void executeUndo() override
|
||||
{
|
||||
this->repo.removeSong(addedSong);
|
||||
}
|
||||
void executeRedo() override
|
||||
{
|
||||
this->repo.addSong(addedSong);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class RemoveAction : public Action
|
||||
{
|
||||
private:
|
||||
Repository& repo;
|
||||
Song removedSong;
|
||||
public:
|
||||
RemoveAction(Repository& repo, const Song& removedSong) : repo{ repo }, removedSong{ removedSong } {}
|
||||
void executeUndo() override
|
||||
{
|
||||
this->repo.addSong(removedSong);
|
||||
}
|
||||
void executeRedo() override
|
||||
{
|
||||
this->repo.removeSong(removedSong);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// class UpdateAction : public Action
|
||||
// {
|
||||
// private:
|
||||
// Repository& repo;
|
||||
// Song updatedSong;
|
||||
// Song oldSong;
|
||||
// public:
|
||||
// UpdateAction(Repository& repo, const Song& updatedSong, const Song& oldSong) : repo{ repo }, updatedSong{ updatedSong }, oldSong{ oldSong } {}
|
||||
// void executeUndo() override
|
||||
// {
|
||||
// this->repo.updateSong(updatedSong, oldSong);
|
||||
// }
|
||||
// void executeRedo() override
|
||||
// {
|
||||
// this->repo.updateSong(oldSong, updatedSong);
|
||||
// }
|
||||
|
||||
// };
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#include "CSVPlaylist.h"
|
||||
#include <fstream>
|
||||
// #include <Windows.h>
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CSVPlaylist::writeToFile()
|
||||
{
|
||||
ofstream f(this->filename);
|
||||
|
||||
if (!f.is_open())
|
||||
throw FileException("The file could not be opened!");
|
||||
|
||||
for (auto s : this->songs)
|
||||
f << s;
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
void CSVPlaylist::displayPlaylist() const
|
||||
{
|
||||
string aux = "\"" + this->filename + "\""; // if the path contains spaces, we must put it inside quotations
|
||||
//ShellExecuteA(NULL, NULL, "C:\\Program Files (x86)\\OpenOffice 4\\program\\scalc.exe", aux.c_str(), NULL, SW_SHOWMAXIMIZED);
|
||||
// ShellExecuteA(NULL, NULL, "c:\\Program Files\\Microsoft Office\\Office15\\EXCEL.EXE", aux.c_str(), NULL, SW_SHOWMAXIMIZED);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "FilePlaylist.h"
|
||||
#include <string>
|
||||
|
||||
class CSVPlaylist: public FilePlaylist
|
||||
{
|
||||
public:
|
||||
/*
|
||||
Writes the playlist to file.
|
||||
Throws: FileException - if it cannot write.
|
||||
*/
|
||||
void writeToFile() override;
|
||||
|
||||
/*
|
||||
Displays the playlist using Microsof Excel.
|
||||
*/
|
||||
void displayPlaylist() const override;
|
||||
};
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#include "FilePlaylist.h"
|
||||
|
||||
|
||||
|
||||
FilePlaylist::FilePlaylist() : PlayList{}, filename{""}
|
||||
{
|
||||
}
|
||||
|
||||
void FilePlaylist::setFilename(const std::string& filename)
|
||||
{
|
||||
this->filename = filename;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "PlayList.h"
|
||||
|
||||
class FilePlaylist : public PlayList
|
||||
{
|
||||
protected:
|
||||
std::string filename;
|
||||
|
||||
public:
|
||||
FilePlaylist();
|
||||
virtual ~FilePlaylist() {}
|
||||
|
||||
void setFilename(const std::string& filename);
|
||||
virtual void writeToFile() = 0;
|
||||
virtual void displayPlaylist() const = 0;
|
||||
};
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#include "PlayList.h"
|
||||
|
||||
|
||||
PlayList::PlayList()
|
||||
{
|
||||
this->current = 0;
|
||||
}
|
||||
|
||||
void PlayList::add(const Song& song)
|
||||
{
|
||||
this->songs.push_back(song);
|
||||
}
|
||||
|
||||
Song PlayList::getCurrentSong()
|
||||
{
|
||||
if (this->current == this->songs.size())
|
||||
this->current = 0;
|
||||
return this->songs[this->current];
|
||||
return Song{};
|
||||
}
|
||||
|
||||
void PlayList::play()
|
||||
{
|
||||
if (this->songs.size() == 0)
|
||||
return;
|
||||
this->current = 0;
|
||||
Song currentSong = this->getCurrentSong();
|
||||
currentSong.play();
|
||||
}
|
||||
|
||||
void PlayList::next()
|
||||
{
|
||||
if (this->songs.size() == 0)
|
||||
return;
|
||||
this->current++;
|
||||
Song currentSong = this->getCurrentSong();
|
||||
currentSong.play();
|
||||
}
|
||||
|
||||
bool PlayList::isEmpty()
|
||||
{
|
||||
return this->songs.size() == 0;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Song.h"
|
||||
|
||||
class PlayList
|
||||
{
|
||||
protected:
|
||||
std::vector<Song> songs;
|
||||
int current;
|
||||
|
||||
public:
|
||||
PlayList();
|
||||
|
||||
// Adds a song to the playlist.
|
||||
void add(const Song& song);
|
||||
|
||||
// Returns the song that is currently playing.
|
||||
Song getCurrentSong();
|
||||
|
||||
// Starts the playlist - plays the first song.
|
||||
void play();
|
||||
|
||||
// Plays the next song in the playlist.
|
||||
void next();
|
||||
|
||||
// Checks if the playlist is empty.
|
||||
bool isEmpty();
|
||||
|
||||
virtual ~PlayList() {}
|
||||
};
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7E0162AB-8678-4BD6-B928-6A2486926936}</ProjectGuid>
|
||||
<RootNamespace>Playlist</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Service.h" />
|
||||
<ClInclude Include="CSVPlaylist.h" />
|
||||
<ClInclude Include="FilePlaylist.h" />
|
||||
<ClInclude Include="PlayList.h" />
|
||||
<ClInclude Include="Repository.h" />
|
||||
<ClInclude Include="RepositoryExceptions.h" />
|
||||
<ClInclude Include="Song.h" />
|
||||
<ClInclude Include="SongValidator.h" />
|
||||
<ClInclude Include="UI.h" />
|
||||
<ClInclude Include="Utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Service.cpp" />
|
||||
<ClCompile Include="CSVPlaylist.cpp" />
|
||||
<ClCompile Include="FilePlaylist.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="PlayList.cpp" />
|
||||
<ClCompile Include="Repository.cpp" />
|
||||
<ClCompile Include="RepositoryExceptions.cpp" />
|
||||
<ClCompile Include="Song.cpp" />
|
||||
<ClCompile Include="SongValidator.cpp" />
|
||||
<ClCompile Include="UI.cpp" />
|
||||
<ClCompile Include="Utils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="Songs.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Song.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Repository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PlayList.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="UI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CSVPlaylist.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FilePlaylist.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SongValidator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RepositoryExceptions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Service.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Song.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Repository.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PlayList.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Utils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CSVPlaylist.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FilePlaylist.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SongValidator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RepositoryExceptions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Service.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="Songs.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#include "Repository.h"
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "Utils.h"
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Repository::Repository(const std::string& filename)
|
||||
{
|
||||
this->filename = filename;
|
||||
this->readFromFile();
|
||||
}
|
||||
|
||||
void Repository::addSong(const Song& s)
|
||||
{
|
||||
Song s1{};
|
||||
try
|
||||
{
|
||||
s1 = this->findByArtistAndTitle(s.getArtist(), s.getTitle());
|
||||
throw DuplicateSongException();
|
||||
}
|
||||
catch (InexistenSongException&) {}
|
||||
this->songs.push_back(s);
|
||||
this->writeToFile();
|
||||
}
|
||||
|
||||
void Repository::removeSong(const Song& s)
|
||||
{
|
||||
auto it = find(this->songs.begin(), this->songs.end(), s);
|
||||
if (it == this->songs.end())
|
||||
throw InexistenSongException{};
|
||||
this->songs.erase(it);
|
||||
this->writeToFile();
|
||||
}
|
||||
|
||||
Song Repository::findByArtistAndTitle(const std::string& artist, const std::string& title) const
|
||||
{
|
||||
for (auto s: this->songs)
|
||||
{
|
||||
if (s.getArtist() == artist && s.getTitle() == title)
|
||||
return s;
|
||||
}
|
||||
|
||||
throw InexistenSongException{};
|
||||
}
|
||||
|
||||
void Repository::readFromFile()
|
||||
{
|
||||
ifstream file(this->filename);
|
||||
|
||||
if (!file.is_open())
|
||||
throw FileException("The file could not be opened!");
|
||||
|
||||
Song s;
|
||||
while (file >> s)
|
||||
this->songs.push_back(s);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void Repository::writeToFile()
|
||||
{
|
||||
ofstream file(this->filename);
|
||||
if (!file.is_open())
|
||||
throw FileException("The file could not be opened!");
|
||||
|
||||
for (auto s : this->songs)
|
||||
{
|
||||
file << s;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "Song.h"
|
||||
#include <vector>
|
||||
|
||||
class Repository
|
||||
{
|
||||
private:
|
||||
std::vector<Song> songs;
|
||||
std::string filename;
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor with parameters.
|
||||
Initializes an object of type repository, by reading data from the given file.
|
||||
Throws: FileException - if the file cannot be opened.
|
||||
*/
|
||||
Repository(const std::string& filename);
|
||||
|
||||
/*
|
||||
Adds a song to the repository.
|
||||
Input: s - Song.
|
||||
Output: the song is added to the repository.
|
||||
Throws: FileException - if the file cannot be opened.
|
||||
DuplicateSongException - if there is another song with the same artist and title.
|
||||
*/
|
||||
void addSong(const Song& s);
|
||||
|
||||
/*
|
||||
Removes the song with the given artist and title.
|
||||
Throws: InexistenSongException - if there are no songs with the given artist and title.
|
||||
*/
|
||||
void removeSong(const Song& s);
|
||||
|
||||
/*
|
||||
Finds a song, by artist and title.
|
||||
Input: artist, title - string
|
||||
Output: the song that was found, or an "empty" song (all fields empty and duration 0), if nothing was found.
|
||||
*/
|
||||
|
||||
void updateSong(const Song& oldSong, const Song& newSong);
|
||||
|
||||
Song findByArtistAndTitle(const std::string& artist, const std::string& title) const;
|
||||
|
||||
std::vector<Song> getSongs() const { return songs; }
|
||||
|
||||
private:
|
||||
void readFromFile();
|
||||
void writeToFile();
|
||||
};
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
FileException::FileException(const std::string & msg) : message(msg)
|
||||
{
|
||||
}
|
||||
|
||||
const char * FileException::what()
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
|
||||
RepositoryException::RepositoryException() : exception{}, message{""}
|
||||
{
|
||||
}
|
||||
|
||||
RepositoryException::RepositoryException(const std::string & msg): message{msg}
|
||||
{
|
||||
}
|
||||
|
||||
const char * RepositoryException::what()
|
||||
{
|
||||
return this->message.c_str();
|
||||
}
|
||||
|
||||
const char * DuplicateSongException::what()
|
||||
{
|
||||
return "There is another song with the same artist and title!";
|
||||
}
|
||||
|
||||
const char * InexistenSongException::what()
|
||||
{
|
||||
return "There are no songs with the given artist and title!";
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
class FileException : public std::exception
|
||||
{
|
||||
protected:
|
||||
std::string message;
|
||||
|
||||
public:
|
||||
FileException(const std::string& msg);
|
||||
virtual const char* what();
|
||||
};
|
||||
|
||||
class RepositoryException : public std::exception
|
||||
{
|
||||
protected:
|
||||
std::string message;
|
||||
|
||||
public:
|
||||
RepositoryException();
|
||||
RepositoryException(const std::string& msg);
|
||||
virtual ~RepositoryException() {}
|
||||
virtual const char* what();
|
||||
};
|
||||
|
||||
class DuplicateSongException : public RepositoryException
|
||||
{
|
||||
public:
|
||||
const char* what();
|
||||
};
|
||||
|
||||
class InexistenSongException : public RepositoryException
|
||||
{
|
||||
public:
|
||||
const char* what();
|
||||
};
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#include "Service.h"
|
||||
#include <algorithm>
|
||||
#include "FilePlaylist.h"
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Service::addSongToRepository(const std::string& artist, const std::string& title, double minutes, double seconds, const std::string& source)
|
||||
{
|
||||
Song s{ artist, title, Duration{ minutes, seconds }, source };
|
||||
this->validator.validate(s);
|
||||
this->repo.addSong(s);
|
||||
|
||||
undoActions.push_back(std::make_unique<AddAction>(this->repo, s));
|
||||
redoActions.clear();
|
||||
|
||||
}
|
||||
|
||||
void Service::removeSongFromRepository(const std::string & artist, const std::string & title)
|
||||
{
|
||||
Song s = this->repo.findByArtistAndTitle(artist, title);
|
||||
this->repo.removeSong(s);
|
||||
|
||||
undoActions.push_back(std::make_unique<RemoveAction>(this->repo, s));
|
||||
redoActions.clear();
|
||||
}
|
||||
|
||||
void Service::addSongToPlaylist(const Song& song)
|
||||
{
|
||||
if (this->playList == nullptr)
|
||||
return;
|
||||
this->playList->add(song);
|
||||
}
|
||||
|
||||
void Service::addAllSongsByArtistToPlaylist(const std::string& artist)
|
||||
{
|
||||
vector<Song> songs = this->repo.getSongs();
|
||||
int nSongs = static_cast<int>(count_if(songs.begin(), songs.end(),
|
||||
[artist](const Song& s)
|
||||
{
|
||||
return s.getArtist() == artist;
|
||||
}));
|
||||
|
||||
vector<Song> songsByArtist(nSongs);
|
||||
copy_if(songs.begin(), songs.end(), songsByArtist.begin(),
|
||||
[artist](const Song& s)
|
||||
{
|
||||
return s.getArtist() == artist;
|
||||
});
|
||||
|
||||
for (auto s : songsByArtist)
|
||||
this->playList->add(s);
|
||||
}
|
||||
|
||||
void Service::startPlaylist()
|
||||
{
|
||||
if (this->playList == nullptr)
|
||||
return;
|
||||
this->playList->play();
|
||||
}
|
||||
|
||||
void Service::nextSongPlaylist()
|
||||
{
|
||||
if (this->playList == nullptr)
|
||||
return;
|
||||
this->playList->next();
|
||||
}
|
||||
|
||||
void Service::savePlaylist(const std::string& filename)
|
||||
{
|
||||
if (this->playList == nullptr)
|
||||
return;
|
||||
|
||||
this->playList->setFilename(filename);
|
||||
this->playList->writeToFile();
|
||||
}
|
||||
|
||||
void Service::openPlaylist() const
|
||||
{
|
||||
if (this->playList == nullptr)
|
||||
return;
|
||||
|
||||
this->playList->displayPlaylist();
|
||||
}
|
||||
|
||||
void Service::undo()
|
||||
{
|
||||
if (undoActions.empty())
|
||||
throw RepositoryException("No more undos!\n");
|
||||
undoActions.back()->executeUndo();
|
||||
redoActions.push_back(std::move(undoActions.back()));
|
||||
undoActions.pop_back();
|
||||
}
|
||||
|
||||
void Service::redo()
|
||||
{
|
||||
if (redoActions.empty())
|
||||
throw RepositoryException("No more redos!\n");
|
||||
redoActions.back()->executeRedo();
|
||||
undoActions.push_back(std::move(redoActions.back()));
|
||||
redoActions.pop_back();
|
||||
}
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include "Repository.h"
|
||||
#include "FilePlaylist.h"
|
||||
#include "SongValidator.h"
|
||||
#include <memory>
|
||||
#include "Action.h"
|
||||
|
||||
class Service
|
||||
{
|
||||
private:
|
||||
Repository repo;
|
||||
FilePlaylist* playList;
|
||||
SongValidator validator;
|
||||
std::vector<std::unique_ptr<Action>> undoActions;
|
||||
std::vector<std::unique_ptr<Action>> redoActions;
|
||||
|
||||
public:
|
||||
Service(const Repository& r, FilePlaylist* p, SongValidator v) : repo{ r }, playList{ p }, validator{ v } {}
|
||||
|
||||
Repository getRepo() const { return repo; }
|
||||
PlayList* getPlaylist() const { return playList; }
|
||||
|
||||
/*
|
||||
Adds a song with the given data to the song repository.
|
||||
Throws: SongException - if the song is not valid
|
||||
DuplicateSongException - if there is another song with the same artist and title
|
||||
Throws: FileException - if the repository file cannot be opened.
|
||||
*/
|
||||
void addSongToRepository(const std::string& artist, const std::string& title, double minutes, double seconds, const std::string& source);
|
||||
|
||||
void removeSongFromRepository(const std::string& artist, const std::string& title);
|
||||
|
||||
/*
|
||||
Adds a given song to the current playlist.
|
||||
Input: song - Song, the song must belong to the repository.
|
||||
Output: the song is added to the playlist.
|
||||
*/
|
||||
void addSongToPlaylist(const Song& song);
|
||||
|
||||
// Adds all the songs from the repository, that have the given artist, to the current playlist.
|
||||
void addAllSongsByArtistToPlaylist(const std::string& artist);
|
||||
|
||||
void startPlaylist();
|
||||
void nextSongPlaylist();
|
||||
|
||||
/*
|
||||
Saves the playlist.
|
||||
Throws: FileException - if the given file cannot be opened.
|
||||
*/
|
||||
void savePlaylist(const std::string& filename);
|
||||
|
||||
/*
|
||||
Opens the playlist, with an appropriate application.
|
||||
Throws: FileException - if the given file cannot be opened.
|
||||
*/
|
||||
void openPlaylist() const;
|
||||
|
||||
|
||||
/*
|
||||
Undo the last operation that changed the repository.
|
||||
Throws: RepositoryException - if undo is not possible.
|
||||
*/
|
||||
void undo();
|
||||
|
||||
|
||||
/*
|
||||
Redo the last operation that changed the repository.
|
||||
Throws: RepositoryException - if redo is not possible.
|
||||
*/
|
||||
void redo();
|
||||
};
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#include "Song.h"
|
||||
// #include <Windows.h>
|
||||
// #include <shellapi.h>
|
||||
#include "Utils.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Song::Song(): title(""), artist(""), duration(Duration()), source("") {}
|
||||
|
||||
Song::Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source)
|
||||
{
|
||||
this->artist = artist;
|
||||
this->title = title;
|
||||
this->duration = duration;
|
||||
this->source = source;
|
||||
}
|
||||
|
||||
bool Song::operator==(const Song & s)
|
||||
{
|
||||
return (this->artist == s.artist && this->title == s.title);
|
||||
}
|
||||
|
||||
void Song::play()
|
||||
{
|
||||
// ShellExecuteA(NULL, NULL, "chrome.exe", this->getSource().c_str(), NULL, SW_SHOWMAXIMIZED);
|
||||
}
|
||||
|
||||
istream & operator>>(istream & is, Song & s)
|
||||
{
|
||||
string line;
|
||||
getline(is, line);
|
||||
|
||||
vector<string> tokens = tokenize(line, ',');
|
||||
if (tokens.size() != 4) // make sure all the starship data was valid
|
||||
return is;
|
||||
|
||||
s.artist = tokens[0];
|
||||
s.title = tokens[1];
|
||||
|
||||
// get duration
|
||||
vector<string> durationTokens = tokenize(tokens[2], ':');
|
||||
if (durationTokens.size() != 2)
|
||||
return is;
|
||||
s.duration = Duration{ stod(durationTokens[0]), stod(durationTokens[1]) };
|
||||
|
||||
s.source = tokens[3];
|
||||
|
||||
return is;
|
||||
|
||||
}
|
||||
|
||||
ostream & operator<<(ostream & os, const Song & s)
|
||||
{
|
||||
os << s.artist << "," << s.title << "," << s.duration.getMinutes() << ":" << s.duration.getSeconds() << "," << s.source << "\n";
|
||||
return os;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
|
||||
class Duration
|
||||
{
|
||||
private:
|
||||
double minutes;
|
||||
double seconds;
|
||||
public:
|
||||
Duration() : minutes(0), seconds(0) {}
|
||||
Duration(double min, double sec) : minutes(min), seconds(sec) {}
|
||||
|
||||
double getMinutes() const { return minutes; }
|
||||
double getSeconds() const { return seconds; }
|
||||
void setMinutes(double min) { minutes = min; }
|
||||
void getSeconds(double sec) { seconds = sec; }
|
||||
};
|
||||
|
||||
class Song
|
||||
{
|
||||
private:
|
||||
std::string title;
|
||||
std::string artist;
|
||||
Duration duration;
|
||||
std::string source; // youtube Link
|
||||
|
||||
public:
|
||||
// default constructor for a song
|
||||
Song();
|
||||
|
||||
// constructor with parameters
|
||||
Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source);
|
||||
|
||||
std::string getTitle() const { return title; }
|
||||
std::string getArtist() const { return artist; }
|
||||
Duration getDuration() const { return duration; }
|
||||
std::string getSource() const { return source; }
|
||||
|
||||
bool operator==(const Song& s);
|
||||
|
||||
// Plays the current song: the page corresponding to the source link is opened in a browser.
|
||||
void play();
|
||||
|
||||
friend std::istream& operator>>(std::istream& is, Song& s);
|
||||
friend std::ostream& operator<<(std::ostream& os, const Song& s);
|
||||
};
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#include "SongValidator.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SongException::SongException(std::vector<std::string> _errors): errors{_errors}
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> SongException::getErrors() const
|
||||
{
|
||||
return this->errors;
|
||||
}
|
||||
|
||||
void SongValidator::validate(const Song & s)
|
||||
{
|
||||
vector<string> errors;
|
||||
if (s.getTitle().size() < 3)
|
||||
errors.push_back("The title name cannot be less than 3 characters!\n");
|
||||
if (!isupper(s.getArtist()[0]))
|
||||
errors.push_back(string("The name of the artist must start with a capital letter!\n"));
|
||||
if (s.getDuration().getMinutes() == 0 && s.getDuration().getSeconds() == 0)
|
||||
errors.push_back(string("The duration cannot be 0!\n"));
|
||||
|
||||
// search for "www" or "http" at the beginning of the source string
|
||||
size_t posWww = s.getSource().find("www");
|
||||
size_t posHttp = s.getSource().find("http");
|
||||
if (posWww != 0 && posHttp != 0)
|
||||
errors.push_back("The youtube source must start with one of the following strings: \"www\" or \"http\"");
|
||||
|
||||
if (errors.size() > 0)
|
||||
throw SongException(errors);
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "Song.h"
|
||||
#include <vector>
|
||||
|
||||
class SongException
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> errors;
|
||||
|
||||
public:
|
||||
SongException(std::vector<std::string> _errors);
|
||||
std::vector<std::string> getErrors() const;
|
||||
};
|
||||
|
||||
class SongValidator
|
||||
{
|
||||
public:
|
||||
SongValidator() {}
|
||||
static void validate(const Song& s);
|
||||
};
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
The Proclaimers,I would walk 500 miles,3:37,https://www.youtube.com/watch?v=otXGqU4LBEI
|
||||
Two Steps From Hell,Heart of Courage,8:12,https://www.youtube.com/watch?v=XYKUeZQbMF0
|
||||
Two Steps From Hell,Protectors of the Earth,2:50,https://www.youtube.com/watch?v=ASj81daun5Q
|
||||
John Dreamer,Becoming A Legend,3:36,https://www.youtube.com/watch?v=toPm-L7Ib44
|
||||
Pink Martini,Splendour in the Grass,3:47,https://www.youtube.com/watch?v=6L-_DiZlrUI
|
||||
Pink Martini,Pana cand nu te iubeam,4:40,https://www.youtube.com/watch?v=admIEqRuPf0
|
||||
Two Steps From Hell,Strength of a Thousand Men,6:38,https://www.youtube.com/watch?v=N2RK6OGNMCY&list=PL28C0A27C5F5E5D3A
|
||||
Queen,Bohemian Rhapsody,6:6,https://www.youtube.com/watch?v=fJ9rUzIMcZQ
|
||||
Hozier,Take me to church,4:2,https://www.youtube.com/watch?v=MYSVMgRr6pw&index=30&list=PLb5DqBOB_Gn7CfN91JAl39ZWX4IwqcBBz
|
||||
Pink Floyd,Comfortably numb,6:53,https://www.youtube.com/watch?v=_FrOQC-zEog
|
||||
Qwerty,Qwe,1:1,www.fasfas
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
#include "UI.h"
|
||||
#include <string>
|
||||
#include "SongValidator.h"
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void UI::printMenu()
|
||||
{
|
||||
cout << endl;
|
||||
cout << "1 - Manage song repository."<<endl;
|
||||
cout << "2 - Manage playlist." << endl;
|
||||
cout << "0 - Exit." << endl;
|
||||
}
|
||||
|
||||
void UI::printRepositoryMenu()
|
||||
{
|
||||
cout << "Possible commands: " << endl;
|
||||
cout << "\t 1 - Add song." << endl;
|
||||
cout << "\t 2 - Remove song." << endl;
|
||||
cout << "\t 3 - Display all." << endl;
|
||||
cout << "\t 4 - Undo." << endl;
|
||||
cout << "\t 5 - Redo." << endl;
|
||||
cout << "\t 0 - Back." << endl;
|
||||
}
|
||||
|
||||
void UI::printPlayListMenu()
|
||||
{
|
||||
cout << "Possible commands: " << endl;
|
||||
cout << "\t 1 - Add song." << endl;
|
||||
cout << "\t 2 - Add songs by artist." << endl;
|
||||
cout << "\t 3 - Play." << endl;
|
||||
cout << "\t 4 - Next." << endl;
|
||||
cout << "\t 5 - Save playlist to file." << endl;
|
||||
cout << "\t 6 - Display playlist." << endl;
|
||||
cout << "\t 0 - Back." << endl;
|
||||
}
|
||||
|
||||
void UI::addSongToRepo()
|
||||
{
|
||||
cout << "Enter the artist: ";
|
||||
std::string artist;
|
||||
getline(cin, artist);
|
||||
cout << "Enter the title: ";
|
||||
std::string title;
|
||||
getline(cin, title);
|
||||
double minutes = 0, seconds = 0;
|
||||
cout << "Enter the duration: " << endl;
|
||||
cout << "\tMinutes: ";
|
||||
cin >> minutes;
|
||||
cin.ignore();
|
||||
cout << "\tSeconds: ";
|
||||
cin >> seconds;
|
||||
cin.ignore();
|
||||
cout << "Youtube link: ";
|
||||
std::string link;
|
||||
getline(cin, link);
|
||||
|
||||
try
|
||||
{
|
||||
this->serv.addSongToRepository(artist, title, minutes, seconds, link);
|
||||
}
|
||||
catch (SongException& e)
|
||||
{
|
||||
for (auto s : e.getErrors())
|
||||
cout << s;
|
||||
}
|
||||
catch (RepositoryException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
catch (FileException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::removeSongFromRepo()
|
||||
{
|
||||
cout << "Enter the artist: ";
|
||||
std::string artist;
|
||||
getline(cin, artist);
|
||||
cout << "Enter the title: ";
|
||||
std::string title;
|
||||
getline(cin, title);
|
||||
|
||||
try
|
||||
{
|
||||
this->serv.removeSongFromRepository(artist, title);
|
||||
}
|
||||
catch (RepositoryException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::displayAllSongsRepo()
|
||||
{
|
||||
vector<Song> songs = this->serv.getRepo().getSongs();
|
||||
if (songs.size() == 0)
|
||||
{
|
||||
cout << "There are no songs in the repository." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto s: songs)
|
||||
{
|
||||
Duration d = s.getDuration();
|
||||
cout << s << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::addSongToPlaylist()
|
||||
{
|
||||
cout << "Enter the artist: ";
|
||||
std::string artist;
|
||||
getline(cin, artist);
|
||||
cout << "Enter the title: ";
|
||||
std::string title;
|
||||
getline(cin, title);
|
||||
|
||||
// search for the song in the repository
|
||||
try
|
||||
{
|
||||
Song s = this->serv.getRepo().findByArtistAndTitle(artist, title);
|
||||
this->serv.addSongToPlaylist(s);
|
||||
}
|
||||
catch (InexistenSongException& e)
|
||||
{
|
||||
cout << e.what();
|
||||
cout << "Nothing will be added to the playlist." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::addAllSongsByArtistToPlaylist()
|
||||
{
|
||||
cout << "Enter the artist: ";
|
||||
std::string artist;
|
||||
getline(cin, artist);
|
||||
|
||||
this->serv.addAllSongsByArtistToPlaylist(artist);
|
||||
}
|
||||
|
||||
void UI::savePlaylistToFile()
|
||||
{
|
||||
std::string filename;
|
||||
cout << "Input the file name (absolute path): ";
|
||||
getline(cin, filename);
|
||||
|
||||
try
|
||||
{
|
||||
this->serv.savePlaylist(filename);
|
||||
|
||||
if (this->serv.getPlaylist() == nullptr)
|
||||
{
|
||||
cout << "Playlist cannot be displayed!" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (FileException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
UI::printMenu();
|
||||
int command{ 0 };
|
||||
cout << "Input the command: ";
|
||||
cin >> command;
|
||||
cin.ignore();
|
||||
if (command == 0)
|
||||
break;
|
||||
|
||||
// repository management
|
||||
if (command == 1)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
UI::printRepositoryMenu();
|
||||
int commandRepo{0};
|
||||
cout << "Input the command: ";
|
||||
cin >> commandRepo;
|
||||
cin.ignore();
|
||||
if (commandRepo == 0)
|
||||
break;
|
||||
switch (commandRepo)
|
||||
{
|
||||
case 1:
|
||||
this->addSongToRepo();
|
||||
break;
|
||||
case 2:
|
||||
this->removeSongFromRepo();
|
||||
break;
|
||||
case 3:
|
||||
this->displayAllSongsRepo();
|
||||
break;
|
||||
case 4:
|
||||
try
|
||||
{
|
||||
this->serv.undo();
|
||||
}
|
||||
catch (RepositoryException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
try
|
||||
{
|
||||
this->serv.redo();
|
||||
}
|
||||
catch (RepositoryException& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// playlist management
|
||||
if (command == 2)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
UI::printPlayListMenu();
|
||||
int commandPlaylist{0};
|
||||
cout << "Input the command: ";
|
||||
cin >> commandPlaylist;
|
||||
cin.ignore();
|
||||
if (commandPlaylist == 0)
|
||||
break;
|
||||
switch (commandPlaylist)
|
||||
{
|
||||
case 1:
|
||||
this->addSongToPlaylist();
|
||||
break;
|
||||
case 2:
|
||||
this->addAllSongsByArtistToPlaylist();
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
if (this->serv.getPlaylist()->isEmpty())
|
||||
{
|
||||
cout << "Nothing to play, the playlist is empty." << endl;
|
||||
continue;
|
||||
}
|
||||
this->serv.startPlaylist();
|
||||
Song s = this->serv.getPlaylist()->getCurrentSong();
|
||||
cout << "Now playing: " << s.getArtist() << " - " << s.getTitle() << endl;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
if (this->serv.getPlaylist()->isEmpty())
|
||||
{
|
||||
cout << "Nothing to play, the playlist is empty." << endl;
|
||||
continue;
|
||||
}
|
||||
this->serv.nextSongPlaylist();
|
||||
Song s = this->serv.getPlaylist()->getCurrentSong();
|
||||
cout << "Now playing: " << s.getArtist() << " - " << s.getTitle() << endl;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
this->savePlaylistToFile();
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
this->serv.openPlaylist();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "Service.h"
|
||||
|
||||
class UI
|
||||
{
|
||||
private:
|
||||
Service& serv; // reference to the Service (Service cannot be copied!)
|
||||
|
||||
public:
|
||||
UI(Service& s) : serv(s) {}
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
static void printMenu();
|
||||
static void printRepositoryMenu();
|
||||
static void printPlayListMenu();
|
||||
|
||||
void addSongToRepo();
|
||||
void removeSongFromRepo();
|
||||
void displayAllSongsRepo();
|
||||
void addSongToPlaylist();
|
||||
void addAllSongsByArtistToPlaylist();
|
||||
void savePlaylistToFile();
|
||||
};
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#include "Utils.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string trim(const std::string& s)
|
||||
{
|
||||
std::string result(s);
|
||||
int pos = result.find_first_not_of(" ");
|
||||
if (pos != -1)
|
||||
result.erase(0, pos);
|
||||
pos = result.find_last_not_of(" ");
|
||||
if (pos != std::string::npos)
|
||||
result.erase(pos + 1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<string> tokenize(const string& str, char delimiter)
|
||||
{
|
||||
vector <string> result;
|
||||
stringstream ss(str);
|
||||
string token;
|
||||
while (getline(ss, token, delimiter))
|
||||
result.push_back(token);
|
||||
|
||||
return result;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
Trims leading and trailing spaces from a string.
|
||||
Input: s - string
|
||||
Output: a string, with no leading and trailing spaces.
|
||||
*/
|
||||
std::string trim(const std::string& s);
|
||||
|
||||
/*
|
||||
Tokenizes a string.
|
||||
Input: str - the string to be tokenized.
|
||||
delimiter - char - the delimiter used for tokenization
|
||||
Output: a vector of strings, containing the tokens
|
||||
*/
|
||||
std::vector<std::string> tokenize(const std::string& str, char delimiter);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#include "UI.h"
|
||||
// #include <Windows.h>
|
||||
#include "CSVPlayList.h"
|
||||
#include "RepositoryExceptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
system("color f4");
|
||||
|
||||
try
|
||||
{
|
||||
Repository repo("Songs.txt");
|
||||
FilePlaylist* p = new CSVPlaylist{};
|
||||
Service serv(repo, p, SongValidator{});
|
||||
UI ui(serv);
|
||||
ui.run();
|
||||
delete p;
|
||||
}
|
||||
catch (FileException&)
|
||||
{
|
||||
cout << "Repository file could not be opened! The application will terminate." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#include<stdio.h>
|
||||
|
||||
typedef struct{
|
||||
int length;
|
||||
int elems[100];
|
||||
}vector;
|
||||
|
||||
vector read(){
|
||||
/*
|
||||
:input:
|
||||
|
||||
:output:
|
||||
vector v
|
||||
|
||||
:description:
|
||||
return a vector of integer numbers read from the keyboard
|
||||
*/
|
||||
vector v;
|
||||
v.length = 0;
|
||||
while (scanf("%d", &v.elems[v.length]) && v.elems[v.length] != 0)
|
||||
{
|
||||
v.length++;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void printVector(vector v,int startI,int endI){
|
||||
/*
|
||||
:input:
|
||||
vector v
|
||||
int startI
|
||||
int endI
|
||||
:output:
|
||||
void
|
||||
|
||||
:description:
|
||||
print the elements of the vector v from startI (inclusive) to endI (exclusive)
|
||||
*/
|
||||
for (int i = startI; i < endI; i++)
|
||||
{
|
||||
printf("%d ", v.elems[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void printInstructions(){
|
||||
printf("1. Read a vector\n");
|
||||
printf("2. Print the sum of a sequence of numbers\n");
|
||||
printf("3. Print the longest contiguous subsequence of equal numbers\n");
|
||||
printf("0. Exit\n");
|
||||
}
|
||||
|
||||
int sum_of_vector(vector v){
|
||||
/*
|
||||
:input:
|
||||
vector v
|
||||
:output:
|
||||
int sum
|
||||
|
||||
:description:
|
||||
return the sum of the elements of the vector v
|
||||
*/
|
||||
int sum = 0;
|
||||
for (int i = 0; i < v.length; i++)
|
||||
{
|
||||
sum += v.elems[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void waitForUserInput(){
|
||||
vector v;
|
||||
v.length = 0;
|
||||
while(1){
|
||||
printInstructions();
|
||||
int option;
|
||||
scanf("%d", &option);
|
||||
switch (option)
|
||||
{
|
||||
case 1:
|
||||
v=read();
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
printf("Invalid option\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
waitForUserInput();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2036
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Seminar3_Week2_stub", "Seminar3_Week2_stub\Seminar3_Week2_stub.vcxproj", "{2A052F8F-28D2-4143-B482-193BF264A62E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x64.Build.0 = Debug|x64
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x64.ActiveCfg = Release|x64
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x64.Build.0 = Release|x64
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {07D2633E-81F6-4DE8-AE18-5DF14D6DD1F3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
#include <iterator>
|
||||
|
||||
template <typename T>
|
||||
class DynamicVector
|
||||
{
|
||||
private:
|
||||
T* elems;
|
||||
int size;
|
||||
int capacity;
|
||||
|
||||
public:
|
||||
// default constructor for a DynamicVector
|
||||
DynamicVector(int capacity = 10);
|
||||
|
||||
// copy constructor for a DynamicVector
|
||||
DynamicVector(const DynamicVector& v);
|
||||
~DynamicVector();
|
||||
|
||||
// assignment operator for a DynamicVector
|
||||
DynamicVector& operator=(const DynamicVector& v);
|
||||
|
||||
/*
|
||||
Overloading the subscript operator
|
||||
Input: pos - a valid position within the vector.
|
||||
Output: a reference to the element o position pos.
|
||||
*/
|
||||
T& operator[](int pos);
|
||||
|
||||
// Adds an element to the current DynamicVector.
|
||||
void add(const T& e);
|
||||
|
||||
int getSize() const;
|
||||
void setSize(int s) { size = s; }
|
||||
|
||||
private:
|
||||
// Resizes the current DynamicVector, multiplying its capacity by a given factor (real number).
|
||||
void resize(double factor = 2);
|
||||
|
||||
public:
|
||||
class iterator
|
||||
{
|
||||
private:
|
||||
T* ptr;
|
||||
public:
|
||||
// constructor
|
||||
iterator(T* p);
|
||||
|
||||
// prefix operator
|
||||
iterator operator++();
|
||||
|
||||
// postfix operator
|
||||
iterator operator++(int dummy);
|
||||
|
||||
T& operator*();
|
||||
T* operator->();
|
||||
bool operator!=(const iterator& it);
|
||||
};
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return this->elems;
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return this->elems + this->size;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
DynamicVector<T>::DynamicVector(int capacity)
|
||||
{
|
||||
this->size = 0;
|
||||
this->capacity = capacity;
|
||||
this->elems = new T[capacity];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DynamicVector<T>::DynamicVector(const DynamicVector<T>& v)
|
||||
{
|
||||
this->size = v.size;
|
||||
this->capacity = v.capacity;
|
||||
this->elems = new T[this->capacity];
|
||||
for (int i = 0; i < this->size; i++)
|
||||
this->elems[i] = v.elems[i];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DynamicVector<T>::~DynamicVector()
|
||||
{
|
||||
delete[] this->elems;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DynamicVector<T>& DynamicVector<T>::operator=(const DynamicVector<T>& v)
|
||||
{
|
||||
if (this == &v)
|
||||
return *this;
|
||||
|
||||
this->size = v.size;
|
||||
this->capacity = v.capacity;
|
||||
|
||||
delete[] this->elems;
|
||||
this->elems = new T[this->capacity];
|
||||
for (int i = 0; i < this->size; i++)
|
||||
this->elems[i] = v.elems[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DynamicVector<T>::operator[](int pos)
|
||||
{
|
||||
return this->elems[pos];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DynamicVector<T>::add(const T& e)
|
||||
{
|
||||
if (this->size == this->capacity)
|
||||
this->resize();
|
||||
this->elems[this->size] = e;
|
||||
this->size++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DynamicVector<T>::resize(double factor)
|
||||
{
|
||||
this->capacity *= static_cast<int>(factor);
|
||||
|
||||
T* els = new T[this->capacity];
|
||||
for (int i = 0; i < this->size; i++)
|
||||
els[i] = this->elems[i];
|
||||
|
||||
delete[] this->elems;
|
||||
this->elems = els;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int DynamicVector<T>::getSize() const
|
||||
{
|
||||
return this->size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DynamicVector<T>::iterator::iterator(T* p){
|
||||
ptr = p;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename DynamicVector<T>::iterator DynamicVector<T>::iterator::operator++(){
|
||||
ptr++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename DynamicVector<T>::iterator DynamicVector<T>::iterator::operator++(int dummy){
|
||||
iterator it = *this;
|
||||
ptr++;
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DynamicVector<T>::iterator::operator*(){
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* DynamicVector<T>::iterator::operator->(){
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DynamicVector<T>::iterator::operator!=(const iterator& it){
|
||||
return ptr != it.ptr;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
T value;
|
||||
Node *nextNode;
|
||||
Node()
|
||||
{
|
||||
this->value = 0;
|
||||
this->nextNode = nullptr;
|
||||
}
|
||||
~Node()
|
||||
{
|
||||
delete nextNode;
|
||||
}
|
||||
Node(const Node &n)
|
||||
{
|
||||
value = n.value;
|
||||
nextNode = n.nextNode;
|
||||
}
|
||||
Node &operator=(const Node &n)
|
||||
{
|
||||
this->value = n.value;
|
||||
this->nextNode = n.nextNode;
|
||||
return *this;
|
||||
}
|
||||
Node &operator=(const T &value)
|
||||
{
|
||||
this->value = value;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class LinkedList
|
||||
{
|
||||
private:
|
||||
Node<T> *beginingNode;
|
||||
int size;
|
||||
|
||||
public:
|
||||
LinkedList(Node<T> *f = nullptr);
|
||||
LinkedList(const LinkedList &l);
|
||||
~LinkedList();
|
||||
|
||||
// assignment operator for a LinkedList
|
||||
LinkedList &operator=(const LinkedList &l);
|
||||
|
||||
T &operator[](int pos);
|
||||
|
||||
// Adds an element to the current LinkedList.
|
||||
void add(const T &e);
|
||||
|
||||
int getSize() const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
LinkedList<T>::LinkedList(Node<T> *f)
|
||||
{
|
||||
this->beginingNode = f;
|
||||
this->size = 0;
|
||||
if (f != nullptr)
|
||||
{
|
||||
this->size++;
|
||||
while (f->nextNode != nullptr)
|
||||
this->size++;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
LinkedList<T>::LinkedList(const LinkedList &l)
|
||||
{
|
||||
Node<T> *currentNode = new Node<T>();
|
||||
if (l.beginingNode == nullptr)
|
||||
{
|
||||
beginingNode = nullptr;
|
||||
size = 0;
|
||||
return;
|
||||
}
|
||||
*currentNode = *l.beginingNode;
|
||||
beginingNode = currentNode;
|
||||
size = 1;
|
||||
Node<T> *nextNode = l.beginingNode->nextNode;
|
||||
while (nextNode != nullptr)
|
||||
{
|
||||
*(currentNode->nextNode) = *nextNode;
|
||||
currentNode = currentNode->nextNode;
|
||||
nextNode = nextNode->nextNode;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
LinkedList<T>::~LinkedList()
|
||||
{
|
||||
delete this->beginingNode;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
LinkedList<T> &LinkedList<T>::operator=(const LinkedList &l)
|
||||
{
|
||||
Node<T> *currentNode = new Node<T>();
|
||||
if (l.beginingNode == nullptr)
|
||||
{
|
||||
this->beginingNode = nullptr;
|
||||
this->size = 0;
|
||||
return *this;
|
||||
}
|
||||
*currentNode = *l.beginingNode;
|
||||
this->beginingNode = currentNode;
|
||||
this->size = 1;
|
||||
Node<T> *nextNode = l.beginingNode->nextNode;
|
||||
while (nextNode != nullptr)
|
||||
{
|
||||
*(currentNode->nextNode) = *nextNode;
|
||||
currentNode = currentNode->nextNode;
|
||||
nextNode = nextNode->nextNode;
|
||||
this->size++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &LinkedList<T>::operator[](int pos)
|
||||
{
|
||||
if (pos >= this->size || pos < 0)
|
||||
throw std::invalid_argument("Invalid position");
|
||||
Node<T> *currentNode = this->beginingNode;
|
||||
for (int i = 0; i < pos; i++)
|
||||
{
|
||||
currentNode = currentNode->nextNode;
|
||||
}
|
||||
return currentNode->value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void LinkedList<T>::add(const T &e)
|
||||
{
|
||||
if (this->beginingNode == nullptr)
|
||||
{
|
||||
this->beginingNode = new Node<T>();
|
||||
this->beginingNode->value = e;
|
||||
this->size = 1;
|
||||
return;
|
||||
}
|
||||
Node<T> *currentNode = this->beginingNode;
|
||||
for (int i = 1; i < this->size; i++)
|
||||
{
|
||||
currentNode = currentNode->nextNode;
|
||||
}
|
||||
currentNode->nextNode = new Node<T>();
|
||||
currentNode->nextNode->value = e;
|
||||
this->size++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int LinkedList<T>::getSize() const
|
||||
{
|
||||
return this->size;
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2A052F8F-28D2-4143-B482-193BF264A62E}</ProjectGuid>
|
||||
<RootNamespace>Seminar3Week2stub</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Song.cpp" />
|
||||
<ClCompile Include="Tests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DynamicVector.h" />
|
||||
<ClInclude Include="LinkedList.h" />
|
||||
<ClInclude Include="Song.h" />
|
||||
<ClInclude Include="Tests.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Song.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Tests.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Song.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Tests.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DynamicVector.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LinkedList.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "Song.h"
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
Song::Song(): title(""), artist(""), duration(Duration()), source("") {}
|
||||
|
||||
Song::Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source)
|
||||
{
|
||||
this->artist = artist;
|
||||
this->title = title;
|
||||
this->duration = duration;
|
||||
this->source = source;
|
||||
}
|
||||
|
||||
bool Song::operator==(const Song & s)
|
||||
{
|
||||
return (this->artist == s.artist && this->title == s.title);
|
||||
}
|
||||
|
||||
void Song::play()
|
||||
{
|
||||
ShellExecuteA(NULL, NULL, "chrome.exe", this->getSource().c_str(), NULL, SW_SHOWMAXIMIZED);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
|
||||
class Duration
|
||||
{
|
||||
private:
|
||||
double minutes;
|
||||
double seconds;
|
||||
public:
|
||||
Duration() : minutes(0), seconds(0) {}
|
||||
Duration(double min, double sec) : minutes(min), seconds(sec) {}
|
||||
|
||||
double getMinutes() const { return minutes; }
|
||||
double getSeconds() const { return seconds; }
|
||||
};
|
||||
|
||||
class Song
|
||||
{
|
||||
private:
|
||||
std::string title;
|
||||
std::string artist;
|
||||
Duration duration;
|
||||
std::string source; // youtube Link
|
||||
|
||||
public:
|
||||
// default constructor for a song
|
||||
Song();
|
||||
|
||||
// constructor with parameters
|
||||
Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source);
|
||||
|
||||
std::string getTitle() const { return title; }
|
||||
std::string getArtist() const { return artist; }
|
||||
std::string getSource() const { return source; }
|
||||
Duration getDuration() const { return duration; }
|
||||
|
||||
bool operator==(const Song& s);
|
||||
|
||||
// Plays the current song: the page corresponding to the source link is opened in a browser.
|
||||
void play();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "Tests.h"
|
||||
#include "DynamicVector.h"
|
||||
#include "LinkedList.h"
|
||||
#include <assert.h>
|
||||
|
||||
void Tests::testDynamicVector()
|
||||
{
|
||||
DynamicVector<int> v1{};
|
||||
v1.add(10);
|
||||
v1.add(20);
|
||||
assert(v1.getSize() == 2);
|
||||
assert(v1[1] == 20);
|
||||
v1[1] = 40;
|
||||
assert(v1[1] == 40);
|
||||
v1.add(30);
|
||||
assert(v1.getSize() == 3);
|
||||
|
||||
DynamicVector<int> v2{ v1 };
|
||||
assert(v2.getSize() == 3);
|
||||
|
||||
DynamicVector<int> v3;
|
||||
v3 = v1;
|
||||
assert(v3[0] == 10);
|
||||
|
||||
// test iterator
|
||||
DynamicVector<int>::iterator it = v1.begin();
|
||||
assert(*it == 10);
|
||||
assert(it != v1.end());
|
||||
++it;
|
||||
assert(*it == 40);
|
||||
}
|
||||
|
||||
void Tests::testLinkedList()
|
||||
{
|
||||
LinkedList<int> l1{};
|
||||
l1.add(10);
|
||||
l1.add(20);
|
||||
assert(l1.getSize() == 2);
|
||||
assert(l1[1] == 20);
|
||||
l1[1] = 40;
|
||||
assert(l1[1] == 40);
|
||||
l1.add(30);
|
||||
assert(l1.getSize() == 3);
|
||||
|
||||
LinkedList<int> l2{ l1 };
|
||||
assert(l2.getSize() == 3);
|
||||
|
||||
LinkedList<int> l3;
|
||||
l3 = l1;
|
||||
assert(l3[0] == 10);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
class Tests
|
||||
{
|
||||
public:
|
||||
static void testDynamicVector();
|
||||
static void testLinkedList();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "DynamicVector.h"
|
||||
#include "LinkedList.h"
|
||||
#include "LinkedList.h"
|
||||
#include "Song.h"
|
||||
#include "Tests.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
Tests::testDynamicVector();
|
||||
Tests::testLinkedList();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user