From 7f99b7456cf411758b61d5ef1d3a6c02a5511dba Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 19 Nov 2014 14:39:00 +0100 Subject: [PATCH] Imp --- src/SALOMESDS/CMakeLists.txt | 1 + src/SALOMESDS/SalomeSDSClt.py | 177 ++++++++++++++++------------------ 2 files changed, 84 insertions(+), 94 deletions(-) diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index 3b0edeca3..421c27f60 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -50,6 +50,7 @@ INSTALL(TARGETS SalomeSDS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME ADD_EXECUTABLE(SALOME_DataScopeServer SALOME_DataScopeServer.cxx) TARGET_LINK_LIBRARIES(SALOME_DataScopeServer SalomeSDS) INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS}) +INSTALL(FILES SalomeSDSClt.py DESTINATION ${SALOME_INSTALL_BINS}) FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py index 333bb2925..5a12f11b9 100644 --- a/src/SALOMESDS/SalomeSDSClt.py +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -19,11 +19,10 @@ # # Author : Anthony Geay -# dict,list,tuple,int,float,str import SALOME import cPickle -class List(object): +class WrappedType(object): def __init__(self,varPtr,isTemporaryVar=False): assert(isinstance(varPtr,SALOME._objref_StringDataServer)) self._var_ptr=varPtr @@ -32,15 +31,34 @@ class List(object): self._is_temp=isTemporaryVar pass - def __del__(self): - self._var_ptr.UnRegister() - pass + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def __reduce__(self): + return (self._wrapped_type,(self.local_copy(),)) def assign(self,elt): st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) self._var_ptr.setSerializedContent(st) pass + def __del__(self): + self._var_ptr.UnRegister() + pass + pass + +class List(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=list + pass + def __getitem__(self,*args): ret=Caller(self._var_ptr,"__getitem__") return ret(*args) @@ -51,33 +69,16 @@ class List(object): def append(self,*args): ret=Caller(self._var_ptr,"append") - return ret(*args) - - def __str__(self): - return self.local_copy().__str__() - - def __repr__(self): - return self.local_copy().__repr__() - - def local_copy(self): - return cPickle.loads(self._var_ptr.fetchSerializedContent()) - - def __reduce__(self): - return (list,(self.local_copy(),)) + return ret(*args) + def __len__(self): + return len(self.local_copy()) pass -class Tuple(object): +class Tuple(WrappedType): def __init__(self,varPtr,isTemporaryVar=False): - assert(isinstance(varPtr,SALOME._objref_StringDataServer)) - self._var_ptr=varPtr - if not isTemporaryVar: - self._var_ptr.Register() - self._is_temp=isTemporaryVar - pass - - def __del__(self): - self._var_ptr.UnRegister() + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=tuple pass def assign(self,elt): @@ -92,33 +93,35 @@ class Tuple(object): def __setitem__(self,*args): ret=Caller(self._var_ptr,"__setitem__") return ret(*args) + + def __len__(self): + return len(self.local_copy()) - def __str__(self): - return self.local_copy().__str__() + pass - def __repr__(self): - return self.local_copy().__repr__() +class Dict(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=dict + pass - def local_copy(self): - return cPickle.loads(self._var_ptr.fetchSerializedContent()) + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) - def __reduce__(self): - return (tuple,(self.local_copy(),)) + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def __len__(self): + return len(self.local_copy()) pass - -class Int(object): +class Float(WrappedType): def __init__(self,varPtr,isTemporaryVar=False): - assert(isinstance(varPtr,SALOME._objref_StringDataServer)) - self._var_ptr=varPtr - if not isTemporaryVar: - self._var_ptr.Register() - self._is_temp=isTemporaryVar - pass - - def __del__(self): - self._var_ptr.UnRegister() + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=float pass def __iadd__(self,*args): @@ -128,67 +131,52 @@ class Int(object): def __isub__(self,*args): ret=Caller(self._var_ptr,"__sub__") return ret(*args) - - def assign(self,elt): - st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) - self._var_ptr.setSerializedContent(st) - pass - - def __str__(self): - return self.local_copy().__str__() - - def __repr__(self): - return self.local_copy().__repr__() - - def local_copy(self): - return cPickle.loads(self._var_ptr.fetchSerializedContent()) - - def __reduce__(self): - return (int,(self.local_copy(),)) - pass -class Dict(object): +class Int(WrappedType): def __init__(self,varPtr,isTemporaryVar=False): - assert(isinstance(varPtr,SALOME._objref_StringDataServer)) - self._var_ptr=varPtr - if not isTemporaryVar: - self._var_ptr.Register() - self._is_temp=isTemporaryVar - pass - - def __del__(self): - self._var_ptr.UnRegister() + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=int pass - def assign(self,elt): - st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) - self._var_ptr.setSerializedContent(st) - pass + def __iadd__(self,*args): + ret=Caller(self._var_ptr,"__add__") + return ret(*args) - def __getitem__(self,*args): - ret=Caller(self._var_ptr,"__getitem__") + def __isub__(self,*args): + ret=Caller(self._var_ptr,"__sub__") return ret(*args) - def __setitem__(self,*args): - ret=Caller(self._var_ptr,"__setitem__") + def __imul__(self,*args): + ret=Caller(self._var_ptr,"__mul__") return ret(*args) - def __len__(self): - return len(self.local_copy()) + def __idiv__(self,*args): + ret=Caller(self._var_ptr,"__div__") + return ret(*args) - def __str__(self): - return self.local_copy().__str__() + def __add__(self,*args): + ret=Caller(self._var_ptr,"__add__") + return ret(*args) - def __repr__(self): - return self.local_copy().__repr__() + def __sub__(self,*args): + ret=Caller(self._var_ptr,"__sub__") + return ret(*args) - def local_copy(self): - return cPickle.loads(self._var_ptr.fetchSerializedContent()) + def __mul__(self,*args): + ret=Caller(self._var_ptr,"__mul__") + return ret(*args) - def __reduce__(self): - return (dict,(self.local_copy(),)) + def __div__(self,*args): + ret=Caller(self._var_ptr,"__div__") + return ret(*args) + pass +class String(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=int + pass pass class Caller: @@ -203,11 +191,12 @@ class Caller: return GetHandlerFromRef(ret,True) pass -PyHandlerTypeMap={int:Int,list:List,tuple:Tuple,dict:Dict} +PyHandlerTypeMap={int:Int,float:Float,str:String,list:List,tuple:Tuple,dict:Dict} def GetHandlerFromRef(objCorba,isTempVar=False): """ Returns a client that allows to handle a remote corba ref of a global var easily. """ + assert(isinstance(objCorba,SALOME._objref_StringDataServer)) v=cPickle.loads(objCorba.fetchSerializedContent()) if v is None: return None -- 2.39.2