Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2018-2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: MIT 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : /** 9 : : * @file 10 : : */ 11 : : 12 : : #pragma once 13 : : 14 : : #include <stdio.h> 15 : : #include "ad/map/serialize/IStorage.hpp" 16 : : 17 : : /** @brief namespace ad */ 18 : : namespace ad { 19 : : /** @brief namespace map */ 20 : : namespace map { 21 : : /** @brief namespace serialize */ 22 : : namespace serialize { 23 : : 24 : : /** 25 : : * @brief File Storage implementation 26 : : */ 27 : : class StorageFile : protected virtual IStorage 28 : : { 29 : : protected: // Constructor/Destructor 30 : : StorageFile(); 31 : : virtual ~StorageFile(); 32 : : 33 : : public: // IStorage Implementation 34 : 1 : const char *getStorageType() override 35 : : { 36 : 1 : return "File"; 37 : : } 38 : : 39 : : protected: // IStorage Implementation 40 : 159 : bool doOpenForRead(std::string const &config) override 41 : : { 42 [ + - + - ]: 159 : return doOpen(config, "rb"); 43 : : }; 44 : : 45 : 12 : bool doOpenForWrite(std::string const &config) override 46 : : { 47 [ + - + - ]: 12 : return doOpen(config, "wb"); 48 : : } 49 : : 50 : 157 : bool doCloseForRead() override 51 : : { 52 : 157 : return doClose(); 53 : : } 54 : : 55 : 12 : bool doCloseForWrite() override 56 : : { 57 : 12 : return doClose(); 58 : : } 59 : : 60 : : bool doWrite(const void *x, size_t bytes) override; 61 : : bool doRead(void *x, size_t bytes) override; 62 : : 63 : : private: // Aux Methods 64 : : bool doOpen(std::string const &config, std::string const &flags); 65 : : bool doClose(); 66 : : 67 : : private: // Data Members 68 : : FILE *file_; 69 : : }; 70 : : 71 : : } // namespace serialize 72 : : } // namespace map 73 : : } // namespace ad