]> SALOME platform Git repositories - modules/shaper.git/blob - src/Events/Events_InfoMessage.cpp
Salome HOME
Task #3237: Allow usage of accented characters in ObjectBrowser
[modules/shaper.git] / src / Events / Events_InfoMessage.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "Events_InfoMessage.h"
21 #include <sstream>
22
23 // To support old types of GCC (less than 5.0), check the wide-string conversion is working
24 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)  && \
25     (__cplusplus >= 201402L || !defined(__GLIBCXX__)   || \
26     (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4))
27 #define HAVE_WORKING_WIDESTRING 1
28 #else
29 #define HAVE_WORKING_WIDESTRING 0
30 #endif
31
32 #if HAVE_WORKING_WIDESTRING
33 #include <codecvt>
34 #endif
35
36 void Events_InfoMessage::addParameter(double theParam)
37 {
38   std::stringstream aStream;
39   aStream << theParam;
40   myParameters.push_back(aStream.str());
41 }
42
43 void Events_InfoMessage::addParameter(int theParam)
44 {
45   std::stringstream aStream;
46   aStream << theParam;
47   myParameters.push_back(aStream.str());
48 }
49
50 void Events_InfoMessage::send()
51 {
52   std::shared_ptr<Events_Message> aMsg(new Events_InfoMessage(*this));
53   Events_Loop::loop()->send(aMsg);
54 }
55
56 Events_InfoMessage& Events_InfoMessage::arg(const std::wstring& theParam)
57 {
58 #if HAVE_WORKING_WIDESTRING
59   static std::wstring_convert<std::codecvt_utf8<wchar_t> > aConvertor;
60   addParameter(aConvertor.to_bytes(theParam));
61 #else
62   char* aBuf = new char[2 * (theParam.size() + 1)];
63   size_t aNbChars = std::wcstombs(aBuf, theParam.c_str(), theParam.size());
64   if (aNbChars != (size_t)-1)
65     aBuf[aNbChars] = '\0';
66   addParameter(aBuf);
67   delete[] aBuf;
68 #endif
69   return *this;
70 }