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"
29 virtual ~TFileInternal() = default;
30 virtual void Open(EModeAcces theMode, TErr* theErr = nullptr) = 0;
31 virtual void Close() = 0;
32 virtual const TIdt& Id() const = 0;
35 class MEDIDTHoder : public TFileInternal
38 MEDIDTHoder(bool *isClosedStatus = nullptr):_isClosedStatus(isClosedStatus) { }
46 *_isClosedStatus = true;
50 const TIdt& Id() const override;
51 ~MEDIDTHoder() { this->UnRefFid(); }
52 void Close() override { this->UnRefFid(); }
56 bool myIsClosed = false;
57 bool *_isClosedStatus = nullptr;
60 class TFileDecorator : public TFileInternal
63 TFileDecorator(TFileInternal *effective):_effective(effective) { }
64 void Open(EModeAcces theMode, TErr* theErr = nullptr) override { if(_effective) _effective->Open(theMode,theErr); }
65 void Close() override { if(_effective) _effective->Close(); }
66 const TIdt& Id() const override { if(_effective) return _effective->Id(); EXCEPTION(std::runtime_error, "TFileDecorator - GetFid() : no effective TFile !"); }
67 ~TFileDecorator() { delete _effective; }
69 TFileInternal *_effective = nullptr;
72 class TMemFile : public MEDIDTHoder
75 TMemFile(bool* isClosedStatus = nullptr):MEDIDTHoder(isClosedStatus) { }
76 void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
77 void *getData() const { return memfile.app_image_ptr; }
78 std::size_t getSize() const { return memfile.app_image_size; }
80 med_memfile memfile = MED_MEMFILE_INIT;
83 class TFile : public MEDIDTHoder
86 TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1);
87 void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
89 std::string myFileName;