/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \*---------------------------------------------------------------------------*/ #include "error.H" #include "pTraits.H" #include "Swap.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template inline Foam::UList::UList() : size_(0), v_(0) {} template inline Foam::UList::UList(T* __restrict__ v, label size) : size_(size), v_(v) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline const Foam::UList& Foam::UList::null() { return *reinterpret_cast< UList* >(0); } template inline Foam::label Foam::UList::fcIndex(const label i) const { return (i == size()-1 ? 0 : i+1); } template inline Foam::label Foam::UList::rcIndex(const label i) const { return (i ? i-1 : size()-1); } // Check start is within valid range (0 ... size-1). template inline void Foam::UList::checkStart(const label start) const { if (start<0 || (start && start>=size_)) { FatalErrorIn("UList::checkStart(const label)") << "start " << start << " out of range 0 ... " << max(size_-1, 0) << abort(FatalError); } } // Check size is within valid range (0 ... size). template inline void Foam::UList::checkSize(const label size) const { if (size<0 || size>size_) { FatalErrorIn("UList::checkSize(const label)") << "size " << size << " out of range 0 ... " << size_ << abort(FatalError); } } // Check index i is within valid range (0 ... size-1). template inline void Foam::UList::checkIndex(const label i) const { if (!size_) { FatalErrorIn("UList::checkIndex(const label)") << "attempt to access element from zero sized list" << abort(FatalError); } else if (i<0 || i>=size_) { FatalErrorIn("UList::checkIndex(const label)") << "index " << i << " out of range 0 ... " << size_-1 << abort(FatalError); } } template inline T& Foam::UList::last() { return this->operator[](this->size()-1); } template inline const T& Foam::UList::last() const { return this->operator[](this->size()-1); } template inline const T* Foam::UList::cdata() const { return v_; } template inline T* Foam::UList::data() { return v_; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // element access template inline T& Foam::UList::operator[](const label i) { # ifdef FULLDEBUG checkIndex(i); # endif return v_[i]; } namespace Foam { // Template specialization for bool template<> inline const bool& Foam::UList::operator[](const label i) const { // lazy evaluation - return false for out-of-range if (i < size_) { return v_[i]; } else { return Foam::pTraits::zero; } } } // end of namespace Foam // const element access template inline const T& Foam::UList::operator[](const label i) const { # ifdef FULLDEBUG checkIndex(i); # endif return v_[i]; } // Allow cast to a const List& template inline Foam::UList::operator const Foam::List&() const { return *reinterpret_cast*>(this); } // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * // template inline typename Foam::UList::iterator Foam::UList::begin() { return v_; } template inline typename Foam::UList::const_iterator Foam::UList::begin() const { return v_; } template inline typename Foam::UList::const_iterator Foam::UList::cbegin() const { return v_; } template inline typename Foam::UList::iterator Foam::UList::end() { return &v_[size_]; } template inline typename Foam::UList::const_iterator Foam::UList::end() const { return &v_[size_]; } template inline typename Foam::UList::const_iterator Foam::UList::cend() const { return &v_[size_]; } template inline typename Foam::UList::iterator Foam::UList::rbegin() { return &v_[size_-1]; } template inline typename Foam::UList::const_iterator Foam::UList::rbegin() const { return &v_[size_-1]; } template inline typename Foam::UList::const_iterator Foam::UList::crbegin() const { return &v_[size_-1]; } template inline typename Foam::UList::iterator Foam::UList::rend() { return &v_[-1]; } template inline typename Foam::UList::const_iterator Foam::UList::rend() const { return &v_[-1]; } template inline typename Foam::UList::const_iterator Foam::UList::crend() const { return &v_[-1]; } template inline Foam::label Foam::UList::size() const { return size_; } template inline Foam::label Foam::UList::max_size() const { return labelMax; } template inline bool Foam::UList::empty() const { return !size_; } // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template inline void Foam::reverse(UList& ul, const label n) { for (int i=0; i inline void Foam::reverse(UList& ul) { reverse(ul, ul.size()); } // ************************************************************************* //