CLRX  1
An unofficial OpenCL extensions designed for Radeon GPUs
Utilities.h
Go to the documentation of this file.
1 /*
2  * CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3  * Copyright (C) 2014-2017 Mateusz Szpakowski
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
23 #ifndef __CLRX_UTILITIES_H__
24 #define __CLRX_UTILITIES_H__
25 
26 #include <CLRX/Config.h>
27 #include <exception>
28 #include <string>
29 #include <vector>
30 #include <cstdlib>
31 #include <cstring>
32 #include <cstdint>
33 #include <mutex>
34 #include <atomic>
35 #include <CLRX/utils/Containers.h>
36 #include <CLRX/utils/CString.h>
37 
39 namespace CLRX
40 {
41 
44 {
55 };
56 
58 class Exception: public std::exception
59 {
60 protected:
61  std::string message;
62 public:
64  Exception() = default;
66  explicit Exception(const std::string& message);
68  virtual ~Exception() noexcept = default;
69 
71  const char* what() const noexcept;
72 };
73 
75 typedef uint64_t LineNo;
76 
78 typedef size_t ColNo;
79 
82 {
83 public:
85  ParseException() = default;
87  explicit ParseException(const std::string& message);
89  ParseException(LineNo lineNo, const std::string& message);
91  ParseException(LineNo lineNo, ColNo charNo, const std::string& message);
93  virtual ~ParseException() noexcept = default;
94 };
95 
97 typedef uint32_t Flags;
98 
99 enum: Flags {
100  FLAGS_ALL = 0xffffffffU
101 };
102 
103 enum: Flags {
107  DYNLIB_MODE1_MASK = 7,
109 };
110 
113 {
114 private:
115  void* handle;
116  static std::mutex mutex;
117 public:
118  DynLibrary();
123  DynLibrary(const char* filename, Flags flags = 0);
124  ~DynLibrary();
125 
130  void load(const char* filename, Flags flags = 0);
132  void unload();
133 
135  void* getSymbol(const char* symbolName);
136 };
137 
138 /* parse utilities */
139 
141 inline bool isSpace(unsigned char c);
142 
143 inline bool isSpace(unsigned char c)
144 { return (c == 32 || (c < 32 && (0x3e00U & (1U<<c)))); }
145 
147 inline bool isODigit(unsigned char c);
148 
149 inline bool isODigit(unsigned char c)
150 { return c>='0' && c<= '7'; }
151 
153 inline bool isDigit(unsigned char c);
154 
155 inline bool isDigit(unsigned char c)
156 { return c>='0' && c<= '9'; }
157 
159 inline bool isXDigit(unsigned char c);
160 
161 inline bool isXDigit(unsigned char c)
162 { return (c>='0' && c<= '9') || (c>='a' && c<='f') || (c>='A' && c<='F'); }
163 
165 inline bool isAlpha(unsigned char c);
166 
167 inline bool isAlpha(unsigned char c)
168 { return (c>='a' && c<='z') || (c>='A' && c<='Z'); }
169 
171 inline bool isAlnum(unsigned char c);
172 
173 inline bool isAlnum(unsigned char c)
174 { return (c>='0' && c<= '9') || (c>='a' && c<='z') || (c>='A' && c<='Z'); }
175 
177 inline const char* skipSpaces(const char* s);
178 
179 inline const char* skipSpaces(const char* s)
180 {
181  while (isSpace(*s)) s++;
182  return s;
183 }
184 
186 inline const char* skipSpacesAtEnd(const char* s, size_t length);
187 
188 inline const char* skipSpacesAtEnd(const char* s, size_t length)
189 {
190  const char* t = s+length;
191  if (t == s) return s;
192  for (t--; t != s-1 && isSpace(*t); t--);
193  return t+1;
194 }
195 
197 
211 template<typename T>
212 extern T cstrtovCStyle(const char* str, const char* inend, const char*& outend);
213 
215 
220 template<typename T>
221 T parseEnvVariable(const char* envVar, const T& defaultValue = T())
222 {
223  const char* var = getenv(envVar);
224  if (var == nullptr)
225  return defaultValue;
226  var = skipSpaces(var);
227  if (*var == 0)
228  return defaultValue;
229  const char* outend;
230  try
231  { return cstrtovCStyle<T>(var, nullptr, outend); }
232  catch(const ParseException& ex)
233  { return defaultValue; }
234 }
235 
237 extern template
238 cxuchar parseEnvVariable<cxuchar>(const char* envVar, const cxuchar& defaultValue);
239 
241 extern template
242 cxchar parseEnvVariable<cxchar>(const char* envVar, const cxchar& defaultValue);
243 
245 extern template
246 cxuint parseEnvVariable<cxuint>(const char* envVar, const cxuint& defaultValue);
247 
249 extern template
250 cxint parseEnvVariable<cxint>(const char* envVar, const cxint& defaultValue);
251 
253 extern template
254 cxushort parseEnvVariable<cxushort>(const char* envVar, const cxushort& defaultValue);
255 
257 extern template
258 cxshort parseEnvVariable<cxshort>(const char* envVar, const cxshort& defaultValue);
259 
261 extern template
262 cxulong parseEnvVariable<cxulong>(const char* envVar, const cxulong& defaultValue);
263 
265 extern template
266 cxlong parseEnvVariable<cxlong>(const char* envVar, const cxlong& defaultValue);
267 
269 extern template
270 cxullong parseEnvVariable<cxullong>(const char* envVar, const cxullong& defaultValue);
271 
273 extern template
274 cxllong parseEnvVariable<cxllong>(const char* envVar, const cxllong& defaultValue);
275 
277 extern template
278 float parseEnvVariable<float>(const char* envVar, const float& defaultValue);
279 
281 extern template
282 double parseEnvVariable<double>(const char* envVar, const double& defaultValue);
283 
284 #ifndef __UTILITIES_MODULE__
285 
287 extern template
288 std::string parseEnvVariable<std::string>(const char* envVar,
289  const std::string& defaultValue);
290 
292 extern template
293 bool parseEnvVariable<bool>(const char* envVar, const bool& defaultValue);
294 
295 #endif
296 
299 {
301  inline bool operator()(const char* c1, const char* c2) const
302  { return ::strcmp(c1, c2)<0; }
303 };
304 
307 {
309  inline bool operator()(const char* c1, const char* c2) const
310  { return ::strcasecmp(c1, c2)<0; }
311 };
312 
315 {
317  inline bool operator()(const char* c1, const char* c2) const
318  { return ::strcmp(c1, c2)==0; }
319 };
320 
323 {
325  size_t operator()(const char* c) const
326  {
327  if (c == nullptr)
328  return 0;
329  size_t hash = 0;
330 
331  for (const char* p = c; *p != 0; p++)
332  hash = ((hash<<8)^(cxbyte)*p)*size_t(0xbf146a3dU);
333  return hash;
334  }
335 };
336 
338 inline cxuint CLZ32(uint32_t v);
340 inline cxuint CLZ64(uint64_t v);
341 
342 inline cxuint CLZ32(uint32_t v)
343 {
344 #ifdef __GNUC__
345  return __builtin_clz(v);
346 #else
347  cxuint count = 0;
348  for (uint32_t t = 1U<<31; t > v; t>>=1, count++);
349  return count;
350 #endif
351 }
352 
353 inline cxuint CLZ64(uint64_t v)
354 {
355 #ifdef __GNUC__
356  return __builtin_clzll(v);
357 #else
358  cxuint count = 0;
359  for (uint64_t t = 1ULL<<63; t > v; t>>=1, count++);
360  return count;
361 #endif
362 }
363 
365 template<typename T, typename T2>
366 inline bool usumGt(T a, T b, T2 c)
367 { return ((a+b)>c) || ((a+b)<a); }
368 
370 template<typename T, typename T2>
371 inline bool usumGe(T a, T b, T2 c)
372 { return ((a+b)>=c) || ((a+b)<a); }
373 
375 extern std::string escapeStringCStyle(size_t strSize, const char* str);
376 
378 inline std::string escapeStringCStyle(const std::string& str)
379 { return escapeStringCStyle(str.size(), str.c_str()); }
380 
382 inline std::string escapeStringCStyle(const CString& str)
383 { return escapeStringCStyle(str.size(), str.c_str()); }
384 
385 
387 
395 extern size_t escapeStringCStyle(size_t strSize, const char* str,
396  size_t outMaxSize, char* outStr, size_t& outSize);
397 
399 
407 extern cxuint cstrtoui(const char* str, const char* inend, const char*& outend);
408 
410 extern int64_t cstrtoiXCStyle(const char* str, const char* inend,
411  const char*& outend, cxuint bits);
412 
414 extern uint64_t cstrtouXCStyle(const char* str, const char* inend,
415  const char*& outend, cxuint bits);
416 
418 struct UInt128
419 {
420  uint64_t lo;
421  uint64_t hi;
422 };
423 
425 extern uint64_t cstrtofXCStyle(const char* str, const char* inend,
426  const char*& outend, cxuint expBits, cxuint mantisaBits);
427 
429 extern UInt128 cstrtou128CStyle(const char* str, const char* inend, const char*& outend);
430 
431 /* cstrtovcstyle impls */
432 
434 template<> inline
435 cxuchar cstrtovCStyle<cxuchar>(const char* str, const char* inend, const char*& outend)
436 { return cstrtouXCStyle(str, inend, outend, sizeof(cxuchar)<<3); }
437 
439 template<> inline
440 cxchar cstrtovCStyle<cxchar>(const char* str, const char* inend, const char*& outend)
441 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxchar)<<3); }
442 
444 template<> inline
445 cxuint cstrtovCStyle<cxuint>(const char* str, const char* inend, const char*& outend)
446 { return cstrtouXCStyle(str, inend, outend, sizeof(cxuint)<<3); }
447 
449 template<> inline
450 cxint cstrtovCStyle<cxint>(const char* str, const char* inend, const char*& outend)
451 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxint)<<3); }
452 
454 template<> inline
455 cxushort cstrtovCStyle<cxushort>(const char* str, const char* inend, const char*& outend)
456 { return cstrtouXCStyle(str, inend, outend, sizeof(cxushort)<<3); }
457 
459 template<> inline
460 cxshort cstrtovCStyle<cxshort>(const char* str, const char* inend, const char*& outend)
461 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxshort)<<3); }
462 
464 template<> inline
465 cxulong cstrtovCStyle<cxulong>(const char* str, const char* inend, const char*& outend)
466 { return cstrtouXCStyle(str, inend, outend, sizeof(cxulong)<<3); }
467 
469 template<> inline
470 cxlong cstrtovCStyle<cxlong>(const char* str, const char* inend, const char*& outend)
471 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxlong)<<3); }
472 
474 template<> inline
475 cxullong cstrtovCStyle<cxullong>(const char* str, const char* inend, const char*& outend)
476 { return cstrtouXCStyle(str, inend, outend, sizeof(cxullong)<<3); }
477 
479 template<> inline
480 cxllong cstrtovCStyle<cxllong>(const char* str, const char* inend, const char*& outend)
481 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxllong)<<3); }
482 
484 template<> inline
485 UInt128 cstrtovCStyle<UInt128>(const char* str, const char* inend, const char*& outend)
486 { return cstrtou128CStyle(str, inend, outend); }
487 
489 template<> inline
490 float cstrtovCStyle<float>(const char* str, const char* inend, const char*& outend)
491 {
492  union {
493  float f;
494  uint32_t u;
495  } v;
496  v.u = cstrtofXCStyle(str, inend, outend, 8, 23);
497  return v.f;
498 }
499 
501 template<> inline
502 double cstrtovCStyle<double>(const char* str, const char* inend, const char*& outend)
503 {
504  union {
505  double d;
506  uint64_t u;
507  } v;
508  v.u = cstrtofXCStyle(str, inend, outend, 11, 52);
509  return v.d;
510 }
511 
513 
524 cxushort cstrtohCStyle(const char* str, const char* inend, const char*& outend);
525 
527 inline cxushort cstrtohCStyle(const char* str, const char* inend, const char*& outend)
528 { return cstrtofXCStyle(str, inend, outend, 5, 10); }
529 
531 extern size_t uXtocstrCStyle(uint64_t value, char* str, size_t maxSize, cxuint radix,
532  cxuint width, bool prefix);
533 
535 extern size_t iXtocstrCStyle(int64_t value, char* str, size_t maxSize, cxuint radix,
536  cxuint width, bool prefix);
537 
539 
548 template<typename T>
549 extern size_t itocstrCStyle(T value, char* str, size_t maxSize, cxuint radix = 10,
550  cxuint width = 0, bool prefix = true);
551 
553 template<> inline
554 size_t itocstrCStyle<cxuchar>(cxuchar value, char* str, size_t maxSize, cxuint radix,
555  cxuint width, bool prefix)
556 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
557 
559 template<> inline
560 size_t itocstrCStyle<cxchar>(cxchar value, char* str, size_t maxSize, cxuint radix,
561  cxuint width, bool prefix)
562 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
563 
565 template<> inline
566 size_t itocstrCStyle<cxushort>(cxushort value, char* str, size_t maxSize, cxuint radix,
567  cxuint width, bool prefix)
568 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
569 
571 template<> inline
572 size_t itocstrCStyle<cxshort>(cxshort value, char* str, size_t maxSize, cxuint radix,
573  cxuint width, bool prefix)
574 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
575 
577 template<> inline
578 size_t itocstrCStyle<cxuint>(cxuint value, char* str, size_t maxSize, cxuint radix,
579  cxuint width, bool prefix)
580 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
581 
583 template<> inline
584 size_t itocstrCStyle<cxint>(cxint value, char* str, size_t maxSize, cxuint radix,
585  cxuint width, bool prefix)
586 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
587 
589 template<> inline
590 size_t itocstrCStyle<cxulong>(cxulong value, char* str, size_t maxSize, cxuint radix,
591  cxuint width, bool prefix)
592 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
593 
595 template<> inline
596 size_t itocstrCStyle<cxlong>(cxlong value, char* str, size_t maxSize, cxuint radix,
597  cxuint width, bool prefix)
598 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
599 
601 template<> inline
602 size_t itocstrCStyle<cxullong>(cxullong value, char* str, size_t maxSize, cxuint radix,
603  cxuint width , bool prefix)
604 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
605 
607 template<> inline
608 size_t itocstrCStyle<cxllong>(cxllong value, char* str, size_t maxSize, cxuint radix,
609  cxuint width, bool prefix)
610 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
611 
613 extern size_t fXtocstrCStyle(uint64_t value, char* str, size_t maxSize,
614  bool scientific, cxuint expBits, cxuint mantisaBits);
615 
617 
627 size_t htocstrCStyle(cxushort value, char* str, size_t maxSize,
628  bool scientific = false);
629 
630 inline size_t htocstrCStyle(cxushort value, char* str, size_t maxSize, bool scientific)
631 { return fXtocstrCStyle(value, str, maxSize, scientific, 5, 10); }
632 
634 
644 size_t ftocstrCStyle(float value, char* str, size_t maxSize,
645  bool scientific = false);
646 
647 inline size_t ftocstrCStyle(float value, char* str, size_t maxSize, bool scientific)
648 {
649  union {
650  float f;
651  uint32_t u;
652  } v;
653  v.f = value;
654  return fXtocstrCStyle(v.u, str, maxSize, scientific, 8, 23);
655 }
656 
658 
668 size_t dtocstrCStyle(double value, char* str, size_t maxSize,
669  bool scientific = false);
670 
671 inline size_t dtocstrCStyle(double value, char* str, size_t maxSize, bool scientific)
672 {
673  union {
674  double d;
675  uint64_t u;
676  } v;
677  v.d = value;
678  return fXtocstrCStyle(v.u, str, maxSize, scientific, 11, 52);
679 }
680 
681 /* file system utilities */
682 
684 extern bool isDirectory(const char* path);
686 extern bool isFileExists(const char* path);
687 
689 
693 extern Array<cxbyte> loadDataFromFile(const char* filename);
694 
696 extern void filesystemPath(char* path);
698 extern void filesystemPath(std::string& path);
699 
701 extern std::string joinPaths(const std::string& path1, const std::string& path2);
702 
704 extern uint64_t getFileTimestamp(const char* filename);
705 
707 extern std::string getHomeDir();
709 extern void makeDir(const char* dirname);
711 extern Array<cxbyte> runExecWithOutput(const char* program, const char** argv);
712 
714 extern std::string findAmdOCL();
715 
717 extern std::string findMesaOCL();
718 
720 extern std::string findLLVMConfig();
721 
722 /*
723  * Reference support
724  */
725 
728 {
729 private:
730  mutable std::atomic<size_t> refCount;
731 public:
733  RefCountable() : refCount(1)
734  { }
735 
737  void reference() const
738  {
739  refCount.fetch_add(1);
740  }
741 
743  bool unreference() const
744  {
745  return (refCount.fetch_sub(1) == 1);
746  }
747 };
748 
751 {
752 private:
753  mutable size_t refCount;
754 public:
756  FastRefCountable() : refCount(1)
757  { }
758 
760  void reference() const
761  {
762  refCount++;
763  }
764 
766  bool unreference() const
767  {
768  return (--refCount == 0);
769  }
770 };
771 
773 template<typename T>
774 class RefPtr
775 {
776 private:
777  T* ptr;
778 public:
780  RefPtr(): ptr(nullptr)
781  { }
782 
784  explicit RefPtr(T* inputPtr) : ptr(inputPtr)
785  { }
786 
788  RefPtr(const RefPtr<T>& refPtr) : ptr(refPtr.ptr)
789  {
790  if (ptr != nullptr)
791  ptr->reference();
792  }
793 
795  RefPtr(RefPtr<T>&& refPtr) : ptr(refPtr.ptr)
796  { refPtr.ptr = nullptr; }
797 
800  {
801  if (ptr != nullptr)
802  if (ptr->unreference())
803  delete ptr;
804  }
805 
807  RefPtr<T>& operator=(const RefPtr<T>& refPtr)
808  {
809  if (ptr != nullptr)
810  if (ptr->unreference())
811  delete ptr;
812  if (refPtr.ptr != nullptr)
813  refPtr.ptr->reference();
814  ptr = refPtr.ptr;
815  return *this;
816  }
819  {
820  if (ptr != nullptr)
821  if (ptr->unreference())
822  delete ptr;
823  ptr = refPtr.ptr;
824  refPtr.ptr = nullptr;
825  return *this;
826  }
827 
829  bool operator==(const RefPtr<T>& refPtr) const
830  { return ptr == refPtr.ptr; }
832  bool operator!=(const RefPtr<T>& refPtr) const
833  { return ptr != refPtr.ptr; }
834 
836  operator bool() const
837  { return ptr!=nullptr; }
838 
840  bool operator!() const
841  { return ptr==nullptr; }
842 
844  T* operator->() const
845  { return ptr; }
846 
848  void reset()
849  {
850  if (ptr != nullptr)
851  if (ptr->unreference())
852  delete ptr;
853  ptr = nullptr;
854  }
855 
857  void swap(RefPtr<T>& refPtr)
858  {
859  T* tmp = ptr;
860  ptr = refPtr.ptr;
861  refPtr.ptr = tmp;
862  }
863 
865  template<typename DestType>
867  {
868  DestType* p = const_cast<DestType*>(ptr);
869  if (p != nullptr)
870  p->reference();
871  return RefPtr<DestType>(p);
872  }
874  template<typename DestType>
876  {
877  DestType* p = static_cast<DestType*>(ptr);
878  if (p != nullptr)
879  p->reference();
880  return RefPtr<DestType>(p);
881  }
883  template<typename DestType>
885  {
886  DestType* p = dynamic_cast<DestType*>(ptr);
887  if (p != nullptr)
888  p->reference();
889  return RefPtr<DestType>(p);
890  }
891 };
892 
894 inline char toLower(char c);
895 
896 inline char toLower(char c)
897 { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; }
898 
900 inline void toLowerString(std::string& string);
901 
902 inline void toLowerString(std::string& string)
903 { std::transform(string.begin(), string.end(), string.begin(), toLower); }
904 
906 inline void toLowerString(char* cstr);
907 
908 inline void toLowerString(char* cstr)
909 {
910  for (; *cstr!=0; cstr++)
911  *cstr = toLower(*cstr);
912 }
913 
915 inline void toLowerString(CString& string);
916 
917 inline void toLowerString(CString& string)
918 { if (!string.empty())
919  toLowerString(string.begin()); }
920 
922 inline char toUpper(char c);
923 
924 inline char toUpper(char c)
925 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; }
926 
928 inline void toUpperString(std::string& string);
929 
930 inline void toUpperString(std::string& string)
931 { std::transform(string.begin(), string.end(), string.begin(), toUpper); }
932 
934 inline void toUpperString(char* cstr);
935 
936 inline void toUpperString(char* cstr)
937 {
938  for (; *cstr!=0; cstr++)
939  *cstr = toUpper(*cstr);
940 }
941 
943 inline void toUpperString(CString& string);
944 
945 inline void toUpperString(CString& string)
946 { if (!string.empty())
947  toUpperString(string.begin()); }
948 
949 /* CALL once */
950 
951 #ifdef HAVE_CALL_ONCE
952 typedef std::once_flag OnceFlag;
954 
956 template<class Callable, class... Args>
957 inline void callOnce(std::once_flag& flag, Callable&& f, Args&&... args)
958 { std::call_once(flag, f, args...); }
959 #else
960 struct OnceFlag: std::atomic<int>
961 { // force zero initialization
962  OnceFlag(): std::atomic<int>(0)
963  { }
964 };
965 
966 template<class Callable, class... Args>
967 inline void callOnce(OnceFlag& flag, Callable&& f, Args&&... args)
968 {
969  if (flag.exchange(1) == 0)
970  f(args...);
971 }
972 #endif
973 
974 };
975 
976 #endif
reference countable object
Definition: Utilities.h:727
template bool parseEnvVariable< bool >(const char *envVar, const bool &defaultValue)
parse environment variable of boolean type
bool operator!=(const RefPtr< T > &refPtr) const
unequality operator
Definition: Utilities.h:832
function class that returns true if C strings are equal
Definition: Utilities.h:314
function class that returns true if first C string is less than second (ignore case) ...
Definition: Utilities.h:306
int64_t cstrtoiXCStyle(const char *str, const char *inend, const char *&outend, cxuint bits)
parse 64-bit signed integer
cxlong cstrtovCStyle< cxlong >(const char *str, const char *inend, const char *&outend)
parse cxlong value from string
Definition: Utilities.h:470
bool isFileExists(const char *path)
returns true if file exists
std::string escapeStringCStyle(size_t strSize, const char *str)
escapes string into C-style string
non copyable and non movable base structure (class)
Definition: Utilities.h:43
bool operator!() const
return true if null
Definition: Utilities.h:840
uint64_t lo
low part
Definition: Utilities.h:420
bool unreference() const
unreference object (returns true if no reference count)
Definition: Utilities.h:743
template cxint parseEnvVariable< cxint >(const char *envVar, const cxint &defaultValue)
parse environment variable of cxint type
bool operator()(const char *c1, const char *c2) const
operator of call
Definition: Utilities.h:317
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:97
cxuint cstrtovCStyle< cxuint >(const char *str, const char *inend, const char *&outend)
parse cxuint value from string
Definition: Utilities.h:445
size_t itocstrCStyle< cxullong >(cxullong value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxullong value to string
Definition: Utilities.h:602
template cxushort parseEnvVariable< cxushort >(const char *envVar, const cxushort &defaultValue)
parse environment variable of cxushort type
void makeDir(const char *dirname)
create directory
template cxuchar parseEnvVariable< cxuchar >(const char *envVar, const cxuchar &defaultValue)
parse environment variable of cxuchar type
template double parseEnvVariable< double >(const char *envVar, const double &defaultValue)
parse environment variable of double type
const char * c_str() const
return C-style string pointer
Definition: CString.h:249
size_t iXtocstrCStyle(int64_t value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
formast signed value to string
bool isDirectory(const char *path)
returns true if path refers to directory
reference pointer based on Glibmm refptr
Definition: Utilities.h:774
RefPtr< DestType > staticCast() const
static cast
Definition: Utilities.h:875
bool unreference() const
unreference object (returns true if no reference count)
Definition: Utilities.h:766
template cxullong parseEnvVariable< cxullong >(const char *envVar, const cxullong &defaultValue)
parse environment variable of cxullong type
signed short cxshort
signed short
Definition: Config.h:215
template cxchar parseEnvVariable< cxchar >(const char *envVar, const cxchar &defaultValue)
parse environment variable of cxchar type
cxullong cstrtovCStyle< cxullong >(const char *str, const char *inend, const char *&outend)
parse cxullong value from string
Definition: Utilities.h:475
size_t fXtocstrCStyle(uint64_t value, char *str, size_t maxSize, bool scientific, cxuint expBits, cxuint mantisaBits)
format float value to string
treats symbols globally
Definition: Utilities.h:108
signed char cxchar
signed character (signed byte)
Definition: Config.h:209
Unsigned 128-bit integer.
Definition: Utilities.h:418
size_t itocstrCStyle< cxushort >(cxushort value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxushort value to string
Definition: Utilities.h:566
RefPtr< DestType > constCast() const
const cast
Definition: Utilities.h:866
bool operator()(const char *c1, const char *c2) const
operator of call
Definition: Utilities.h:301
std::string findAmdOCL()
find amdocl library, returns path if found, otherwise returns empty string
signed long cxlong
signed long
Definition: Config.h:223
RefCountable()
constructor
Definition: Utilities.h:733
RefPtr(T *inputPtr)
constructor from pointer
Definition: Utilities.h:784
an array class
Definition: Containers.h:38
RefPtr< DestType > dynamicCast() const
dynamic cast
Definition: Utilities.h:884
cxuint CLZ32(uint32_t v)
counts leading zeroes for 32-bit unsigned integer. For zero behavior is undefined ...
Definition: Utilities.h:342
template cxuint parseEnvVariable< cxuint >(const char *envVar, const cxuint &defaultValue)
parse environment variable of cxuint type
Configuration header.
bool operator==(const RefPtr< T > &refPtr) const
equality operator
Definition: Utilities.h:829
bool isDigit(unsigned char c)
check whether character is digit
Definition: Utilities.h:155
std::string findMesaOCL()
find Mesa OpenCL library, returns path if found, otherwise returns empty string
size_t dtocstrCStyle(double value, char *str, size_t maxSize, bool scientific=false)
formats double float in C-style
Definition: Utilities.h:671
uint64_t getFileTimestamp(const char *filename)
get file timestamp in nanosecond since Unix epoch
~RefPtr()
destructor
Definition: Utilities.h:799
const char * skipSpaces(const char *s)
skip spaces from cString
Definition: Utilities.h:179
unsigned char cxuchar
unsigned character (unsigned byte)
Definition: Config.h:211
size_t itocstrCStyle< cxuchar >(cxuchar value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxuchar value to string
Definition: Utilities.h:554
RefPtr< T > & operator=(const RefPtr< T > &refPtr)
copy constructor
Definition: Utilities.h:807
template cxshort parseEnvVariable< cxshort >(const char *envVar, const cxshort &defaultValue)
parse environment variable of cxshort type
bool usumGt(T a, T b, T2 c)
safely compares sum of two unsigned integers with other unsigned integer
Definition: Utilities.h:366
UInt128 cstrtou128CStyle(const char *str, const char *inend, const char *&outend)
parse 128-bit unsigned integer
uint64_t cstrtouXCStyle(const char *str, const char *inend, const char *&outend, cxuint bits)
parse 64-bit unsigned integer
size_t ColNo
column number type
Definition: Utilities.h:78
template float parseEnvVariable< float >(const char *envVar, const float &defaultValue)
parse environment variable of float type
UInt128 cstrtovCStyle< UInt128 >(const char *str, const char *inend, const char *&outend)
parse UInt128 value from string
Definition: Utilities.h:485
size_t itocstrCStyle< cxulong >(cxulong value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxulong value to string
Definition: Utilities.h:590
cxint cstrtovCStyle< cxint >(const char *str, const char *inend, const char *&outend)
parse cxint value from string
Definition: Utilities.h:450
unsigned long long cxullong
unsigned long long
Definition: Config.h:229
unsigned char cxbyte
unsigned byte
Definition: Config.h:213
size_t ftocstrCStyle(float value, char *str, size_t maxSize, bool scientific=false)
formats single float in C-style
Definition: Utilities.h:647
const char * skipSpacesAtEnd(const char *s, size_t length)
skip spaces from cString
Definition: Utilities.h:188
reference countable object (only for single threading usage)
Definition: Utilities.h:750
Array< cxbyte > loadDataFromFile(const char *filename)
load data from file (any regular or pipe or device)
bool isODigit(unsigned char c)
check whether character is digit
Definition: Utilities.h:149
template cxlong parseEnvVariable< cxlong >(const char *envVar, const cxlong &defaultValue)
parse environment variable of cxlong type
bool isSpace(unsigned char c)
check whether character is space
Definition: Utilities.h:143
void toUpperString(std::string &string)
convert string to uppercase
Definition: Utilities.h:930
main namespace
Definition: AsmDefs.h:38
bool usumGe(T a, T b, T2 c)
safely compares sum of two unsigned integers with other unsigned integer
Definition: Utilities.h:371
T cstrtovCStyle(const char *str, const char *inend, const char *&outend)
parses integer or float point formatted looks like C-style
std::string findLLVMConfig()
find LLVM config, returns path if found, otherwise returns empty string
unsigned int cxuint
unsigned int
Definition: Config.h:221
void reset()
reset refpointer
Definition: Utilities.h:848
cxuint cstrtoui(const char *str, const char *inend, const char *&outend)
parses unsigned integer regardless locales
float cstrtovCStyle< float >(const char *str, const char *inend, const char *&outend)
parse float value from string
Definition: Utilities.h:490
std::string getHomeDir()
get user&#39;s home directory
bool isAlnum(unsigned char c)
check whether character is digit
Definition: Utilities.h:173
size_t uXtocstrCStyle(uint64_t value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format unsigned value to string
bool isAlpha(unsigned char c)
check whether character is digit
Definition: Utilities.h:167
size_t itocstrCStyle< cxchar >(cxchar value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxchar value to string
Definition: Utilities.h:560
size_t itocstrCStyle< cxshort >(cxshort value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxshort value to string
Definition: Utilities.h:572
unsigned short cxushort
unsigned short
Definition: Config.h:217
void toLowerString(std::string &string)
convert string to lowercase
Definition: Utilities.h:902
T parseEnvVariable(const char *envVar, const T &defaultValue=T())
parse environment variable
Definition: Utilities.h:221
unsigned long cxulong
unsigned long
Definition: Config.h:225
size_t operator()(const char *c) const
operator of call
Definition: Utilities.h:325
size_t itocstrCStyle< cxint >(cxint value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxint value to string
Definition: Utilities.h:584
uint64_t cstrtofXCStyle(const char *str, const char *inend, const char *&outend, cxuint expBits, cxuint mantisaBits)
parse 64-bit float value
generate hash function for C string
Definition: Utilities.h:322
void swap(RefPtr< T > &refPtr)
swap between refpointers
Definition: Utilities.h:857
signed long long cxllong
signed long long
Definition: Config.h:227
cxllong cstrtovCStyle< cxllong >(const char *str, const char *inend, const char *&outend)
parse cxllong value from string
Definition: Utilities.h:480
bool isXDigit(unsigned char c)
check whether character is hexadecimal digit
Definition: Utilities.h:161
cxshort cstrtovCStyle< cxshort >(const char *str, const char *inend, const char *&outend)
parse cxshort value from string
Definition: Utilities.h:460
Array< cxbyte > runExecWithOutput(const char *program, const char **argv)
run executable with output, returns array of output
cxuchar cstrtovCStyle< cxuchar >(const char *str, const char *inend, const char *&outend)
parse cxuchar value from string
Definition: Utilities.h:435
char toLower(char c)
convert character to lowercase
Definition: Utilities.h:896
size_t itocstrCStyle< cxlong >(cxlong value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxlong value to string
Definition: Utilities.h:596
NonCopyableAndNonMovable & operator=(const NonCopyableAndNonMovable &)=delete
copy-assignment
std::string message
message
Definition: Utilities.h:61
FastRefCountable()
constructor
Definition: Utilities.h:756
uint64_t hi
high part
Definition: Utilities.h:421
size_t htocstrCStyle(cxushort value, char *str, size_t maxSize, bool scientific=false)
formats half float in C-style
Definition: Utilities.h:630
exception class
Definition: Utilities.h:58
cxchar cstrtovCStyle< cxchar >(const char *str, const char *inend, const char *&outend)
parse cxchar value from string
Definition: Utilities.h:440
void reference() const
reference object
Definition: Utilities.h:760
parse exception class
Definition: Utilities.h:81
bool operator()(const char *c1, const char *c2) const
operator of call
Definition: Utilities.h:309
treat symbols locally
Definition: Utilities.h:104
cxushort cstrtovCStyle< cxushort >(const char *str, const char *inend, const char *&outend)
parse cxushort value from string
Definition: Utilities.h:455
char toUpper(char c)
convert character to uppercase
Definition: Utilities.h:924
std::string joinPaths(const std::string &path1, const std::string &path2)
join two paths
resolve symbols now
Definition: Utilities.h:106
uint64_t LineNo
line number type
Definition: Utilities.h:75
signed int cxint
signed int
Definition: Config.h:219
template cxllong parseEnvVariable< cxllong >(const char *envVar, const cxllong &defaultValue)
parse environment variable of cxllong type
RefPtr(const RefPtr< T > &refPtr)
copy constructor
Definition: Utilities.h:788
function class that returns true if first C string is less than second
Definition: Utilities.h:298
RefPtr(RefPtr< T > &&refPtr)
move constructor
Definition: Utilities.h:795
void callOnce(std::once_flag &flag, Callable &&f, Args &&...args)
callOnce - portable wrapper for std::call_once
Definition: Utilities.h:957
cxushort cstrtohCStyle(const char *str, const char *inend, const char *&outend)
parses half float formatted looks like C-style
Definition: Utilities.h:527
cxuint CLZ64(uint64_t v)
counts leading zeroes for 64-bit unsigned integer. For zero behavior is undefined ...
Definition: Utilities.h:353
template cxulong parseEnvVariable< cxulong >(const char *envVar, const cxulong &defaultValue)
parse environment variable of cxulong type
NonCopyableAndNonMovable()
constructor
Definition: Utilities.h:46
double cstrtovCStyle< double >(const char *str, const char *inend, const char *&outend)
parse double value from string
Definition: Utilities.h:502
std::once_flag OnceFlag
Once flag type (wrapper for std::once_flag)
Definition: Utilities.h:953
RefPtr()
empty constructor
Definition: Utilities.h:780
resolve symbols when is needed
Definition: Utilities.h:105
size_t itocstrCStyle(T value, char *str, size_t maxSize, cxuint radix=10, cxuint width=0, bool prefix=true)
formats an integer
size_t size() const
compute size
Definition: CString.h:269
simple C-string container
Definition: CString.h:38
size_t itocstrCStyle< cxuint >(cxuint value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxuint value to string
Definition: Utilities.h:578
dynamic library class
Definition: Utilities.h:112
containers and other utils for other libraries and programs
cxulong cstrtovCStyle< cxulong >(const char *str, const char *inend, const char *&outend)
parse cxulong value from string
Definition: Utilities.h:465
void filesystemPath(char *path)
convert to filesystem from unified path (with slashes)
size_t itocstrCStyle< cxllong >(cxllong value, char *str, size_t maxSize, cxuint radix, cxuint width, bool prefix)
format cxllong value to string
Definition: Utilities.h:608
RefPtr< T > & operator=(RefPtr< T > &&refPtr)
move constructor
Definition: Utilities.h:818
C-style string class.
void reference() const
reference object
Definition: Utilities.h:737
T * operator->() const
get elem from pointer
Definition: Utilities.h:844