source: XIOS3/trunk/extern/boost_extraction/include/boost_extract.hpp

Last change on this file was 2629, checked in by jderouillat, 2 months ago

Delete boost dependencies, the few features used are replaced by functions stored in extern/boost_extraction

File size: 3.0 KB
Line 
1
2#ifndef __BOOST_EXTRACT_HPP__
3#define __BOOST_EXTRACT_HPP__
4
5#include <string>
6#include <regex>
7#include <utility>
8#include <algorithm>
9#include <cassert>
10
11
12#if defined( XIOS_DISABLE_CURRENT_FUNCTION )
13
14# define XIOS_CURRENT_FUNCTION "(unknown)"
15
16#elif defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
17
18# define XIOS_CURRENT_FUNCTION __PRETTY_FUNCTION__
19
20#elif defined(__DMC__) && (__DMC__ >= 0x810)
21
22# define XIOS_CURRENT_FUNCTION __PRETTY_FUNCTION__
23
24#elif defined(__FUNCSIG__)
25
26# define XIOS_CURRENT_FUNCTION __FUNCSIG__
27
28#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
29
30# define XIOS_CURRENT_FUNCTION __FUNCTION__
31
32#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
33
34# define XIOS_CURRENT_FUNCTION __FUNC__
35
36#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
37
38# define XIOS_CURRENT_FUNCTION __func__
39
40#elif defined(__cplusplus) && (__cplusplus >= 201103)
41
42# define XIOS_CURRENT_FUNCTION __func__
43
44#else
45
46# define XIOS_CURRENT_FUNCTION "(unknown)"
47
48#endif
49
50
51template <class Target,class Source>
52inline Target xios_polymorphic_downcast(Source* x)
53{
54    //BOOST_ASSERT( dynamic_cast<Target>(x) == x );  // detect logic error
55    assert( dynamic_cast<Target>(x) == x );  // detect logic error
56    return static_cast<Target>(x);
57}
58
59inline std::string xios_trim_copy(const std::string &s) {
60    std::regex pattern("^\\s+|\\s+$");
61    return std::regex_replace(s, pattern, "");
62}
63
64inline std::string xios_to_lower_copy(const std::string& input,
65    const std::locale& loc = std::locale())
66{
67    auto const& facet = std::use_facet<std::ctype<char>>(loc);
68
69    std::string out;
70    out.reserve(input.size());
71
72    std::transform(input.begin(), input.end(), std::back_inserter(out),
73        [&facet](unsigned char c) { return facet.tolower(c); });
74
75    return out;
76}
77
78template <class SequenceSequenceT>
79inline void xios_split(SequenceSequenceT& retvalue, std::string value, std::string del)
80{
81    //std::vector<std::string> v;
82    const char* delimiter( del.c_str() );
83    std::string accum;
84    for (auto f = begin(value), l = end(value); f != l;) {
85        while (f!=l && *f==delimiter[0]) {
86            ++f;
87            retvalue.push_back(std::move(accum));
88            accum="";
89            //std::swap(accum, v.emplace_back());
90        }
91        while (f != l && *f != delimiter[0])
92            accum += *f++;
93    }
94    retvalue.push_back(std::move(accum));
95}
96
97inline void xios_replace_all(std::string & data, std::string toSearch, std::string replaceStr)
98{
99    // Get the first occurrence
100    size_t pos = data.find(toSearch);
101    // Repeat till end is reached
102    while( pos != std::string::npos)
103    {
104        // Replace this occurrence of Sub String
105        data.replace(pos, toSearch.size(), replaceStr);
106        // Get the next occurrence from the current position
107        pos =data.find(toSearch, pos + replaceStr.size());
108    }
109}
110
111
112#endif // __BOOST_EXTRACT_HPP__
Note: See TracBrowser for help on using the repository browser.