Mako 8.2.0 API
MakoCore SDK API Documentation
Loading...
Searching...
No Matches
edlstring.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007-2025 Global Graphics Software Ltd. All rights reserved.
3 */
4
11
12#ifndef EDLSTRING_H
13#define EDLSTRING_H
14
15#include <string>
16#include <sstream>
17#include <limits>
18#ifdef ANDROID
19#include <ctype.h>
20#endif
21#include <edl/platform.h>
22#include <edl/edltypes.h>
23#include <edl/edlvector.h>
24
26
27#if defined(_WIN32) && !defined(SWIG_BINDINGS)
28# define USE_EDL_ALLOCATOR
29#endif
30
31#ifdef USE_EDL_ALLOCATOR
32
33// An STL Allocator, used for strings to allow
34// strings to be passed between DLLs that use
35// statically-linked runtimes.
36
37EDL_API void *edlStringAlloc(size_t);
38EDL_API void edlStringFree(void*);
39template <class T>
40class CEDLStringAllocator
41{
42 public:
43 inline CEDLStringAllocator()
44 {
45 allocFunc = edlStringAlloc;
46 freeFunc = edlStringFree;
47 }
48 CEDLStringAllocator(CEDLStringAllocator const &r)
49 {
50 allocFunc = r.allocFunc;
51 freeFunc = r.freeFunc;
52 }
53 template <class U>
54 inline explicit CEDLStringAllocator(CEDLStringAllocator<U> const &r)
55 {
56 allocFunc = r.allocFunc;
57 freeFunc = r.freeFunc;
58 }
59 inline ~CEDLStringAllocator() {}
60
61 public:
62 void *(*allocFunc)(size_t);
63 void (*freeFunc)(void*);
64
65 public:
66 typedef T value_type;
67 typedef T* pointer;
68 typedef const T* const_pointer;
69 typedef T& reference;
70 typedef const T& const_reference;
71 typedef std::size_t size_type;
72 typedef std::ptrdiff_t difference_type;
73
74 template <class U>
75 struct rebind
76 {
77 typedef CEDLStringAllocator<U> other;
78 };
79
80 inline pointer address (reference v) const { return &v; }
81 const_pointer address (const_reference v) const { return &v; }
82 size_type max_size () const
83 {
84#undef max
85 return std::numeric_limits<std::size_t>::max() / sizeof(T);
86 }
87
88 pointer allocate (size_type n, const void * = 0)
89 {
90 pointer p = (pointer) allocFunc(n * sizeof(T));
91 if (!p)
92 throw std::bad_alloc();
93 return p;
94 }
95 void deallocate (pointer p, size_type)
96 {
97 freeFunc(p);
98 }
99
100 void construct (pointer p, const T& v)
101 {
102 new ((void*)p) T(v);
103 }
104
105 void destroy (pointer p)
106 {
107 p->~T();
108 }
109};
110
111template <typename T, typename U>
112bool operator== (CEDLStringAllocator<T> const &l, CEDLStringAllocator<U> const &r)
113{
114 return (l.freeFunc == r.freeFunc);
115}
116
117template<typename T, typename U>
118bool operator!= (CEDLStringAllocator<T> const &l, CEDLStringAllocator<U> const &r)
119{
120 return (l.freeFunc != r.freeFunc);
121}
122
123#endif
124
125
126// Basic EDLString types, be careful about the make assumptions about the size of wchar_t
127// on Windows it's 2 bytes, on Linux and OSX it's 4 bytes
128
129#ifdef _WIN32
130typedef wchar_t u16char;
131typedef char32_t u32char;
132#elif defined(ANDROID)
133typedef uint16_t u16char;
134typedef wchar_t u32char;
135#else
136typedef char16_t u16char;
137typedef wchar_t u32char;
138#endif
139
140
141
142#if defined(USE_EDL_ALLOCATOR) && defined(_WIN32)
143
144
145typedef std::basic_string<char, std::char_traits<char>, CEDLStringAllocator<char> > EDLSysString;
146typedef std::basic_istringstream<char, std::char_traits<char>, CEDLStringAllocator<char> > EDLSysStringIStream;
147typedef std::basic_ostringstream<char, std::char_traits<char>, CEDLStringAllocator<char> > EDLSysStringOStream;
148
149typedef std::basic_string<u16char, std::char_traits<u16char>, CEDLStringAllocator<u16char> > EDLU16String;
150typedef std::basic_string<u32char, std::char_traits<u32char>, CEDLStringAllocator<u32char> > EDLU32String;
151
152typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, CEDLStringAllocator<wchar_t> > EDLString;
153typedef std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, CEDLStringAllocator<wchar_t> > EDLStringIStream;
154typedef std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, CEDLStringAllocator<wchar_t> > EDLStringOStream;
155
156#else
157
158typedef std::string EDLSysString;
159typedef std::istringstream EDLSysStringIStream;
160typedef std::ostringstream EDLSysStringOStream;
161
162typedef std::basic_string<u16char> EDLU16String;
163typedef std::basic_string<u32char> EDLU32String;
164
165typedef std::wstring EDLString;
166typedef std::wistringstream EDLStringIStream;
167typedef std::wostringstream EDLStringOStream;
168
169#endif
170
172
176
177
178inline bool equal(const EDLSysString &str1,const EDLSysString &str2) { return (str1 == str2); }
180uint32 hashValue(const char *pStr, uint32 lenStr);
181
191inline uint8 sxtob(char c)
192{
193 return (uint8) ((c >= '0' && c <= '9') ? (c - '0') : ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : (c - 'A' + 10)));
194}
195
203 inline bool edlstringEqualsIgnoreCaseCnt(const EDLString &str1,const EDLString &str2, size_t len)
204{
205 wchar_t c1;
206 wchar_t c2;
207 size_t minLen = (str1.size() < str2.size()) ? str1.size() : str2.size();
208
209 if (minLen < len)
210 return false;
211
212 for (size_t i = 0; i < len; i++)
213 {
214 c1 = (wchar_t) ::tolower(str1.at(i));
215 c2 = (wchar_t) ::tolower(str2.at(i));
216
217 if (c1 != c2)
218 return false;
219 }
220
221 return true;
222}
223
230inline size_t edlstringFind(const EDLString &str, EDLString &searchStr)
231{
232 return str.find(searchStr);
233}
234
242 inline void edlstringSubstr(const EDLString &str, EDLString& result, size_t start, size_t end)
243{
244 result = str.substr(start, end);
245}
246
247
253
255
261
263
265
266#endif /* __EDLSTRING_H__ */
Definition edlvector.h:30
#define _BEGIN_EDL_NAMESPACE
Definition edlnamespaces.h:75
#define _END_EDL_NAMESPACE
Definition edlnamespaces.h:76
bool edlstringEqualsIgnoreCaseCnt(const EDLString &str1, const EDLString &str2, size_t len)
edlstringEqualsIgnoreCaseCnt performs a case-insensitive maximum-length-constrained string equality t...
Definition edlstring.h:203
_BEGIN_EDL_NAMESPACE typedef char16_t u16char
Definition edlstring.h:136
uint32 hashValue(const EDLSysString &str)
std::istringstream EDLSysStringIStream
Definition edlstring.h:159
std::string EDLSysString
Definition edlstring.h:158
size_t edlstringFind(const EDLString &str, EDLString &searchStr)
edlstringFind searches for a substring within a larger string.
Definition edlstring.h:230
std::wstring EDLString
Definition edlstring.h:165
bool equal(const EDLSysString &str1, const EDLSysString &str2)
Definition edlstring.h:178
uint8 sxtob(char c)
sxtob converts a hexadecimal character into corresponding (unsigned) integer value.
Definition edlstring.h:191
void edlstringSubstr(const EDLString &str, EDLString &result, size_t start, size_t end)
edlstringSubstr returns a substring from specified start and end points from a larger string
Definition edlstring.h:242
EDLSysString EDLRawString
Definition edlstring.h:171
wchar_t u32char
Definition edlstring.h:137
std::basic_string< u16char > EDLU16String
Definition edlstring.h:162
std::wostringstream EDLStringOStream
Definition edlstring.h:167
std::ostringstream EDLSysStringOStream
Definition edlstring.h:160
EDL_API EDLSysString EDLStringToEDLSysString(const EDLString &edlString)
EDLStringToEDLSysString converts an (UTF16 or UTF32 depending on platform) EDLString to an EDLSysStri...
EDL_API EDLString EDLSysStringToEDLString(const EDLSysString &edlSysString)
EDLSysStringToEDLString converts an EDLSysString (UTF8) to an EDLString (UTF16 or UTF32 depending on ...
std::wistringstream EDLStringIStream
Definition edlstring.h:166
std::basic_string< u32char > EDLU32String
Definition edlstring.h:163
CEDLVector< EDLString > CEDLStringVect
Definition edlstring.h:173
CEDLVector< EDLSysString > CEDLSysStringVect
Definition edlstring.h:174
CEDLVector< EDLRawString > CEDLRawStringVect
Definition edlstring.h:175
EDL "standard" types including known bit-length signed and unsigned integer type[def]s and definition...
unsigned int uint32
Definition edltypes.h:34
#define EDL_API
Definition edltypes.h:86
unsigned char uint8
Definition edltypes.h:32
Simple template vector class for general use.
Platform-dependent defines, enumerations, types etc. that are visible through the EDL API.