2015-03-12 14:27:51 +01:00
# include "InMemoryBlock.h"
# include "InMemoryBlockStore.h"
2014-12-09 17:19:59 +01:00
# include <cstring>
2015-12-14 17:16:54 +01:00
# include <messmer/cpp-utils/data/DataUtils.h>
2015-07-22 13:42:07 +02:00
# include <messmer/cpp-utils/assert/assert.h>
2014-12-09 17:19:59 +01:00
using std : : make_shared ;
using std : : istream ;
using std : : ostream ;
using std : : ifstream ;
using std : : ofstream ;
using std : : ios ;
2015-04-25 02:48:41 +02:00
using cpputils : : Data ;
2014-12-09 17:19:59 +01:00
namespace blockstore {
namespace inmemory {
2015-04-18 14:47:12 +02:00
InMemoryBlock : : InMemoryBlock ( const Key & key , Data data )
: Block ( key ) , _data ( make_shared < Data > ( std : : move ( data ) ) ) {
2014-12-09 17:19:59 +01:00
}
InMemoryBlock : : InMemoryBlock ( const InMemoryBlock & rhs )
2015-01-24 22:08:41 +01:00
: Block ( rhs ) , _data ( rhs . _data ) {
2014-12-09 17:19:59 +01:00
}
InMemoryBlock : : ~ InMemoryBlock ( ) {
}
2015-03-04 20:47:02 +01:00
const void * InMemoryBlock : : data ( ) const {
2014-12-09 17:19:59 +01:00
return _data - > data ( ) ;
}
2015-03-04 20:47:02 +01:00
void InMemoryBlock : : write ( const void * source , uint64_t offset , uint64_t size ) {
2015-07-22 13:42:07 +02:00
ASSERT ( offset < = _data - > size ( ) & & offset + size < = _data - > size ( ) , " Write outside of valid area " ) ; //Also check offset < _data->size() because of possible overflow in the addition
2015-03-04 20:47:02 +01:00
std : : memcpy ( ( uint8_t * ) _data - > data ( ) + offset , source , size ) ;
2014-12-09 17:19:59 +01:00
}
size_t InMemoryBlock : : size ( ) const {
return _data - > size ( ) ;
}
2015-12-14 17:16:54 +01:00
void InMemoryBlock : : resize ( size_t newSize ) {
* _data = cpputils : : DataUtils : : resize ( std : : move ( * _data ) , newSize ) ;
}
2014-12-09 17:19:59 +01:00
void InMemoryBlock : : flush ( ) {
}
}
}