Salome HOME
IPAL52460: Optimal Axes button is inert when edit body fitting parameters
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Utils.h
index 2cf9eaac2896dabd7d51b2b33f3dfeb360afb6c2..d5ec25ed4a7134897d7371269f4a5a69f47d7e8f 100644 (file)
@@ -184,6 +184,30 @@ SMESHGUI_EXPORT
   // type to use instead of SMESH_IDSource_var for automatic UnRegister()
   typedef SALOME::GenericObj_wrap<SMESH_IDSource> 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