diff options
author | Jenkins <bsgcomp@arm.com> | 2018-05-23 11:36:53 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-05-23 14:55:11 +0100 |
commit | b3a371bc429d2ba45e56baaf239d8200c2662a74 (patch) | |
tree | 554525e415c303d64a08722a755397852ebbb8e4 /support | |
parent | 67c8c91522e5be8156b77f57e63c0253535c902a (diff) | |
download | armcl-master.tar.gz armcl-master.tar.bz2 armcl-master.zip |
Diffstat (limited to 'support')
-rw-r--r-- | support/Mutex.h | 12 | ||||
-rw-r--r-- | support/ToolchainSupport.h | 50 |
2 files changed, 50 insertions, 12 deletions
diff --git a/support/Mutex.h b/support/Mutex.h index 6d0a38767..d70dd7595 100644 --- a/support/Mutex.h +++ b/support/Mutex.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -29,6 +29,7 @@ namespace arm_compute { #ifndef NO_MULTI_THREADING +/** Wrapper of Mutex data-object */ using Mutex = std::mutex; #else /* NO_MULTI_THREADING */ /** Wrapper implementation of Mutex data-object */ @@ -36,13 +37,20 @@ class Mutex { public: /** Default constructor */ - Mutex() = default; + Mutex() = default; + /** Default destructor */ ~Mutex() = default; + /** Lock */ void lock() {}; + /** Unlock */ void unlock() {}; + /** Try the lock. + * + * @return true. + */ bool try_lock() { return true; diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h index 56cbce8cc..88c17009c 100644 --- a/support/ToolchainSupport.h +++ b/support/ToolchainSupport.h @@ -69,12 +69,17 @@ inline std::string to_string(T && value) * * @return Integer representation of @p str. */ -inline int stoi(const std::string &str) +inline int stoi(const std::string &str, std::size_t *pos = 0, int base = 10) { - std::stringstream stream(str); - int value = 0; - stream >> value; - return value; + unsigned int x; + std::stringstream ss; + if(base == 16) + { + ss << std::hex; + } + ss << str; + ss >> x; + return x; } /** Convert string values to unsigned long. @@ -86,10 +91,15 @@ inline int stoi(const std::string &str) * * @return Unsigned long representation of @p str. */ -inline unsigned long stoul(const std::string &str) +inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, int base = 10) { - std::stringstream stream(str); + std::stringstream stream; unsigned long value = 0; + if(base == 16) + { + stream << std::hex; + } + stream << str; stream >> value; return value; } @@ -339,24 +349,37 @@ inline bool isfinite(half_float::half value) namespace cpp14 { /** make_unique is missing in CPP11. Re-implement it according to the standard proposal. */ + +/**<Template for single object */ template <class T> struct _Unique_if { - typedef std::unique_ptr<T> _Single_object; + typedef std::unique_ptr<T> _Single_object; /**< Single object type */ }; +/** Template for array */ template <class T> struct _Unique_if<T[]> { - typedef std::unique_ptr<T[]> _Unknown_bound; + typedef std::unique_ptr<T[]> _Unknown_bound; /**< Array type */ }; +/** Template for array with known bounds (to throw an error). + * + * @note this is intended to never be hit. + */ template <class T, size_t N> struct _Unique_if<T[N]> { - typedef void _Known_bound; + typedef void _Known_bound; /**< Should never be used */ }; +/** Construct a single object and return a unique pointer to it. + * + * @param[in] args Constructor arguments. + * + * @return a unique pointer to the new object. + */ template <class T, class... Args> typename _Unique_if<T>::_Single_object make_unique(Args &&... args) @@ -364,6 +387,12 @@ make_unique(Args &&... args) return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } +/** Construct an array of objects and return a unique pointer to it. + * + * @param[in] n Array size + * + * @return a unique pointer to the new array. + */ template <class T> typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) @@ -372,6 +401,7 @@ make_unique(size_t n) return std::unique_ptr<T>(new U[n]()); } +/** It is invalid to attempt to make_unique an array with known bounds. */ template <class T, class... Args> typename _Unique_if<T>::_Known_bound make_unique(Args &&...) = delete; |