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-2018 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 
138  operator bool() const
139  { return handle!=nullptr; }
140 
142  bool operator!() const
143  { return handle==nullptr; }
144 
145  // return true if loaded
146  bool isLoaded() const
147  { return handle!=nullptr; }
148 };
149 
150 /* parse utilities */
151 
153 inline bool isSpace(unsigned char c);
154 
155 inline bool isSpace(unsigned char c)
156 { return (c == 32 || (c < 32 && (0x3e00U & (1U<<c)))); }
157 
159 inline bool isODigit(unsigned char c);
160 
161 inline bool isODigit(unsigned char c)
162 { return c>='0' && c<= '7'; }
163 
165 inline bool isDigit(unsigned char c);
166 
167 inline bool isDigit(unsigned char c)
168 { return c>='0' && c<= '9'; }
169 
171 inline bool isXDigit(unsigned char c);
172 
173 inline bool isXDigit(unsigned char c)
174 { return (c>='0' && c<= '9') || (c>='a' && c<='f') || (c>='A' && c<='F'); }
175 
177 inline bool isAlpha(unsigned char c);
178 
179 inline bool isAlpha(unsigned char c)
180 { return (c>='a' && c<='z') || (c>='A' && c<='Z'); }
181 
183 inline bool isAlnum(unsigned char c);
184 
185 inline bool isAlnum(unsigned char c)
186 { return (c>='0' && c<= '9') || (c>='a' && c<='z') || (c>='A' && c<='Z'); }
187 
189 inline const char* skipSpaces(const char* s);
190 
191 inline const char* skipSpaces(const char* s)
192 {
193  while (isSpace(*s)) s++;
194  return s;
195 }
196 
198 inline const char* skipSpacesAtEnd(const char* s, size_t length);
199 
200 inline const char* skipSpacesAtEnd(const char* s, size_t length)
201 {
202  const char* t = s+length;
203  if (t == s) return s;
204  for (t--; t != s-1 && isSpace(*t); t--);
205  return t+1;
206 }
207 
209 
223 template<typename T>
224 extern T cstrtovCStyle(const char* str, const char* inend, const char*& outend);
225 
227 
232 template<typename T>
233 T parseEnvVariable(const char* envVar, const T& defaultValue = T())
234 {
235  const char* var = getenv(envVar);
236  if (var == nullptr)
237  return defaultValue;
238  var = skipSpaces(var);
239  if (*var == 0)
240  return defaultValue;
241  const char* outend;
242  try
243  { return cstrtovCStyle<T>(var, nullptr, outend); }
244  catch(const ParseException& ex)
245  { return defaultValue; }
246 }
247 
249 extern template
250 cxuchar parseEnvVariable<cxuchar>(const char* envVar, const cxuchar& defaultValue);
251 
253 extern template
254 cxchar parseEnvVariable<cxchar>(const char* envVar, const cxchar& defaultValue);
255 
257 extern template
258 cxuint parseEnvVariable<cxuint>(const char* envVar, const cxuint& defaultValue);
259 
261 extern template
262 cxint parseEnvVariable<cxint>(const char* envVar, const cxint& defaultValue);
263 
265 extern template
266 cxushort parseEnvVariable<cxushort>(const char* envVar, const cxushort& defaultValue);
267 
269 extern template
270 cxshort parseEnvVariable<cxshort>(const char* envVar, const cxshort& defaultValue);
271 
273 extern template
274 cxulong parseEnvVariable<cxulong>(const char* envVar, const cxulong& defaultValue);
275 
277 extern template
278 cxlong parseEnvVariable<cxlong>(const char* envVar, const cxlong& defaultValue);
279 
281 extern template
282 cxullong parseEnvVariable<cxullong>(const char* envVar, const cxullong& defaultValue);
283 
285 extern template
286 cxllong parseEnvVariable<cxllong>(const char* envVar, const cxllong& defaultValue);
287 
289 extern template
290 float parseEnvVariable<float>(const char* envVar, const float& defaultValue);
291 
293 extern template
294 double parseEnvVariable<double>(const char* envVar, const double& defaultValue);
295 
296 #ifndef __UTILITIES_MODULE__
297 
299 extern template
300 std::string parseEnvVariable<std::string>(const char* envVar,
301  const std::string& defaultValue);
302 
304 extern template
305 bool parseEnvVariable<bool>(const char* envVar, const bool& defaultValue);
306 
307 #endif
308 
311 {
313  inline bool operator()(const char* c1, const char* c2) const
314  { return ::strcmp(c1, c2)<0; }
315 };
316 
319 {
321  inline bool operator()(const char* c1, const char* c2) const
322  { return ::strcasecmp(c1, c2)<0; }
323 };
324 
327 {
329  inline bool operator()(const char* c1, const char* c2) const
330  { return ::strcmp(c1, c2)==0; }
331 };
332 
335 {
337  size_t operator()(const char* c) const
338  {
339  if (c == nullptr)
340  return 0;
341  size_t hash = 0;
342 
343  for (const char* p = c; *p != 0; p++)
344  hash = ((hash<<8)^(cxbyte)*p)*size_t(0xbf146a3dU);
345  return hash;
346  }
347 };
348 
350 inline cxuint CLZ32(uint32_t v);
352 inline cxuint CLZ64(uint64_t v);
353 
354 inline cxuint CLZ32(uint32_t v)
355 {
356 #ifdef __GNUC__
357  return __builtin_clz(v);
358 #else
359  cxuint count = 0;
360  for (uint32_t t = 1U<<31; t > v; t>>=1, count++);
361  return count;
362 #endif
363 }
364 
365 inline cxuint CLZ64(uint64_t v)
366 {
367 #ifdef __GNUC__
368  return __builtin_clzll(v);
369 #else
370  cxuint count = 0;
371  for (uint64_t t = 1ULL<<63; t > v; t>>=1, count++);
372  return count;
373 #endif
374 }
375 
377 template<typename T, typename T2>
378 inline bool usumGt(T a, T b, T2 c)
379 { return ((a+b)>c) || ((a+b)<a); }
380 
382 template<typename T, typename T2>
383 inline bool usumGe(T a, T b, T2 c)
384 { return ((a+b)>=c) || ((a+b)<a); }
385 
387 extern std::string escapeStringCStyle(size_t strSize, const char* str);
388 
390 inline std::string escapeStringCStyle(const std::string& str)
391 { return escapeStringCStyle(str.size(), str.c_str()); }
392 
394 inline std::string escapeStringCStyle(const CString& str)
395 { return escapeStringCStyle(str.size(), str.c_str()); }
396 
397 
399 
407 extern size_t escapeStringCStyle(size_t strSize, const char* str,
408  size_t outMaxSize, char* outStr, size_t& outSize);
409 
411 
419 extern cxuint cstrtoui(const char* str, const char* inend, const char*& outend);
420 
422 extern int64_t cstrtoiXCStyle(const char* str, const char* inend,
423  const char*& outend, cxuint bits);
424 
426 extern uint64_t cstrtouXCStyle(const char* str, const char* inend,
427  const char*& outend, cxuint bits);
428 
430 struct UInt128
431 {
432  uint64_t lo;
433  uint64_t hi;
434 };
435 
437 extern uint64_t cstrtofXCStyle(const char* str, const char* inend,
438  const char*& outend, cxuint expBits, cxuint mantisaBits);
439 
441 extern UInt128 cstrtou128CStyle(const char* str, const char* inend, const char*& outend);
442 
443 /* cstrtovcstyle impls */
444 
446 template<> inline
447 cxuchar cstrtovCStyle<cxuchar>(const char* str, const char* inend, const char*& outend)
448 { return cstrtouXCStyle(str, inend, outend, sizeof(cxuchar)<<3); }
449 
451 template<> inline
452 cxchar cstrtovCStyle<cxchar>(const char* str, const char* inend, const char*& outend)
453 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxchar)<<3); }
454 
456 template<> inline
457 cxuint cstrtovCStyle<cxuint>(const char* str, const char* inend, const char*& outend)
458 { return cstrtouXCStyle(str, inend, outend, sizeof(cxuint)<<3); }
459 
461 template<> inline
462 cxint cstrtovCStyle<cxint>(const char* str, const char* inend, const char*& outend)
463 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxint)<<3); }
464 
466 template<> inline
467 cxushort cstrtovCStyle<cxushort>(const char* str, const char* inend, const char*& outend)
468 { return cstrtouXCStyle(str, inend, outend, sizeof(cxushort)<<3); }
469 
471 template<> inline
472 cxshort cstrtovCStyle<cxshort>(const char* str, const char* inend, const char*& outend)
473 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxshort)<<3); }
474 
476 template<> inline
477 cxulong cstrtovCStyle<cxulong>(const char* str, const char* inend, const char*& outend)
478 { return cstrtouXCStyle(str, inend, outend, sizeof(cxulong)<<3); }
479 
481 template<> inline
482 cxlong cstrtovCStyle<cxlong>(const char* str, const char* inend, const char*& outend)
483 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxlong)<<3); }
484 
486 template<> inline
487 cxullong cstrtovCStyle<cxullong>(const char* str, const char* inend, const char*& outend)
488 { return cstrtouXCStyle(str, inend, outend, sizeof(cxullong)<<3); }
489 
491 template<> inline
492 cxllong cstrtovCStyle<cxllong>(const char* str, const char* inend, const char*& outend)
493 { return cstrtoiXCStyle(str, inend, outend, sizeof(cxllong)<<3); }
494 
496 template<> inline
497 UInt128 cstrtovCStyle<UInt128>(const char* str, const char* inend, const char*& outend)
498 { return cstrtou128CStyle(str, inend, outend); }
499 
501 template<> inline
502 float cstrtovCStyle<float>(const char* str, const char* inend, const char*& outend)
503 {
504  union {
505  float f;
506  uint32_t u;
507  } v;
508  v.u = cstrtofXCStyle(str, inend, outend, 8, 23);
509  return v.f;
510 }
511 
513 template<> inline
514 double cstrtovCStyle<double>(const char* str, const char* inend, const char*& outend)
515 {
516  union {
517  double d;
518  uint64_t u;
519  } v;
520  v.u = cstrtofXCStyle(str, inend, outend, 11, 52);
521  return v.d;
522 }
523 
525 
536 cxushort cstrtohCStyle(const char* str, const char* inend, const char*& outend);
537 
539 inline cxushort cstrtohCStyle(const char* str, const char* inend, const char*& outend)
540 { return cstrtofXCStyle(str, inend, outend, 5, 10); }
541 
543 extern size_t uXtocstrCStyle(uint64_t value, char* str, size_t maxSize, cxuint radix,
544  cxuint width, bool prefix);
545 
547 extern size_t iXtocstrCStyle(int64_t value, char* str, size_t maxSize, cxuint radix,
548  cxuint width, bool prefix);
549 
551 
560 template<typename T>
561 extern size_t itocstrCStyle(T value, char* str, size_t maxSize, cxuint radix = 10,
562  cxuint width = 0, bool prefix = true);
563 
565 template<> inline
566 size_t itocstrCStyle<cxuchar>(cxuchar 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<cxchar>(cxchar 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<cxushort>(cxushort 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<cxshort>(cxshort 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<cxuint>(cxuint 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<cxint>(cxint 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<cxulong>(cxulong 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<cxlong>(cxlong value, char* str, size_t maxSize, cxuint radix,
609  cxuint width, bool prefix)
610 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
611 
613 template<> inline
614 size_t itocstrCStyle<cxullong>(cxullong value, char* str, size_t maxSize, cxuint radix,
615  cxuint width , bool prefix)
616 { return uXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
617 
619 template<> inline
620 size_t itocstrCStyle<cxllong>(cxllong value, char* str, size_t maxSize, cxuint radix,
621  cxuint width, bool prefix)
622 { return iXtocstrCStyle(value, str, maxSize, radix, width, prefix); }
623 
625 extern size_t fXtocstrCStyle(uint64_t value, char* str, size_t maxSize,
626  bool scientific, cxuint expBits, cxuint mantisaBits);
627 
629 
639 size_t htocstrCStyle(cxushort value, char* str, size_t maxSize,
640  bool scientific = false);
641 
642 inline size_t htocstrCStyle(cxushort value, char* str, size_t maxSize, bool scientific)
643 { return fXtocstrCStyle(value, str, maxSize, scientific, 5, 10); }
644 
646 
656 size_t ftocstrCStyle(float value, char* str, size_t maxSize,
657  bool scientific = false);
658 
659 inline size_t ftocstrCStyle(float value, char* str, size_t maxSize, bool scientific)
660 {
661  union {
662  float f;
663  uint32_t u;
664  } v;
665  v.f = value;
666  return fXtocstrCStyle(v.u, str, maxSize, scientific, 8, 23);
667 }
668 
670 
680 size_t dtocstrCStyle(double value, char* str, size_t maxSize,
681  bool scientific = false);
682 
683 inline size_t dtocstrCStyle(double value, char* str, size_t maxSize, bool scientific)
684 {
685  union {
686  double d;
687  uint64_t u;
688  } v;
689  v.d = value;
690  return fXtocstrCStyle(v.u, str, maxSize, scientific, 11, 52);
691 }
692 
693 /* file system utilities */
694 
696 extern bool isDirectory(const char* path);
698 extern bool isFileExists(const char* path);
699 
701 
705 extern Array<cxbyte> loadDataFromFile(const char* filename);
706 
708 extern void filesystemPath(char* path);
710 extern void filesystemPath(std::string& path);
711 
713 extern std::string joinPaths(const std::string& path1, const std::string& path2);
714 
716 extern uint64_t getFileTimestamp(const char* filename);
717 
719 extern std::string getHomeDir();
721 extern void makeDir(const char* dirname);
723 extern Array<cxbyte> runExecWithOutput(const char* program, const char** argv);
724 
726 extern std::string findAmdOCL();
727 
729 extern std::string findMesaOCL();
730 
732 extern std::string findLLVMConfig();
733 
734 /*
735  * Reference support
736  */
737 
740 {
741 private:
742  mutable std::atomic<size_t> refCount;
743 public:
745  RefCountable() : refCount(1)
746  { }
747 
749  void reference() const
750  {
751  refCount.fetch_add(1);
752  }
753 
755  bool unreference() const
756  {
757  return (refCount.fetch_sub(1) == 1);
758  }
759 };
760 
763 {
764 private:
765  mutable size_t refCount;
766 public:
768  FastRefCountable() : refCount(1)
769  { }
770 
772  void reference() const
773  {
774  refCount++;
775  }
776 
778  bool unreference() const
779  {
780  return (--refCount == 0);
781  }
782 };
783 
785 template<typename T>
786 class RefPtr
787 {
788 private:
789  T* ptr;
790 public:
792  RefPtr(): ptr(nullptr)
793  { }
794 
796  explicit RefPtr(T* inputPtr) : ptr(inputPtr)
797  { }
798 
800  RefPtr(const RefPtr<T>& refPtr) : ptr(refPtr.ptr)
801  {
802  if (ptr != nullptr)
803  ptr->reference();
804  }
805 
807  RefPtr(RefPtr<T>&& refPtr) : ptr(refPtr.ptr)
808  { refPtr.ptr = nullptr; }
809 
812  {
813  if (ptr != nullptr)
814  if (ptr->unreference())
815  delete ptr;
816  }
817 
819  RefPtr<T>& operator=(const RefPtr<T>& refPtr)
820  {
821  if (ptr != nullptr)
822  if (ptr->unreference())
823  delete ptr;
824  if (refPtr.ptr != nullptr)
825  refPtr.ptr->reference();
826  ptr = refPtr.ptr;
827  return *this;
828  }
831  {
832  if (ptr != nullptr)
833  if (ptr->unreference())
834  delete ptr;
835  ptr = refPtr.ptr;
836  refPtr.ptr = nullptr;
837  return *this;
838  }
839 
841  bool operator==(const RefPtr<T>& refPtr) const
842  { return ptr == refPtr.ptr; }
844  bool operator!=(const RefPtr<T>& refPtr) const
845  { return ptr != refPtr.ptr; }
846 
848  operator bool() const
849  { return ptr!=nullptr; }
850 
852  bool operator!() const
853  { return ptr==nullptr; }
854 
856  T* operator->() const
857  { return ptr; }
858 
860  void reset()
861  {
862  if (ptr != nullptr)
863  if (ptr->unreference())
864  delete ptr;
865  ptr = nullptr;
866  }
867 
869  void swap(RefPtr<T>& refPtr)
870  {
871  T* tmp = ptr;
872  ptr = refPtr.ptr;
873  refPtr.ptr = tmp;
874  }
875 
877  template<typename DestType>
879  {
880  DestType* p = const_cast<DestType*>(ptr);
881  if (p != nullptr)
882  p->reference();
883  return RefPtr<DestType>(p);
884  }
886  template<typename DestType>
888  {
889  DestType* p = static_cast<DestType*>(ptr);
890  if (p != nullptr)
891  p->reference();
892  return RefPtr<DestType>(p);
893  }
895  template<typename DestType>
897  {
898  DestType* p = dynamic_cast<DestType*>(ptr);
899  if (p != nullptr)
900  p->reference();
901  return RefPtr<DestType>(p);
902  }
903 };
904 
906 inline char toLower(char c);
907 
908 inline char toLower(char c)
909 { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; }
910 
912 inline void toLowerString(std::string& string);
913 
914 inline void toLowerString(std::string& string)
915 { std::transform(string.begin(), string.end(), string.begin(), toLower); }
916 
918 inline void toLowerString(char* cstr);
919 
920 inline void toLowerString(char* cstr)
921 {
922  for (; *cstr!=0; cstr++)
923  *cstr = toLower(*cstr);
924 }
925 
927 inline void toLowerString(CString& string);
928 
929 inline void toLowerString(CString& string)
930 { if (!string.empty())
931  toLowerString(string.begin()); }
932 
934 inline char toUpper(char c);
935 
936 inline char toUpper(char c)
937 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; }
938 
940 inline void toUpperString(std::string& string);
941 
942 inline void toUpperString(std::string& string)
943 { std::transform(string.begin(), string.end(), string.begin(), toUpper); }
944 
946 inline void toUpperString(char* cstr);
947 
948 inline void toUpperString(char* cstr)
949 {
950  for (; *cstr!=0; cstr++)
951  *cstr = toUpper(*cstr);
952 }
953 
955 inline void toUpperString(CString& string);
956 
957 inline void toUpperString(CString& string)
958 { if (!string.empty())
959  toUpperString(string.begin()); }
960 
961 /* CALL once */
962 
963 #ifdef HAVE_CALL_ONCE
964 typedef std::once_flag OnceFlag;
966 
968 template<class Callable, class... Args>
969 inline void callOnce(std::once_flag& flag, Callable&& f, Args&&... args)
970 { std::call_once(flag, f, args...); }
971 #else
972 struct OnceFlag: std::atomic<int>
973 {
974  // force zero initialization
975  OnceFlag(): std::atomic<int>(0)
976  { }
977 };
978 
979 template<class Callable, class... Args>
980 inline void callOnce(OnceFlag& flag, Callable&& f, Args&&... args)
981 {
982  if (flag.exchange(1) == 0)
983  f(args...);
984 }
985 #endif
986 
987 };
988 
989 #endif
reference countable object
Definition: Utilities.h:739
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:844
function class that returns true if C strings are equal
Definition: Utilities.h:326
function class that returns true if first C string is less than second (ignore case) ...
Definition: Utilities.h:318
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:482
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:852
uint64_t lo
low part
Definition: Utilities.h:432
bool unreference() const
unreference object (returns true if no reference count)
Definition: Utilities.h:755
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:329
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:457
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:614
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:252
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:786
RefPtr< DestType > staticCast() const
static cast
Definition: Utilities.h:887
bool unreference() const
unreference object (returns true if no reference count)
Definition: Utilities.h:778
template cxullong parseEnvVariable< cxullong >(const char *envVar, const cxullong &defaultValue)
parse environment variable of cxullong type
signed short cxshort
signed short
Definition: Config.h:217
template cxchar parseEnvVariable< cxchar >(const char *envVar, const cxchar &defaultValue)
parse environment variable of cxchar type
treat symbols locally
Definition: Utilities.h:104
cxullong cstrtovCStyle< cxullong >(const char *str, const char *inend, const char *&outend)
parse cxullong value from string
Definition: Utilities.h:487
size_t fXtocstrCStyle(uint64_t value, char *str, size_t maxSize, bool scientific, cxuint expBits, cxuint mantisaBits)
format float value to string
signed char cxchar
signed character (signed byte)
Definition: Config.h:211
Unsigned 128-bit integer.
Definition: Utilities.h:430
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:578
RefPtr< DestType > constCast() const
const cast
Definition: Utilities.h:878
bool operator()(const char *c1, const char *c2) const
operator of call
Definition: Utilities.h:313
std::string findAmdOCL()
find amdocl library, returns path if found, otherwise returns empty string
signed long cxlong
signed long
Definition: Config.h:225
RefCountable()
constructor
Definition: Utilities.h:745
RefPtr(T *inputPtr)
constructor from pointer
Definition: Utilities.h:796
an array class
Definition: Containers.h:38
RefPtr< DestType > dynamicCast() const
dynamic cast
Definition: Utilities.h:896
cxuint CLZ32(uint32_t v)
counts leading zeroes for 32-bit unsigned integer. For zero behavior is undefined ...
Definition: Utilities.h:354
template cxuint parseEnvVariable< cxuint >(const char *envVar, const cxuint &defaultValue)
parse environment variable of cxuint type
bool operator!() const
returns true if not loaded
Definition: Utilities.h:142
Configuration header.
bool operator==(const RefPtr< T > &refPtr) const
equality operator
Definition: Utilities.h:841
bool isDigit(unsigned char c)
check whether character is digit
Definition: Utilities.h:167
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:683
uint64_t getFileTimestamp(const char *filename)
get file timestamp in nanosecond since Unix epoch
~RefPtr()
destructor
Definition: Utilities.h:811
const char * skipSpaces(const char *s)
skip spaces from cString
Definition: Utilities.h:191
unsigned char cxuchar
unsigned character (unsigned byte)
Definition: Config.h:213
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:566
RefPtr< T > & operator=(const RefPtr< T > &refPtr)
copy constructor
Definition: Utilities.h:819
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:378
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:497
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:602
cxint cstrtovCStyle< cxint >(const char *str, const char *inend, const char *&outend)
parse cxint value from string
Definition: Utilities.h:462
unsigned long long cxullong
unsigned long long
Definition: Config.h:231
unsigned char cxbyte
unsigned byte
Definition: Config.h:215
size_t ftocstrCStyle(float value, char *str, size_t maxSize, bool scientific=false)
formats single float in C-style
Definition: Utilities.h:659
const char * skipSpacesAtEnd(const char *s, size_t length)
skip spaces from cString
Definition: Utilities.h:200
reference countable object (only for single threading usage)
Definition: Utilities.h:762
Array< cxbyte > loadDataFromFile(const char *filename)
load data from file (any regular or pipe or device)
resolve symbols when is needed
Definition: Utilities.h:105
bool isODigit(unsigned char c)
check whether character is digit
Definition: Utilities.h:161
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:155
void toUpperString(std::string &string)
convert string to uppercase
Definition: Utilities.h:942
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:383
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:223
resolve symbols now
Definition: Utilities.h:106
void reset()
reset refpointer
Definition: Utilities.h:860
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:502
std::string getHomeDir()
get user&#39;s home directory
bool isAlnum(unsigned char c)
check whether character is digit
Definition: Utilities.h:185
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:179
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:572
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:584
unsigned short cxushort
unsigned short
Definition: Config.h:219
treats symbols globally
Definition: Utilities.h:108
void toLowerString(std::string &string)
convert string to lowercase
Definition: Utilities.h:914
T parseEnvVariable(const char *envVar, const T &defaultValue=T())
parse environment variable
Definition: Utilities.h:233
unsigned long cxulong
unsigned long
Definition: Config.h:227
size_t operator()(const char *c) const
operator of call
Definition: Utilities.h:337
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:596
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:334
void swap(RefPtr< T > &refPtr)
swap between refpointers
Definition: Utilities.h:869
signed long long cxllong
signed long long
Definition: Config.h:229
cxllong cstrtovCStyle< cxllong >(const char *str, const char *inend, const char *&outend)
parse cxllong value from string
Definition: Utilities.h:492
bool isXDigit(unsigned char c)
check whether character is hexadecimal digit
Definition: Utilities.h:173
cxshort cstrtovCStyle< cxshort >(const char *str, const char *inend, const char *&outend)
parse cxshort value from string
Definition: Utilities.h:472
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:447
char toLower(char c)
convert character to lowercase
Definition: Utilities.h:908
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:608
NonCopyableAndNonMovable & operator=(const NonCopyableAndNonMovable &)=delete
copy-assignment
std::string message
message
Definition: Utilities.h:61
FastRefCountable()
constructor
Definition: Utilities.h:768
uint64_t hi
high part
Definition: Utilities.h:433
size_t htocstrCStyle(cxushort value, char *str, size_t maxSize, bool scientific=false)
formats half float in C-style
Definition: Utilities.h:642
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:452
void reference() const
reference object
Definition: Utilities.h:772
parse exception class
Definition: Utilities.h:81
bool operator()(const char *c1, const char *c2) const
operator of call
Definition: Utilities.h:321
cxushort cstrtovCStyle< cxushort >(const char *str, const char *inend, const char *&outend)
parse cxushort value from string
Definition: Utilities.h:467
char toUpper(char c)
convert character to uppercase
Definition: Utilities.h:936
std::string joinPaths(const std::string &path1, const std::string &path2)
join two paths
uint64_t LineNo
line number type
Definition: Utilities.h:75
signed int cxint
signed int
Definition: Config.h:221
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:800
function class that returns true if first C string is less than second
Definition: Utilities.h:310
RefPtr(RefPtr< T > &&refPtr)
move constructor
Definition: Utilities.h:807
void callOnce(std::once_flag &flag, Callable &&f, Args &&...args)
callOnce - portable wrapper for std::call_once
Definition: Utilities.h:969
cxushort cstrtohCStyle(const char *str, const char *inend, const char *&outend)
parses half float formatted looks like C-style
Definition: Utilities.h:539
cxuint CLZ64(uint64_t v)
counts leading zeroes for 64-bit unsigned integer. For zero behavior is undefined ...
Definition: Utilities.h:365
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:514
std::once_flag OnceFlag
Once flag type (wrapper for std::once_flag)
Definition: Utilities.h:965
RefPtr()
empty constructor
Definition: Utilities.h:792
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:272
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:590
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:477
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:620
RefPtr< T > & operator=(RefPtr< T > &&refPtr)
move constructor
Definition: Utilities.h:830
C-style string class.
void reference() const
reference object
Definition: Utilities.h:749
T * operator->() const
get elem from pointer
Definition: Utilities.h:856