Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 21 / Sketcher05 / HashElem
.h#if !defined(HASHELEM_H)
#define HASHELEM_H
#include "TextInTriangle.h"
#include <iostream>
using namespace std;
template<class K, class V>
class HashElem {
private:
static unsigned long int count;
static unsigned long int total;
const unsigned long int id;
K key;
V value;
bool null;
public:
HashElem(): id(++total){
null = true;
count++;
cout << "create HashElem#" << id << endl;
};
HashElem(K k, V v): id(++total){
count++;
cout << "create HashElem#" << id << endl;
key = k;
value = v;
null = false;
};
HashElem(const HashElem<K, V>& o): id(++total){
count++;
cout << "create HashElem" << id << " via cc" << endl;
key = o.key;
value = o.value;
null = false;
};
virtual ~HashElem() {
count--;
cout << "destroy HashElem#" << id << endl;
/*if (!null){
delete key;
delete value;
}*/
null = true;
};
K& getKey() {
return key;
}
V& getValue() {
return value;
}
void set(K k, V v){
key = k;
value = v;
null = false;
}
void setNull(){
/*delete key;
delete value;*/
null = true;
}
bool isNull(){
return null;
}
/*
template<class K, class V>
friend ostream& operator<<(ostream& os, const HashElem<K, V>& o);
*/
unsigned long int getObjectId() const{
return id;
}
static unsigned long int getNumberOfObjects(){ //const
return count;
}
/*
template<class K, class V>
HashElem<K, V>& operator=(const HashElem<K, V>& o){
if(this == &o)
return *this;
key = o.key;
value = o.value;
null = false;
return *this;
}
*/
void Serialize(CArchive& ar);
};
template<class K, class V>
void HashElem<K, V>::Serialize(CArchive& ar)
{
if (ar.IsStoring()){
/* ar //<< typeid(*key).name()
//<< key
//<< typeid(*value).name()
<< *t1;
*/
ar << key;
ar << typeid(*value).name()
<< *value;
}
else{
ar >> key;
CString s;
ar >> s;
if (s == typeid(Text).name())
value = new Text();
else if (s == typeid(Line).name())
value = new Line();
else if (s == typeid(Triangle).name())
value = new Triangle();
else if (s == typeid(TextInTriangle).name())
value = new TextInTriangle();
ar >> value;
//3
/*
CElement* t1 = new Text();
ar >> t1;
value = dynamic_cast<Text*>(t1);
*/
null = false;
}
}
/*
template<class K, class V>
ostream& operator<<(ostream& os, const HashElem<K, V>& o){
os << "key: " << o.key << ", value: " << o.value;
return os;
}
*/
template<class K, class V>
unsigned long int HashElem<K, V>::count = 0;
template<class K, class V>
unsigned long int HashElem<K, V>::total = 0;
#endif
Соседние файлы в папке Sketcher05