data_store_map.h
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef DATA_STORE_MAP
#define DATA_STORE_MAP
#include <unordered_map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <regex>
#include "data_store.h"
#include "../multithread/buffer_producer.h"
#include "data_basic.h"
/*
* Regex dependencies on gcc >= 4.9
* */
namespace data{
class Producer_map: public multithread::Buffer_producer<data::Data_basic*>{
protected:
std::unordered_map<std::string,data::Data_basic*> * const data;
std::string pattern;
void work_out(){
for(auto const &v: (*this->data)){
std::regex ex(this->pattern);
if(std::regex_match(v.first,ex)){
data::Data_basic *tmp = v.second->clone();
this->push(tmp);
}
}
}
public:
Producer_map(std::unordered_map<std::string,data::Data_basic*> * const map,std::string pattern):
data(map),pattern(pattern){}
virtual ~Producer_map(){
this->join();
}
};
class Data_Store_Map: public data::Data_Store{
protected:
std::unordered_map<std::string,data::Data_basic*> data_map;
void add_internal(data::Data_basic *data){
this->data_map[data->getName()] = data;
this->size ++;
}
public:
Data_Store_Map(){}
Data_Store_Map(std::string file_name):data::Data_Store(file_name){}
~Data_Store_Map(){
for(auto const &kv: this->data_map){
delete kv.second;
}
}
multithread::Buffer<data::Data_basic*> *get(std::string pattern){
Producer_map *tmp = new Producer_map(&(this->data_map),pattern);
tmp->start();
return tmp;
}
};
}
#endif // DATA_STORE_MAP