Version: 9.15.0
SUIT_extensions.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2025 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 #ifndef SUIT_TOOLS_EXTENSIONS_H
24 #define SUIT_TOOLS_EXTENSIONS_H
25 
26 #include "../SUIT.h"
27 #include <cstddef>
28 #include <limits>
29 #include <string>
30 #include <QString>
31 
32 
33 namespace SUIT_tools {
34 
37  template <class Iterator>
38  SUIT_EXPORT std::size_t distance(
39  const Iterator& theStartIt,
40  const Iterator& theFinalIt
41  ) {
42  auto it = theStartIt;
43  std::size_t distance = 0;
44  while (distance <= std::numeric_limits<typename std::iterator_traits<Iterator>::difference_type>::max()) {
45  if (it == theFinalIt)
46  return distance;
47 
48  it++;
49  distance++;
50  }
51  return distance;
52  }
53 
56  template <class Container>
58  const Container& theContainer,
59  const typename Container::const_iterator& theIt
60  ) {
61  auto it = theContainer.begin();
62  std::size_t distance = 0;
63  while (it != theContainer.end()) {
64  if (it == theIt)
65  return distance;
66 
67  it++;
68  distance++;
69  }
70  return std::numeric_limits<std::size_t>::infinity();
71  }
72 
74  SUIT_EXPORT QString substituteBashVars(const QString& theString);
75 
77  SUIT_EXPORT QString substituteDOSVars(const QString& theString);
78 
80  SUIT_EXPORT QString substituteVars(const QString& theString);
81 
82  SUIT_EXPORT std::wstring to_wstring(const std::string& theStdString);
83 
84 } //namespace SUIT_tools
85 
86 #endif //SUIT_TOOLS_EXTENSIONS_H
87 
#define SUIT_EXPORT
Definition: SUIT.h:36
Definition: SUIT_ShortcutMgr.h:950
std::size_t distance(const Iterator &theStartIt, const Iterator &theFinalIt)
Compensates lack of std::distance(..) prior to C++17. Does not check whether the iterators iterate th...
Definition: SUIT_extensions.h:38
QString substituteVars(const QString &theString)
Replaces all Bash- and DOS- style variables with values of corresponding environment variables.
Definition: SUIT_extensions.cxx:63
QString substituteDOSVars(const QString &theString)
Replaces all DOS-style variables (enlosed with "%") with values of corresponding environment variable...
Definition: SUIT_extensions.cxx:48
std::size_t distanceFromBegin(const Container &theContainer, const typename Container::const_iterator &theIt)
Definition: SUIT_extensions.h:57
std::wstring to_wstring(const std::string &theStdString)
Definition: SUIT_extensions.cxx:69
QString substituteBashVars(const QString &theString)
Replaces all Bash-style variables (enlosed with "${" and "}") with values of corresponding environmen...
Definition: SUIT_extensions.cxx:32