Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019-2023 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19
20#pragma once
21
22#include "../Types.h"
23#include <string>
24#include <locale>
25#include <sstream>
26#include <pluginterfaces/base/ftypes.h>
27#include <base/source/fstring.h>
29
31
35inline std::string toUT8String(VstString16 const &iString)
36{
37 Steinberg::String utf8Str(iString.c_str());
38 utf8Str.toMultiByte(Steinberg::kCP_Utf8);
39 return utf8Str.text8();
40}
41
46template<typename T>
47std::string toUTF8String(T const &iValue, Steinberg::int32 iPrecision)
48{
50 {
51 std::ostringstream s;
52 if(iPrecision >= 0)
53 {
54 s.precision(iPrecision);
55 s.setf(std::ios::fixed);
56 }
57 s << iValue;
58 return s.str();
59 }
60 else
61 return "";
62}
63
66template<typename... Args>
67VstString16 printf16(VstString16 const &iFormat, Args&& ...iArgs)
68{
69 Steinberg::String s;
70 s.printf(iFormat.c_str(), std::forward<Args>(iArgs)...);
71 return s.text16();
72}
73
85template<typename T, typename... Args>
86std::shared_ptr<T> make_sfo(Args&& ...iArgs)
87{
88 auto ptr = new T(std::forward<Args>(iArgs)...);
89 std::shared_ptr<T> sptr(ptr, [](T *p) { p->release(); });
90 return sptr;
91}
92
93}
constexpr auto is_operator_write_to_ostream_defined
Allows to detect whether a type defines ostream << x at compile time.
Definition Metaprogramming.h:115
Definition ExpiringDataCache.h:28
std::string toUT8String(VstString16 const &iString)
Converts a VstString16 to a regular std::string that is properly utf-8 encoded.
Definition Utils.h:35
std::string toUTF8String(T const &iValue, Steinberg::int32 iPrecision)
This generic function will determine (at compilation time) whether T can be written to an ostream and...
Definition Utils.h:47
std::shared_ptr< T > make_sfo(Args &&...iArgs)
The VST SDK uses the concept of FObject (which are self contained reference counted objects) but requ...
Definition Utils.h:86
VstString16 printf16(VstString16 const &iFormat, Args &&...iArgs)
Equivalent to printf but for VstString16.
Definition Utils.h:67
std::basic_string< Steinberg::char16 > VstString16
Strings made of char16 characters are represented by the native C++11 type std::basic_string<Steinber...
Definition Types.h:44