_tmp_files.clear();
}
-/*
-std::string Engines_Container_i::AnotherMethodeToReplace_PyString_AsString(PyObject * result)
-{
- std::string my_result = "";
- if (PyUnicode_Check(result)) {
- // Convert string to bytes.
- // strdup() bytes into my_result.
- PyObject * temp_bytes = PyUnicode_AsEncodedString(result, "ASCII", "strict"); // Owned reference
- if (temp_bytes != NULL) {
- my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
- my_result = strdup(my_result);
- Py_DECREF(temp_bytes);
- } else {
- // TODO PY3: Handle encoding error.
- Py_DECREF(temp_bytes);
- }
+static Engines_Container_i *_container_singleton_ssl = nullptr;
- } else if (PyBytes_Check(result)) {
- // strdup() bytes into my_result.
- my_result = PyBytes_AS_STRING(result); // Borrowed pointer
- my_result = strdup(my_result);
- } else {
- // Convert into your favorite string representation.
- // Convert string to bytes if it is not already.
- // strdup() bytes into my_result.
- // TODO PY3: Check if only bytes is ok.
- PyObject * temp_bytes = PyObject_Bytes(result); // Owned reference
- if (temp_bytes != NULL) {
- my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
- my_result = strdup(my_result);
- Py_DECREF(temp_bytes);
- } else {
- // TODO PY3: Handle error.
- Py_DECREF(temp_bytes);
- }
- }
- return my_result;
-}
-*/
+static PortableServer::ObjectId_var _container_id_singleton_ssl;
-static Engines_Container_i *_container_singleton_ssl = nullptr;
+static Engines::Container_var _container_ref_singleton_ssl;
-Engines_Container_i *KERNEL::getContainerIdSA()
+Engines_Container_i *KERNEL::getContainerSA()
{
-
if(!_container_singleton_ssl)
{
- int argc(0); orb = CORBA::ORB_init(argc,nullptr); }
+ int argc(0);
+ CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
PortableServer::POAManager_var pman = poa->the_POAManager();
policies.length(0);
PortableServer::ObjectId_var conId;
//
- {
- char *argv[4] = {"Container","FactoryServer","toto",nullptr};
- _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,false,false);
- conId = poa->activate_object(_container_singleton_ssl);
- }
+ char *argv[4] = {"Container","FactoryServer","toto",nullptr};
+ _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,false,false);
+ _container_id_singleton_ssl = poa->activate_object(_container_singleton_ssl);
+ //
+ CORBA::Object_var zeRef = poa->id_to_reference(_container_id_singleton_ssl);
+ _container_ref_singleton_ssl = Engines::Container::_narrow(zeRef);
}
-CORBA::ORB_var orb;
+ return _container_singleton_ssl;
+}
+
+PortableServer::ObjectId_var KERNEL::getContainerIdSA()
+{
+ getContainerSA();
+ return _container_id_singleton_ssl;
+}
+
+Engines::Container_var KERNEL::getContainerRefSA()
+{
+ getContainerSA();
+ return _container_ref_singleton_ssl;
+}
+
+/*CORBA::ORB_var orb;
{ int argc(0); orb = CORBA::ORB_init(argc,nullptr); }
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
Engines::Container_var KERNEL::getContainerRefSA()
{
-}
+}*/
*/
namespace KERNEL
{
- CONTAINER_EXPORT Engines_Container_i *getContainerIdSA();
+ CONTAINER_EXPORT Engines_Container_i *getContainerSA();
CONTAINER_EXPORT PortableServer::ObjectId_var getContainerIdSA();
CONTAINER_EXPORT Engines::Container_var getContainerRefSA();
}
return oss_.str();
}
- // Surtout ne pas écrire le code suivant:
+ // Surtout ne pas �crire le code suivant:
// car oss_.str() renvoie une string temporaire
// operator const char*()
// {
}; /* end class OSS */
#endif
-
-// Cette fonction provient de Utils_SALOME_Exception
-// Solution pas très élégante mais contrainte par les manques de la classe SALOME_Exception
-const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber);
-
struct DSC_Exception : public SALOME_Exception {
- // Attention, en cas de modification des paramètres par défaut
+ // Attention, en cas de modification des param�tres par d�faut
// il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous
// Le constructeur de la SALOME_Exception demande une chaine non vide
- // Du coup on est obliger de la désallouer avant d'y mettre la notre
+ // Du coup on est obliger de la d�sallouer avant d'y mettre la notre
// car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text
// soit utilisable.
- // Ne pas mettre lineNumber=0 à cause du calcul log dans la SALOME_Exception si fileName est défini
+ // Ne pas mettre lineNumber=0 � cause du calcul log dans la SALOME_Exception si fileName est d�fini
DSC_Exception( const std::string & text,
const char *fileName="",
const unsigned int lineNumber=0,
const char *funcName="" ):
- SALOME_Exception(text.c_str()) ,
+ SALOME_Exception(text) ,
_dscText(text),
_filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
_lineNumber(lineNumber),
_exceptionName("DSC_Exception")
{
- // Mise en cohérence avec l'exception SALOME (à revoir)
- delete [] ((char*)SALOME_Exception::_text);
if (! _filefuncName.empty() )
SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
else
return _what.c_str() ;
}
- // L'opérateur = de SALOME_Exception n'est pas défini
- // problème potentiel concernant la recopie de son pointeur _text
+ // L'op�rateur = de SALOME_Exception n'est pas d�fini
+ // probl�me potentiel concernant la recopie de son pointeur _text
- // Le destructeur de la SALOME_Exception devrait être virtuel
+ // Le destructeur de la SALOME_Exception devrait �tre virtuel
// sinon pb avec nos attributs de type pointeur.
virtual ~DSC_Exception(void) noexcept {};
virtual ~Derived(void) noexcept;\
};\
-//Sert à eviter le problème d'identification RTTI des exceptions
-//Crée un unique typeInfo pour tous les bibliothèques composants SALOME
+//Sert � eviter le probl�me d'identification RTTI des exceptions
+//Cr�e un unique typeInfo pour tous les biblioth�ques composants SALOME
//dans un fichier cxx
#define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) noexcept {}
//
#include "SALOME_Fake_NamingService.hxx"
+#include "Utils_SALOME_Exception.hxx"
SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb))
{
CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path)
{
std::string pathCpp(Path);
- if(pathCpp == )
+ auto it = _map.find(pathCpp);
+ if( it != _map.end() )
+ return (*it).second;
+ THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::Resolve : no such entry \"" << Path << "\" !");
}
# include <iostream>
# include "utilities.h"
# include "Utils_Identity.hxx"
+# include <cstring>
extern "C"
{
-# include <string.h>
-
#ifndef WIN32 /* unix functionality */
# include <pwd.h>
#endif
// Module : SALOME
// $Header$
//
-#include <iostream>
#include "Utils_SALOME_Exception.hxx"
#include "utilities.h"
}
#endif
-
-const char* duplicate( const char *const str ) ;
-
-SALOME_Exception::SALOME_Exception( void ): exception() , _text(0)
+std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber)
{
- MESSAGE( "You must use the standard builder: SALOME_Exception::SALOME_Exception( const char *text )" ) ;
- INTERRUPTION(1) ;
+ constexpr char prefix[] = "Salome Exception";
+ std::ostringstream oss;
+ if (fileName)
+ {
+ oss << prefix << " in " << fileName << "[" << lineNumber << "] : " << text;
+ }
+ else
+ {
+ oss << prefix << " : " << text;
+ }
+ return oss.str();
}
-
-
-const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
+SALOME_Exception::SALOME_Exception(const char *text, const char *fileName, const unsigned int lineNumber) : _text(makeText(text, fileName, lineNumber))
{
- char *newText = 0 ;
-
- ASSERT(text) ;
- const size_t l1 = 1+strlen(text) ;
- ASSERT(l1>1) ;
-
- const char* prefix = "Salome Exception" ;
- const size_t l0 = 2+strlen(prefix) ;
-
- if ( fileName )
- {
- const size_t l2 = 4+strlen(fileName) ;
- ASSERT(l2>4) ;
-
- ASSERT(lineNumber>=1) ;
- const size_t l3 = 4+int(log10(float(lineNumber))) ;
-
- newText = new char [ 1+l0+l1+l2+l3 ] ;
- sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
- }
- else
- {
- newText = new char [ 1+l0+l1 ] ;
- sprintf( newText , "%s : %s" , prefix, text ) ;
- }
- ASSERT(newText) ;
- return newText ;
}
-
-SALOME_Exception::SALOME_Exception( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) )
-{
-}
-
-
SALOME_Exception::~SALOME_Exception() noexcept
{
- if ( _text )
- {
- delete [] ((char*)_text);
- char** pRef = (char**)&_text;
- *pRef = 0;
- }
- ASSERT(_text==NULL) ;
-}
-
-
-
-SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text))
-{
- ;
}
-
-std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex )
+std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex)
{
- os << ex._text ;
- return os ;
+ os << ex._text;
+ return os;
}
-
-
-const char* SALOME_Exception::what( void ) const noexcept
+const char *SALOME_Exception::what(void) const noexcept
{
- return _text ;
+ return _text.c_str();
}
// Module : SALOME
// $Header$
//
-#if !defined( __Utils_SALOME_Exception_hxx__ )
-#define __Utils_SALOME_Exception_hxx__
+#pragma once
-//#include "SALOME_Utils.hxx"
-
-# include <exception>
-# include <iostream>
+#include <exception>
+#include <sstream>
+#include <string>
#ifdef LOCALIZED
#undef LOCALIZED
#endif
#if defined(_DEBUG_) || defined(_DEBUG)
-# define LOCALIZED(message) #message , __FILE__ , __LINE__
+#define LOCALIZED(message) #message, __FILE__, __LINE__
#else
-# define LOCALIZED(message) #message
+#define LOCALIZED(message) #message
#endif
//swig tool on Linux doesn't pass defines from header SALOME_Utils.hxx
//therefore (temporary solution) defines are placed below
#ifdef WIN32
-# if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
-# define UTILS_EXPORT __declspec( dllexport )
-# else
-# define UTILS_EXPORT __declspec( dllimport )
-# undef LOCALIZED
-# define LOCALIZED(message) #message
-# endif
+#if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
+#define UTILS_EXPORT __declspec(dllexport)
+#else
+#define UTILS_EXPORT __declspec(dllimport)
+#undef LOCALIZED
+#define LOCALIZED(message) #message
+#endif
#else
-# define UTILS_EXPORT
+#define UTILS_EXPORT
#endif
class SALOME_Exception;
-UTILS_EXPORT std::ostream& operator<<( std::ostream&, const SALOME_Exception& );
+UTILS_EXPORT std::ostream &operator<<(std::ostream &, const SALOME_Exception &);
-UTILS_EXPORT const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber );
+UTILS_EXPORT std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber);
class UTILS_EXPORT SALOME_Exception : public std::exception
{
+protected:
+ std::string _text;
+public:
+ SALOME_Exception() = delete;
+ SALOME_Exception(const std::string& text):_text(text) { }
+ SALOME_Exception(const char *text, const char *fileName = nullptr, const unsigned int lineNumber = 0);
+ virtual ~SALOME_Exception() noexcept;
+ UTILS_EXPORT friend std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex);
+ virtual const char *what(void) const noexcept;
+};
-private :
- SALOME_Exception( void );
-
-protected :
- const char* _text ; // non constant pointer but read only char variable
-
-public :
- SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 );
- SALOME_Exception( const SALOME_Exception &ex );
- virtual ~SALOME_Exception() noexcept;
- UTILS_EXPORT friend std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex );
- virtual const char *what( void ) const noexcept;
-} ;
-
-
-#endif /* #if !defined( __Utils_SALOME_Exception_hxx__ ) */
+#define THROW_SALOME_EXCEPTION(text) \
+{ \
+ std::ostringstream oss; oss << text; \
+ throw SALOME_Exception(oss.str()); \
+}