X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSMESHGUI%2FSMESHGUI_Utils.h;h=5ac9ee97cfbd402878949c76a0e44dede4930078;hb=333b8ff2fb70f855dadfef145d7b13ebdf07f2cd;hp=2cf9eaac2896dabd7d51b2b33f3dfeb360afb6c2;hpb=b0a908c0d20341651771d0249fb10882f54b2aad;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_Utils.h b/src/SMESHGUI/SMESHGUI_Utils.h index 2cf9eaac2..5ac9ee97c 100644 --- a/src/SMESHGUI/SMESHGUI_Utils.h +++ b/src/SMESHGUI/SMESHGUI_Utils.h @@ -184,6 +184,30 @@ SMESHGUI_EXPORT // type to use instead of SMESH_IDSource_var for automatic UnRegister() typedef SALOME::GenericObj_wrap SMESH_IDSource_wrap; + /*! + * \brief Class usefull to convert a string returned from a CORBA call + * to other string types w/o memory leak. + * + * Usage (of instantiations): QString s = toQStr( objVar->GetName() ); + * std::string ss = toStdStr( objVar->GetName() ); + */ + template < class _STRING > + class toStrT : public _STRING { + CORBA::String_var myStr; + public: + toStrT( char* s ): myStr(s), _STRING( s ) + {} + operator const char*() const + { return myStr.in(); } + }; + // Instantiations: + struct toQStr : public toStrT< QString > { + toQStr( char* s ): toStrT< QString >(s) {} + }; + struct toStdStr : public toStrT< std::string > { + toStdStr( char* s ): toStrT< std::string >(s) {} + }; + } #endif // SMESHGUI_UTILS_H