2014-07-07 15:20:21 +10:00
|
|
|
/*
|
2015-04-13 18:05:28 +10:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2014-07-07 15:20:21 +10:00
|
|
|
*
|
2015-04-13 18:05:28 +10:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-07-07 15:20:21 +10:00
|
|
|
*
|
2015-04-13 18:05:28 +10:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2014-07-07 15:20:21 +10:00
|
|
|
*
|
|
|
|
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pascal.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
using util::parray;
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
parray<T>::parray (size_t _size, T *_data):
|
|
|
|
size (_size),
|
|
|
|
data (_data)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
T&
|
|
|
|
parray<T>::operator[] (size_t idx) {
|
|
|
|
return data[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T&
|
|
|
|
parray<T>::operator[] (size_t idx) const {
|
|
|
|
return data[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
T&
|
|
|
|
parray<T>::at (size_t idx) {
|
|
|
|
if (idx >= size)
|
|
|
|
throw std::out_of_range ("invalid index for parray");
|
|
|
|
|
|
|
|
return (*this)[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T&
|
|
|
|
parray<T>::at (size_t idx) const {
|
|
|
|
if (idx >= size)
|
|
|
|
throw std::out_of_range ("invalid index for parray");
|
|
|
|
|
|
|
|
return (*this)[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
T*
|
2014-07-29 02:20:24 +10:00
|
|
|
parray<T>::begin (void) const {
|
2014-07-07 15:20:21 +10:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T*
|
2014-07-29 02:20:24 +10:00
|
|
|
parray<T>::end (void) const {
|
2014-07-07 15:20:21 +10:00
|
|
|
return data + size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
const T*
|
|
|
|
parray<T>::cbegin (void) const {
|
2014-09-01 16:26:29 +10:00
|
|
|
return data;
|
2014-07-07 15:20:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T*
|
|
|
|
parray<T>::cend (void) const {
|
|
|
|
return data + size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
std::ostream&
|
2014-09-01 16:26:47 +10:00
|
|
|
util::operator<< (std::ostream &os, parray<T> p) {
|
2014-07-07 15:20:21 +10:00
|
|
|
os << "[" << p.size << ", " << std::hex << p.data << std::dec << "]";
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 16:26:47 +10:00
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<uint16_t>);
|
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<uint32_t>);
|
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<uint64_t>);
|
2014-07-07 15:20:21 +10:00
|
|
|
|
2014-09-01 16:26:47 +10:00
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<const uint16_t>);
|
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<const uint32_t>);
|
|
|
|
template std::ostream& util::operator<< (std::ostream&, parray<const uint64_t>);
|
2014-07-07 15:20:21 +10:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
namespace util {
|
2014-09-01 16:26:47 +10:00
|
|
|
template struct parray<char>;
|
|
|
|
template struct parray<const char>;
|
|
|
|
|
2014-07-23 15:53:18 +10:00
|
|
|
template struct parray<int8_t>;
|
|
|
|
template struct parray<int16_t>;
|
|
|
|
template struct parray<int32_t>;
|
|
|
|
template struct parray<int64_t>;
|
|
|
|
|
|
|
|
template struct parray<uint8_t>;
|
2014-07-07 15:20:21 +10:00
|
|
|
template struct parray<uint16_t>;
|
|
|
|
template struct parray<uint32_t>;
|
|
|
|
template struct parray<uint64_t>;
|
|
|
|
|
2014-07-23 15:53:18 +10:00
|
|
|
template struct parray<const int8_t>;
|
|
|
|
template struct parray<const int16_t>;
|
|
|
|
template struct parray<const int32_t>;
|
|
|
|
template struct parray<const int64_t>;
|
|
|
|
|
|
|
|
template struct parray<const uint8_t>;
|
2014-07-07 15:20:21 +10:00
|
|
|
template struct parray<const uint16_t>;
|
|
|
|
template struct parray<const uint32_t>;
|
|
|
|
template struct parray<const uint64_t>;
|
|
|
|
}
|