Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __MAP_TEMPLATE_H__
- #define __MAP_TEMPLATE_H__
- #include <vector>
- #include <map>
- #include "employee.h"
- #include "biblioteka.h"
- using namespace std;
- template <typename ID, typename dane>
- class map_template{
- vector<ID> data;
- vector<dane> data2;
- public:
- map_template(){
- };
- ~map_template(){
- vector<ID>().swap(data); //That will create an empty vector with no memory allocated
- //and swap it with tempVector, effectively deallocating the memory.
- vector<dane>().swap(data2);
- }
- class BadAlloc{ }; // tylko do rzucenia wyjatku
- void Add(ID idd, dane dd)
- {
- try{
- data.push_back(idd);
- data2.push_back(dd);
- }
- catch(const std::bad_alloc &e){
- cerr << "Exception at " << e.what() << endl;
- }
- catch(...){
- }
- }
- dane* Find(ID idd)
- {
- if(!data.empty()){
- for (size_t i = 0; i != data.size(); ++i)
- {
- if(idd==this->data[i])
- {
- return &(this->data2[i]);
- }
- }
- }
- return 0;
- }
- friend ostream& operator << (ostream& o, const map_template& m)
- {
- if(!(m.data2.empty()) || !(m.data.empty()) || m.data.size()==m.data2.size()){
- for (size_t i = 0; i != m.data2.size(); ++i) {
- o << m.data[i] << ", " <<m.data2[i] <<endl;
- }
- }
- else o << "Error" <<endl;
- return o;
- }
- };
- #endif /* __MAP_TEMPLATE_H__ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement