gStore/KVstore/IVArray/IVEntry.cpp

147 lines
2.0 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;
2018-02-21 16:52:20 +08:00
LongListFlag = false;
}
void
IVEntry::setLongListFlag(bool _flag)
{
LongListFlag = _flag;
}
bool
IVEntry::isLongList() const
{
return LongListFlag;
2018-02-13 11:37:54 +08:00
}
void
IVEntry::setBstr(const Bstr* _value)
{
if (value != NULL)
delete value;
value = new Bstr(*_value);
}
void
IVEntry::setBstr(const char *_str, unsigned _len)
{
if (value != NULL)
delete value;
value = new Bstr();
value->copy(_str, _len);
}
bool
IVEntry::getBstr(char *& _str, unsigned &_len) const
{
if (value == NULL)
{
_str = NULL;
_len = 0;
return false;
}
char *str = value->getStr();
_len = value->getLen();
_str = new char [_len];
memcpy(_str, str, _len);
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::release()
{
if (value != NULL)
{
delete value;
}
value = NULL;
}
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);
}
}
IVEntry::~IVEntry()
{
this->release();
}