consolidate all repos to one for archive
This commit is contained in:
66
semester_2/programiranje_2/naloga1002/Gallery.cpp
Normal file
66
semester_2/programiranje_2/naloga1002/Gallery.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "Gallery.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
Gallery::Gallery(std::string name) : name(name)
|
||||
{
|
||||
}
|
||||
|
||||
void Gallery::addArtwork(std::shared_ptr<Artwork> artwork)
|
||||
{
|
||||
artworks.push_back(artwork);
|
||||
}
|
||||
|
||||
void Gallery::printArtworks() const
|
||||
{
|
||||
for (auto &artwork: artworks)
|
||||
std::cout << artwork->toString() << std::endl;
|
||||
}
|
||||
|
||||
std::string Gallery::toString() const
|
||||
{
|
||||
std::string ret;
|
||||
for (auto &artwork: artworks) ret += artwork->toString() + "\n\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Gallery::getSize() const
|
||||
{
|
||||
return artworks.size();
|
||||
};
|
||||
|
||||
void Gallery::sort(std::function<bool(std::shared_ptr<Artwork>, std::shared_ptr<Artwork>)> c)
|
||||
{
|
||||
for (int i = 0; i < artworks.size(); ++i)
|
||||
{
|
||||
for (int j = 0; j < artworks.size() - i - 1; ++j)
|
||||
{
|
||||
c(artworks[j], artworks[j + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Artwork> Gallery::find(std::function<bool(std::shared_ptr<Artwork>)> c)
|
||||
{
|
||||
auto it = std::find_if(artworks.begin(), artworks.end(), c);
|
||||
return *it;
|
||||
}
|
||||
|
||||
void Gallery::printArtworks(PrintIfPainting i)
|
||||
{
|
||||
std::for_each(artworks.begin(), artworks.end(), i);
|
||||
}
|
||||
|
||||
void Gallery::filterOut(std::function<bool(std::shared_ptr<Artwork>)> c)
|
||||
{
|
||||
auto it = artworks.begin();
|
||||
for (int i = 0; i < artworks.size(); ++i)
|
||||
{
|
||||
if (c(artworks[i]))
|
||||
{
|
||||
artworks.erase(it);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user