1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME DataContainer : implementation of data container
24 // File : SALOME_DataContainer_i.cxx
25 // Author : Mikhail PONIKAROV
30 #include "SALOME_DataContainer_i.hxx"
39 Engines_DataContainer_i::Engines_DataContainer_i()
43 Engines_DataContainer_i::Engines_DataContainer_i(const char* url,
44 const char* name, const char* identifier, const bool removeAfterGet)
45 : myName(name), myIdentifier(identifier), myURL(url), myRemoveAfterGet(removeAfterGet),
48 std::string anExtension(url);
49 if (anExtension.rfind(".") != std::string::npos) { // keep only extension
50 myExt = anExtension.substr(anExtension.rfind(".") + 1);
54 Engines_DataContainer_i::Engines_DataContainer_i(char* stream,
55 const int streamSize, const char* name, const char* identifier, const bool removeAfterGet)
56 : myName(name), myIdentifier(identifier), myRemoveAfterGet(removeAfterGet),
57 myStream(stream), myStreamSize(streamSize), myExt("")
61 Engines_DataContainer_i::~Engines_DataContainer_i()
65 Engines::TMPFile* Engines_DataContainer_i::get()
69 if (myStream) { // send from stream
71 aFileSize = myStreamSize;
72 } else { // send from file
73 // open file to make stream from its content
75 ifstream aFile(myURL.c_str(), std::ios::binary);
77 ifstream aFile(myURL.c_str());
80 std::cerr<<"File "<<myURL.c_str()<<" can not be opened for reading"<<std::endl;
82 aFile.seekg(0, std::ios::end);
83 aFileSize = aFile.tellg();
84 aBuffer = new char[aFileSize];
86 aFile.seekg(0, std::ios::beg);
87 aFile.read(aBuffer, aFileSize);
90 // remove file after it converted to a stream
91 // also remove directory of the file if it is empty
92 if (myRemoveAfterGet) {
93 string aDirName = myURL.substr(0, myURL.find_last_of("/\\"));
95 DeleteFile(myURL.c_str());
96 RemoveDirectory(aDirName.c_str());
98 unlink(myURL.c_str());
99 rmdir(aDirName.c_str());
105 // make CORBA TMP file from the buffer
106 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
107 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aFileSize, aFileSize, anOctetBuf, 1);
109 if (myStream && myRemoveAfterGet)
112 return aStreamFile._retn();
115 char* Engines_DataContainer_i::name()
117 return CORBA::string_dup(myName.c_str());
120 char* Engines_DataContainer_i::identifier()
122 return CORBA::string_dup(myIdentifier.c_str());
125 char* Engines_DataContainer_i::extension()
127 return CORBA::string_dup(myExt.c_str());
130 void Engines_DataContainer_i::setExtension(const char* theExt)