SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_string_view.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_string_view.h -- Non-owning, constant reference to a character string
23 */
39 #ifndef SYSC_UTILS_STRING_VIEW_H_INCLUDED_
40 #define SYSC_UTILS_STRING_VIEW_H_INCLUDED_
41 
42 #include <sysc/kernel/sc_cmnhdr.h>
43 
44 #if SC_CPLUSPLUS >= 201402L && defined(__has_include)
45 # if SC_CPLUSPLUS > 201402L && __has_include(<string_view>) /* since C++17 */
46 # define SC_STRING_VIEW_NS_ std
47 # include <string_view>
48  /* available in Library Fundamentals, ISO/IEC TS 19568:2015 */
49 # elif __has_include(<experimental/string_view>)
50 # define SC_STRING_VIEW_NS_ std::experimental
51 # include <experimental/string_view>
52 # endif
53 #else
54 // TODO: other ways to detect availability of std::(experimental::)string_view?
55 #endif
56 
57 #ifndef SC_STRING_VIEW_NS_
58 // fallback to (mostly compatible) implementation from Boost
59 # include <sysc/packages/boost/utility/string_view.hpp>
60 # define SC_STRING_VIEW_NS_ sc_boost
61 #endif // Boost fallback
62 
63 namespace sc_core {
64 
66 typedef SC_STRING_VIEW_NS_::string_view sc_string_view;
67 // TODO: add ABI guard against inconsistent configurations
68 
70 class sc_zstring_view : public sc_string_view
71 {
72 public:
73  /* constexpr */ sc_zstring_view() /* noexcept */
74  : sc_string_view() {}
75 
76  /* constexpr */ sc_zstring_view(const char* s) /* noexcept */
77  : sc_string_view(s) {}
78 
79  sc_zstring_view(const std::string& s) /* noexcept */
80  : sc_string_view(s) {}
81 
82  /* constexpr */ void swap(sc_zstring_view& s) /* noexcept */
83  { sc_string_view::swap(s); }
84 
85  /* constexpr */ const char* c_str() const /* noexcept */
86  { return data(); }
87 
88 private:
89  // Hide invariant-breaking function
90  using sc_string_view::remove_suffix;
91 }; // class sc_zstring_view
92 
93 } // namespace sc_core
94 
95 #undef SC_STRING_VIEW_NS_
96 #endif // SYSC_UTILS_STRING_VIEW_H_INCLUDED_
97 // Taf!
sc_zstring_view(const std::string &s)
const char * c_str() const
SC_STRING_VIEW_NS_::string_view sc_string_view
non-owning, constant reference to a string (implementation-defined)
non-owning, const-ref to null-terminated string (implementation-defined)
sc_zstring_view(const char *s)
void swap(sc_zstring_view &s)