X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_Utils.h;h=d5ec25ed4a7134897d7371269f4a5a69f47d7e8f;hp=2cf9eaac2896dabd7d51b2b33f3dfeb360afb6c2;hb=52f164fb658ee0f92803649489757c52dbcb1ef3;hpb=5d68554076bbca0e1e95fb0db215a6c2b84b6c54 diff --git a/src/SMESHGUI/SMESHGUI_Utils.h b/src/SMESHGUI/SMESHGUI_Utils.h index 2cf9eaac2..d5ec25ed4 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) {} + }; + class toStdStr : public toStrT< std::string > { + toStdStr( char* s ): toStrT< std::string >(s) {} + }; + } #endif // SMESHGUI_UTILS_H