gStore/KVstore/IVArray/IVEntry.cpp

184 lines
2.4 KiB
C++
Raw Normal View History

2018-02-13 11:37:54 +08:00
/*=========================================================================
* File name: IVEntry.cpp
* Author: Zongyue Qin
* Mail: qinzongyue@pku.edu.cn
* Last Modified: 2018-01-30
* Description:
* Implementation of functions in IVEntry.h
* =======================================================================*/
#include "IVEntry.h"
using namespace std;
IVEntry::IVEntry()
{
store = 0;
value = NULL;
usedFlag = false;
dirtyFlag = true;
cacheFlag = false;
CachePinFlag = false;
prevID = nextID = -1;
2018-02-13 11:37:54 +08:00
}
void
IVEntry::setBstr(const Bstr* _value)
{
if (value != NULL)
delete value;
value = new Bstr(*_value);
}
void
2018-03-19 14:06:27 +08:00
IVEntry::setBstr(char *_str, unsigned _len)
2018-02-13 11:37:54 +08:00
{
if (value != NULL)
delete value;
value = new Bstr();
2018-03-19 14:06:27 +08:00
//value->copy(_str, _len);
value->setStr(_str);
value->setLen(_len);
2018-02-13 11:37:54 +08:00
}
bool
IVEntry::getBstr(char *& _str, unsigned &_len, bool if_copy) const
2018-02-13 11:37:54 +08:00
{
if (value == NULL)
{
_str = NULL;
_len = 0;
return false;
}
if (if_copy)
{
char *str = value->getStr();
_len = value->getLen();
_str = new char [_len];
memcpy(_str, str, _len);
}
else
{
_str = value->getStr();
_len = value->getLen();
}
2018-02-13 11:37:54 +08:00
return true;
}
void
IVEntry::setStore(unsigned _store)
{
store = _store;
}
unsigned
IVEntry::getStore() const
{
return store;
}
void
IVEntry::setUsedFlag(bool _flag)
{
usedFlag = _flag;
}
bool
IVEntry::isUsed() const
{
return usedFlag;
}
void
IVEntry::setDirtyFlag(bool _flag)
{
dirtyFlag = _flag;
}
bool
IVEntry::isDirty() const
{
return dirtyFlag;
}
void
IVEntry::setCacheFlag(bool _flag)
{
cacheFlag = _flag;
}
bool
IVEntry::inCache() const
{
return cacheFlag;
}
void
IVEntry::setCachePinFlag(bool _flag)
{
CachePinFlag = _flag;
}
bool
IVEntry::isPined()
{
return CachePinFlag;
}
2018-02-13 11:37:54 +08:00
void
IVEntry::release()
{
if (value != NULL)
{
delete value;
}
value = NULL;
nextID = prevID = -1;
2018-02-13 11:37:54 +08:00
}
void
IVEntry::Copy(const IVEntry& _entry)
{
this->store = _entry.store;
this->cacheFlag = _entry.cacheFlag;
this->dirtyFlag = _entry.dirtyFlag;
this->usedFlag = _entry.usedFlag;
if (_entry.value != NULL)
{
this->value = new Bstr();
value->copy(_entry.value);
}
2018-04-12 14:50:13 +08:00
this->prevID = _entry.prevID;
this->nextID = _entry.nextID;
2018-02-13 11:37:54 +08:00
}
void
IVEntry::setPrev(int ID)
{
prevID = ID;
}
int
IVEntry::getPrev() const
{
return prevID;
}
void
IVEntry::setNext(int ID)
{
nextID = ID;
}
int
IVEntry::getNext() const
{
return nextID;
}
2018-02-13 11:37:54 +08:00
IVEntry::~IVEntry()
{
this->release();
}