From 46bdb8cdbc14f61eb31bf32728e034cbead96a17 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 23 Nov 2012 13:27:40 +0000 Subject: [PATCH] Implementation of "setExtension" method and working with stream (by Daniel remarks) --- src/Container/SALOME_DataContainerPy.py | 24 ++++++--- src/Container/SALOME_DataContainer_i.cxx | 66 ++++++++++++++++-------- src/Container/SALOME_DataContainer_i.hxx | 9 ++++ 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/src/Container/SALOME_DataContainerPy.py b/src/Container/SALOME_DataContainerPy.py index ea2808c26..65b7d02e0 100755 --- a/src/Container/SALOME_DataContainerPy.py +++ b/src/Container/SALOME_DataContainerPy.py @@ -49,25 +49,32 @@ class SALOME_DataContainerPy_i (Engines__POA.DataContainer): #------------------------------------------------------------------------- - def __init__(self, url, name, identifier, removeAfterGet): - self._url = url + def __init__(self, urlorstream, name, identifier, removeAfterGet, isStream = False): + self._urlorstream = urlorstream self._name = name self._identifier = identifier self._removeAfterGet = removeAfterGet - self._ext = url[url.rfind(".") + 1 : ] + self._isStream = isStream + if isStream: + self._ext = "" + else: + self._ext = urlorstream[urlorstream.rfind(".") + 1 : ] #------------------------------------------------------------------------- def get(self): - f = open(self._url, 'r') + if self._isStream: + return self._urlorstream + + f = open(self._urlorstream, 'r') stream = f.read() f.close() if self._removeAfterGet: - os.remove(self._url) + os.remove(self._urlorstream) try: # try to remove directory if it is empty - index = max(self._url.rfind("\\"), self._url.rfind("/")) + index = max(self._urlorstream.rfind("\\"), self._url.rfind("/")) if index > 0: - os.rmdir(self._url[:index]) + os.rmdir(self._urlorstream[:index]) except: pass return stream @@ -84,3 +91,6 @@ class SALOME_DataContainerPy_i (Engines__POA.DataContainer): def extension(self): return self._ext + + def setExtension(self, ext): + self._ext = ext diff --git a/src/Container/SALOME_DataContainer_i.cxx b/src/Container/SALOME_DataContainer_i.cxx index 2085bd2c1..965b4047c 100644 --- a/src/Container/SALOME_DataContainer_i.cxx +++ b/src/Container/SALOME_DataContainer_i.cxx @@ -40,7 +40,8 @@ Engines_DataContainer_i::Engines_DataContainer_i() Engines_DataContainer_i::Engines_DataContainer_i(const char* url, const char* name, const char* identifier, const bool removeAfterGet) - : myName(name), myIdentifier(identifier), myURL(url), myRemoveAfterGet(removeAfterGet) + : myName(name), myIdentifier(identifier), myURL(url), myRemoveAfterGet(removeAfterGet), + myStream(0) { std::string anExtension(url); if (anExtension.rfind(".") != std::string::npos) { // keep only extension @@ -48,42 +49,60 @@ Engines_DataContainer_i::Engines_DataContainer_i(const char* url, } else myExt = ""; } +Engines_DataContainer_i::Engines_DataContainer_i(char* stream, + const int streamSize, const char* name, const char* identifier, const bool removeAfterGet) + : myName(name), myIdentifier(identifier), myRemoveAfterGet(removeAfterGet), + myStream(stream), myStreamSize(streamSize), myExt("") +{ +} + Engines_DataContainer_i::~Engines_DataContainer_i() { } Engines::TMPFile* Engines_DataContainer_i::get() { - // open file to make stream from its content + char* aBuffer = NULL; + int aFileSize = 0; + if (myStream) { // send from stream + aBuffer = myStream; + aFileSize = myStreamSize; + } else { // send from file + // open file to make stream from its content #ifdef WIN32 - ifstream aFile(myURL.c_str(), std::ios::binary); + ifstream aFile(myURL.c_str(), std::ios::binary); #else - ifstream aFile(myURL.c_str()); + ifstream aFile(myURL.c_str()); #endif - if (!aFile.good()) { - std::cerr<<"File "<