consolidate all repos to one for archive
This commit is contained in:
43
semester_2/programiranje_2/naloga1001/Gallery.cpp
Normal file
43
semester_2/programiranje_2/naloga1001/Gallery.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "Gallery.h"
|
||||
#include <iostream>
|
||||
|
||||
Gallery::Gallery(std::string name) : name(name) {
|
||||
}
|
||||
|
||||
void Gallery::addArtwork(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;
|
||||
}
|
||||
|
||||
void Gallery::sort(bool (*c)(Artwork *, Artwork *)) {
|
||||
std::sort(artworks.begin(),artworks.end(), c);
|
||||
}
|
||||
|
||||
Artwork *Gallery::find(bool (*c)(Artwork *)) {
|
||||
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);
|
||||
}
|
||||
|
||||
std::vector<Artwork *> Gallery::filteredVector(bool (*c)(Artwork *)) {
|
||||
std::vector<Artwork *> tmp;
|
||||
for (int i = 0; i < artworks.size(); ++i) {
|
||||
if(c(artworks[i])){
|
||||
tmp.push_back(artworks[i]);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
Reference in New Issue
Block a user