Line data Source code
1 : /* 2 : Copyright 2016-2017 Esri 3 : Licensed under the Apache License, Version 2.0 (the "License"); 4 : you may not use this file except in compliance with the License. 5 : You may obtain a copy of the License at 6 : http://www.apache.org/licenses/LICENSE-2.0 7 : Unless required by applicable law or agreed to in writing, software 8 : distributed under the License is distributed on an "AS IS" BASIS, 9 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 : See the License for the specific language governing permissions and 11 : limitations under the License. 12 : 13 : Contributors: Lucian Plesea 14 : */ 15 : 16 : #if !defined(PACKER_H) 17 : #define PACKER_H 18 : #include <cstring> 19 : #include "marfa.h" 20 : 21 : NAMESPACE_MRF_START 22 : 23 : typedef struct storage_manager 24 : { 25 : char *buffer; 26 : size_t size; 27 : } storage_manager; 28 : 29 : // A base class that provides import and export functions based on storage 30 : // managers Default implementation is a straight copy 31 : class Packer 32 : { 33 : public: 34 20 : virtual ~Packer() 35 20 : { 36 20 : } 37 : 38 0 : virtual int load(storage_manager *src, storage_manager *dst) 39 : { 40 0 : if (dst->size < src->size) 41 0 : return false; 42 0 : std::memcpy(dst->buffer, src->buffer, src->size); 43 0 : dst->size -= src->size; // Adjust the destination size 44 0 : return true; 45 : } 46 : 47 0 : virtual int store(storage_manager *src, storage_manager *dst) 48 : { 49 0 : return load(src, dst); 50 : } 51 : }; 52 : 53 : NAMESPACE_MRF_END 54 : #endif