Salome HOME
add method NameChanged to update title name
[modules/kernel.git] / src / SALOMESDS / SALOMESDS_PickelizedPyObjServer.cxx
index 2989150d486b79632d2f8171f22ca44c1e0f2e32..7de5f2c2b7b5433ae3acbbbfe486dae55653949d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -72,24 +72,14 @@ void PickelizedPyObjServer::checkKeyPresent(PyObject *key)
 
 void PickelizedPyObjServer::addKeyValueHard(PyObject *key, PyObject *value)
 {
-  bool isOK(PyDict_SetItem(_self,key,value)==0);
-  if(!isOK)
-    throw Exception("PickelizedPyObjServer::addKeyValueHard : error when trying to add key,value to dict !");
-}
-
-void PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value)
-{
-  checkKeyNotAlreadyPresent(key);
-  bool isOK(PyDict_SetItem(_self,key,value)==0);
-  if(!isOK)
-    throw Exception("PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !");
+  std::ostringstream oss; oss << "PickelizedPyObjServer::addKeyValueHard : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !";
+  throw Exception(oss.str());
 }
 
 void PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key)
 {
-  checkKeyPresent(key);
-  if(PyDict_DelItem(_self,key)!=0)
-    throw Exception("PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !");
+  std::ostringstream oss; oss << "PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !";
+  throw Exception(oss.str());
 }
 
 void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
@@ -101,14 +91,19 @@ void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv,
     buf[i]=bsToBeConv[i];
 }
 
-SALOME::ByteVec *PickelizedPyObjServer::FromCppToByteSeq(const std::string& strToBeConv)
+void PickelizedPyObjServer::FromCppToByteSeq(const std::string& strToBeConv, SALOME::ByteVec& ret)
 {
-  SALOME::ByteVec *ret(new SALOME::ByteVec);
   const char *buf(strToBeConv.c_str());
   std::size_t sz(strToBeConv.size());
-  ret->length(sz);
+  ret.length(sz);
   for(std::size_t i=0;i<sz;i++)
-    (*ret)[i]=buf[i];
+    ret[i]=buf[i];
+}
+
+SALOME::ByteVec *PickelizedPyObjServer::FromCppToByteSeq(const std::string& strToBeConv)
+{
+  SALOME::ByteVec *ret(new SALOME::ByteVec);
+  FromCppToByteSeq(strToBeConv,*ret);
   return ret;
 }
 
@@ -259,3 +254,26 @@ void PickelizedPyObjServer::checkKeyPresence(PyObject *key, bool presence)
     }
   Py_XDECREF(retPy);
 }
+
+PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+{
+}
+
+PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+{
+}
+
+void PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value)
+{
+  checkKeyNotAlreadyPresent(key);
+  bool isOK(PyDict_SetItem(_self,key,value)==0);
+  if(!isOK)
+    throw Exception("PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !");
+}
+
+void PickelizedPyObjServerModifiable::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key)
+{
+  checkKeyPresent(key);
+  if(PyDict_DelItem(_self,key)!=0)
+    throw Exception("PickelizedPyObjServerModifiable::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !");
+}