diff options
author | EdB <[email protected]> | 2015-04-23 20:13:51 +0200 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2015-04-29 14:25:42 +0000 |
commit | d8f817ae7f4241a9ea23140805aaeb724a0ac851 (patch) | |
tree | fd6fc8f82eb32d3e4b0ba9955a0285a135b9073c /src/gallium/state_trackers/clover/util | |
parent | 5d4f085a43ccd1122301421f2013e42a3f0a7604 (diff) |
clover: remove util/compat
Acked-by: Francisco Jerez <[email protected]>
Reviewed-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/util')
-rw-r--r-- | src/gallium/state_trackers/clover/util/compat.hpp | 313 |
1 files changed, 0 insertions, 313 deletions
diff --git a/src/gallium/state_trackers/clover/util/compat.hpp b/src/gallium/state_trackers/clover/util/compat.hpp deleted file mode 100644 index dc063344c3c..00000000000 --- a/src/gallium/state_trackers/clover/util/compat.hpp +++ /dev/null @@ -1,313 +0,0 @@ -// -// Copyright 2012 Francisco Jerez -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef CLOVER_UTIL_COMPAT_HPP -#define CLOVER_UTIL_COMPAT_HPP - -#include <new> -#include <cstring> -#include <cstdlib> -#include <string> -#include <stdint.h> - -namespace clover { - namespace compat { - // XXX - For cases where we can't rely on STL... I.e. the - // interface between code compiled as C++98 and C++11 - // source. Get rid of this as soon as everything can be - // compiled as C++11. - - namespace detail { - template<typename R, typename S> - bool - ranges_equal(const R &a, const S &b) { - if (a.size() != b.size()) - return false; - - for (size_t i = 0; i < a.size(); ++i) - if (a[i] != b[i]) - return false; - - return true; - } - } - - template<typename T> - class vector { - protected: - static T * - alloc(int n, const T *q, int m) { - T *p = reinterpret_cast<T *>(std::malloc(n * sizeof(T))); - - for (int i = 0; i < m; ++i) - new(&p[i]) T(q[i]); - - return p; - } - - static void - free(int n, T *p) { - for (int i = 0; i < n; ++i) - p[i].~T(); - - std::free(p); - } - - public: - typedef T *iterator; - typedef const T *const_iterator; - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - - vector() : p(NULL), _size(0), _capacity(0) { - } - - vector(const vector &v) : - p(alloc(v._size, v.p, v._size)), - _size(v._size), _capacity(v._size) { - } - - vector(const_iterator p, size_type n) : - p(alloc(n, p, n)), _size(n), _capacity(n) { - } - - template<typename C> - vector(const C &v) : - p(alloc(v.size(), NULL, 0)), _size(0), - _capacity(v.size()) { - for (typename C::const_iterator it = v.begin(); it != v.end(); ++it) - new(&p[_size++]) T(*it); - } - - ~vector() { - free(_size, p); - } - - vector & - operator=(const vector &v) { - free(_size, p); - - p = alloc(v._size, v.p, v._size); - _size = v._size; - _capacity = v._size; - - return *this; - } - - bool - operator==(const vector &v) const { - return detail::ranges_equal(*this, v); - } - - void - reserve(size_type n) { - if (_capacity < n) { - T *q = alloc(n, p, _size); - free(_size, p); - - p = q; - _capacity = n; - } - } - - void - resize(size_type n, T x = T()) { - if (n <= _size) { - for (size_type i = n; i < _size; ++i) - p[i].~T(); - - } else { - reserve(n); - - for (size_type i = _size; i < n; ++i) - new(&p[i]) T(x); - } - - _size = n; - } - - void - push_back(const T &x) { - reserve(_size + 1); - new(&p[_size]) T(x); - ++_size; - } - - size_type - size() const { - return _size; - } - - size_type - capacity() const { - return _capacity; - } - - iterator - begin() { - return p; - } - - const_iterator - begin() const { - return p; - } - - iterator - end() { - return p + _size; - } - - const_iterator - end() const { - return p + _size; - } - - reference - operator[](size_type i) { - return p[i]; - } - - const_reference - operator[](size_type i) const { - return p[i]; - } - - private: - iterator p; - size_type _size; - size_type _capacity; - }; - - template<typename T> - class vector_ref { - public: - typedef T *iterator; - typedef const T *const_iterator; - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - - vector_ref(iterator p, size_type n) : p(p), n(n) { - } - - template<typename C> - vector_ref(C &v) : p(&*v.begin()), n(v.size()) { - } - - bool - operator==(const vector_ref &v) const { - return detail::ranges_equal(*this, v); - } - - size_type - size() const { - return n; - } - - iterator - begin() { - return p; - } - - const_iterator - begin() const { - return p; - } - - iterator - end() { - return p + n; - } - - const_iterator - end() const { - return p + n; - } - - reference - operator[](int i) { - return p[i]; - } - - const_reference - operator[](int i) const { - return p[i]; - } - - private: - iterator p; - size_type n; - }; - - class istream { - public: - typedef vector_ref<const unsigned char> buffer_t; - - class error { - public: - virtual ~error() {} - }; - - istream(const buffer_t &buf) : buf(buf), offset(0) {} - - void - read(char *p, size_t n) { - if (offset + n > buf.size()) - throw error(); - - std::memcpy(p, buf.begin() + offset, n); - offset += n; - } - - private: - const buffer_t &buf; - size_t offset; - }; - - class ostream { - public: - typedef vector<unsigned char> buffer_t; - - ostream(buffer_t &buf) : buf(buf), offset(buf.size()) {} - - void - write(const char *p, size_t n) { - buf.resize(offset + n); - std::memcpy(buf.begin() + offset, p, n); - offset += n; - } - - private: - buffer_t &buf; - size_t offset; - }; - - } -} - -#endif |