Line data Source code
1 : /*
2 : * Interests.cpp
3 : *
4 : * Created on: Jun 2, 2016
5 : * Author: tobias
6 : */
7 :
8 : #include "Interests.h"
9 :
10 : using namespace std;
11 :
12 2646 : Interests::Interests() {
13 : // TODO Auto-generated constructor stub
14 :
15 2646 : }
16 :
17 3345 : void Interests::add(std::string category, std::string value){
18 3345 : map<string,vector<string>>::iterator it = this->intereses.find(category);
19 :
20 3345 : if ( it != this->intereses.end() ){
21 548 : vector<string> *valores = &it->second;
22 : //http://stackoverflow.com/questions/3450860/check-if-a-stdvector-contains-a-certain-object
23 548 : if (std::find(valores->begin(), valores->end(), value) == valores->end()){
24 415 : valores->push_back(value);
25 : }
26 :
27 : }else{
28 2797 : vector<string> valores;
29 2797 : valores.push_back(value);
30 2797 : this->intereses[category] = valores;
31 : }
32 3345 : }
33 :
34 5 : bool Interests::getAll(string category,vector<string> &values){
35 5 : map<string,vector<string>>::iterator it = this->intereses.find(category);
36 :
37 5 : if ( it != this->intereses.end() ){
38 : //devuelve copia
39 5 : values = it->second;
40 5 : return true;
41 : }
42 0 : return false;
43 :
44 : }
45 :
46 65 : bool Interests::has(string category, string value){
47 65 : map<string,vector<string>>::iterator it = this->intereses.find(category);
48 :
49 65 : if ( it != this->intereses.end() ){
50 : //codigo duplicado TODO
51 55 : vector<string> *valores = &it->second;
52 55 : if (std::find(valores->begin(), valores->end(), value) != valores->end()){
53 45 : return true;
54 : }
55 : }
56 :
57 20 : return false;
58 : }
59 :
60 10 : void Interests::remove(string category, string value){
61 10 : map<string,vector<string>>::iterator it = this->intereses.find(category);
62 :
63 10 : if ( it != this->intereses.end() ){
64 10 : vector<string> *valores = &it->second;
65 10 : vector<string>::iterator position = find(valores->begin(), valores->end(), value);
66 10 : if (position != valores->end()){
67 10 : valores->erase(position);
68 : }
69 :
70 : }
71 10 : }
72 :
73 509 : map<string,vector<string>> Interests::allInterests(){
74 509 : return this->intereses;
75 : }
76 :
77 3873 : Interests::~Interests() {
78 :
79 3873 : }
80 :
|