         self.write(data, atPos: pos)
     }
 
+
+
+    // subclases have to override
     func delete(aID: UID) -> CUnsignedLongLong {
         
         var pos = self.seekToFileID(aID)
         
         return pos;
     }
-    
+    */
 }

import Foundation


class DataStore<O: ObjectCoding, H> : FileStore {
    
    var dataSize: Int = 0
    
    init(url: NSURL) {
        super.init(url: url)
    }

    
    // #pragma mark -

    // #pragma mark - read/write header
    
        
    func readHeader() -> H! {
        
        var data = self.fileHandle.readDataOfLength(sizeof(H))
        
        var result : H
        
        data.getBytes(&result)
        
        return result
        
    }
   
    /**
    func writeHeader(header: H) {
        
        var data = NSData(bytesNoCopy:CMutableVoidPointer(&header), length:sizeof(H))
        
        self.fileHandle.writeData(data)
        
    }*/

    // override this methode
    func writeHeader(forData data:NSData, atPos pos:CUnsignedLongLong) {
        
    }
    
    func writeHeader(buffer: CConstPointer<H>) {
        
        let headerData = buffer.withUnsafePointer {
            NSData(bytes:$0, length:sizeof(H))
        }
        self.fileHandle.writeData(headerData)
    }
        
    //#pragma mark - pos Calcuation
    
    func calculatePos(aID: UID) -> CUnsignedLongLong {
        
        return CUnsignedLongLong((aID * self.dataSize) + self.fileOffset)
    
    }
    
    func calculateID(pos: CUnsignedLongLong) -> UID {
        
        var result = (Int(pos) - self.fileOffset) / self.dataSize;
        
        return result
    }
    
    func seekToFileID(aID: UID) -> CUnsignedLongLong {
        
        var pos = self.calculatePos(aID)
        
        self.fileHandle.seekToFileOffset(pos)
        
        return pos
    }

    //#pragma mark - SOFileStore
    
    override func write(data: NSData, atPos pos: CUnsignedLongLong) {
        
        self.fileHandle.seekToFileOffset(pos)
        
        self.writeHeader(forData: data, atPos: pos)

        self.fileHandle.writeData(data);

        return self.readData()
    }


    
    func update(data: NSData, atID aID:UID) {
        
