Kaynağa Gözat

Define readAggregatedStream in DBHandler

The method readAggregatedStream can be defined in the DBHandler since
its logic is general and can be reused.

Move the definition of readAggregatedStream in DBHandler. Declare it as
virtual but not abstract so that, if necessary, children classes can
redefine it.
mandragore 7 yıl önce
ebeveyn
işleme
df40af7171

+ 1 - 1
pir/dbhandlers/CMakeLists.txt

@@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 2.6.0)
 include_directories(..)
 include_directories(../..)
 
-add_library(pir_dbhandlers STATIC DBDirectoryProcessor.cpp DBGenerator.cpp)
+add_library(pir_dbhandlers STATIC DBDirectoryProcessor.cpp DBGenerator.cpp DBHandler.cpp)

+ 0 - 25
pir/dbhandlers/DBDirectoryProcessor.cpp

@@ -221,28 +221,3 @@ std::streampos DBDirectoryProcessor::getFileSize( std::string filePath ){
 	file.close();
 	return fsize;
 }
-
-void DBDirectoryProcessor::readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits){
-	uint64_t fileByteSize = std::min(bytes_per_file, getmaxFileBytesize()-offset);
-	uint64_t startStream = streamNb*alpha;
-	uint64_t endStream = std::min(streamNb*alpha + alpha - 1, getNbStream() - 1);
-	uint64_t paddingStreams = (streamNb*alpha+alpha) >= getNbStream() ? (streamNb*alpha+alpha) - getNbStream() : 0;
-
-  #pragma omp critical
-	{	
-		for (int i=startStream; i <= endStream; i++)
-		{
-			openStream(i, offset);
-
-			// Just read the file (plus padding for that file)
-			readStream(i, rawBits + (i % alpha) * fileByteSize, fileByteSize);
-
-			closeStream(i);
-		} 
-
-		if(paddingStreams !=0)
-		{
-			bzero(rawBits + (endStream % alpha) * fileByteSize, fileByteSize*paddingStreams);
-		}
-	}
-}

+ 0 - 1
pir/dbhandlers/DBDirectoryProcessor.hpp

@@ -58,7 +58,6 @@ public:
   
   bool openStream(uint64_t streamNb, uint64_t requested_offset);
   uint64_t readStream(uint64_t streamNb, char * buf, uint64_t size);
-  void readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits);
   void closeStream(uint64_t streamNb);
   
   

+ 26 - 0
pir/dbhandlers/DBHandler.cpp

@@ -0,0 +1,26 @@
+#include "DBHandler.hpp"
+
+void DBHandler::readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits) {
+    uint64_t fileByteSize = std::min(bytes_per_file, getmaxFileBytesize()-offset);
+    uint64_t startStream = streamNb*alpha;
+    uint64_t endStream = std::min(streamNb*alpha + alpha - 1, getNbStream() - 1);
+    uint64_t paddingStreams = (streamNb*alpha+alpha) >= getNbStream() ? (streamNb*alpha+alpha) - getNbStream() : 0;
+
+  #pragma omp critical
+    {
+        for (int i=startStream; i <= endStream; i++)
+        {
+            openStream(i, offset);
+
+            // Just read the file (plus padding for that file)
+            readStream(i, rawBits + (i % alpha) * fileByteSize, fileByteSize);
+
+            closeStream(i);
+        }
+
+        if(paddingStreams !=0)
+        {
+            bzero(rawBits + (endStream % alpha) * fileByteSize, fileByteSize*paddingStreams);
+        }
+    }
+}

+ 2 - 1
pir/dbhandlers/DBHandler.hpp

@@ -21,6 +21,7 @@
 #include <vector>
 #include <string>
 #include <iostream>
+#include <string.h>
 
 class DBHandler
 {
@@ -35,7 +36,7 @@ public:
   
   virtual bool openStream(uint64_t streamNb, uint64_t requested_offset)=0;
   virtual uint64_t readStream(uint64_t streamNb, char * buf, uint64_t size)=0;
-  virtual void readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits)=0;
+  virtual void readAggregatedStream(uint64_t streamNb, uint64_t alpha, uint64_t offset, uint64_t bytes_per_file, char* rawBits);
   virtual void closeStream(uint64_t streamNb)=0;
   virtual ~DBHandler(){};