1 // Copyright (C) 2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MED_Wrapper.hxx"
23 #include "MED_WrapperDef.hxx"
30 virtual ~TFileInternal() = default;
31 virtual void Open(EModeAcces theMode, TErr* theErr = nullptr) = 0;
32 virtual void Close() = 0;
33 virtual const TIdt& Id() const = 0;
36 class MEDWRAPPER_EXPORT MEDIDTHoder : public TFileInternal
39 MEDIDTHoder(bool *isClosedStatus = nullptr):_isClosedStatus(isClosedStatus) { }
47 *_isClosedStatus = true;
51 const TIdt& Id() const override;
52 ~MEDIDTHoder() { this->UnRefFid(); }
53 void Close() override { this->UnRefFid(); }
57 bool myIsClosed = false;
58 bool *_isClosedStatus = nullptr;
61 class MEDWRAPPER_EXPORT TFileDecorator : public TFileInternal
64 TFileDecorator(TFileInternal *effective):_effective(effective) { }
65 void Open(EModeAcces theMode, TErr* theErr = nullptr) override { if(_effective) _effective->Open(theMode,theErr); }
66 void Close() override { if(_effective) _effective->Close(); }
67 const TIdt& Id() const override { if(_effective) return _effective->Id(); EXCEPTION(std::runtime_error, "TFileDecorator - GetFid() : no effective TFile !"); }
68 ~TFileDecorator() { delete _effective; }
70 TFileInternal *_effective = nullptr;
73 class MEDWRAPPER_EXPORT TMemFile : public MEDIDTHoder
76 TMemFile(void **data, std::size_t *sz, bool* isClosedStatus):MEDIDTHoder(isClosedStatus),_data(data),_sz(sz) { memfile.app_image_ptr=*data; memfile.app_image_size=*sz; }
77 ~TMemFile() { UnRefFid(); if(myIsClosed) { *_data = memfile.app_image_ptr; *_sz = memfile.app_image_size; } }
78 void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
79 void *getData() const { return memfile.app_image_ptr; }
80 std::size_t getSize() const { return memfile.app_image_size; }
82 void **_data = nullptr;
83 std::size_t * _sz = nullptr;
84 med_memfile memfile = MED_MEMFILE_INIT;
87 class MEDWRAPPER_EXPORT TFile : public MEDIDTHoder
90 TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1);
91 void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
93 std::string myFileName;