/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* $Id: vctFixedSizeVectorRef.h,v 1.17 2007/04/26 19:33:58 anton Exp $ Author(s): Ofri Sadowsky, Anton Deguet Created on: 2003-09-30 (C) Copyright 2003-2007 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ /*! \file \brief Declaration of vctFixedSizeVectorRef */ #ifndef _vctFixedSizeVectorRef_h #define _vctFixedSizeVectorRef_h #include /*! \brief An implementation of the ``abstract'' vctFixedSizeVectorBase. \ingroup cisstVector This implementations uses a pointer to the vector beginning as the vector defining data member. An instantiation of this type can be used as a subsequence with GetSubsequence(). See the base class (vctFixedSizeVectorBase) for template parameter details. \sa vctFixedSizeConstVectorRef */ template class vctFixedSizeVectorRef : public vctFixedSizeVectorBase< _size, _stride, _elementType, typename vctFixedSizeVectorTraits<_elementType, _size, _stride>::pointer > { public: VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType); typedef vctFixedSizeVectorTraits<_elementType, _size, _stride> VectorTraits; typedef vctFixedSizeVectorRef ThisType; typedef vctFixedSizeVectorBase<_size, _stride, value_type, pointer> BaseType; typedef typename BaseType::CopyType CopyType; /*! Default constructor: create an uninitialized vector */ vctFixedSizeVectorRef() {} /*! Initialize the vector with a (non-const) pointer */ vctFixedSizeVectorRef(pointer p) { SetRef(p); } /*! Initialize a fixed size reference to a fixed-size vector. \note This constructor is explicit. \note The stride values are taken from the fixed size vector. */ template explicit vctFixedSizeVectorRef(vctFixedSizeVectorBase<__size, _stride, _elementType, __dataPtrType> & otherVector, size_type startPosition = 0) { SetRef(otherVector, startPosition); } /*! Initialize a fixed size reference to a dynamic vector. \note This constructor is declared as explicit, since it is atypical. */ template explicit vctFixedSizeVectorRef(vctDynamicVectorBase<__vectorOwnerType, _elementType> & otherVector, size_type startPosition = 0) { SetRef(otherVector, startPosition); } /*! Assign the vector start with a (non-const) pointer */ void SetRef(pointer p) { this->Data = p; } /*! Set a fixed size reference to a fixed-size vector. \note the stride of the input vector must be identical to the stride of this vector (this is enforced by the template parameters). \note this vector must be contained in the input vector, that is, startPos+_size <= __size (otherwise cmnThrow is used to throw std::out_of_range). */ template void SetRef(vctFixedSizeVectorBase<__size, _stride, _elementType, __dataPtrType> & otherVector, size_type startPosition = 0) { if (startPosition + this->size() > otherVector.size()) { cmnThrow(std::out_of_range("vctFixedSizeVectorRef SetRef out of range")); } SetRef(otherVector.Pointer(startPosition)); } /*! Set a fixed size reference to a dynamic vector. \note the stride of the input vector must be identical to the stride of this vector (otherwise cmnThrow is used to throw std::runtime_error). \note this vector must be contained in the input vector, that is, startPos+_size <= __size (otherwise cmnThrow is used to throw std::out_of_range). */ template void SetRef(vctDynamicVectorBase<__vectorOwnerType, _elementType> & otherVector, size_type startPosition = 0) { if (this->stride() != otherVector.stride()) { cmnThrow(std::runtime_error("vctFixedSizeVectorRef SetRef with incompatible stride")); } if (startPosition + this->size() > otherVector.size()) { cmnThrow(std::out_of_range("vctFixedSizeVectorRef SetRef out of range")); } SetRef(otherVector.Pointer(startPosition)); } /*! Assignment operation between vectors of different types \param other The vector to be copied. */ //@{ inline CISST_DEPRECATED ThisType & operator=(const ThisType & other) { return reinterpret_cast(this->Assign(other)); } template inline ThisType & operator=(const vctFixedSizeConstVectorRef & other) { return reinterpret_cast(this->Assign(other)); } template inline ThisType & operator=(const vctFixedSizeConstVectorBase<_size, __stride, __elementType, __dataPtrType> & other) { return reinterpret_cast(this->Assign(other)); } //@} /*! Assignement of a scalar to all elements. See also SetAll. */ inline ThisType & operator = (const value_type & value) { this->SetAll(value); return *this; } }; #endif // _vctFixedSizeVectorRef_h // **************************************************************************** // Change History // **************************************************************************** // // $Log: vctFixedSizeVectorRef.h,v $ // Revision 1.17 2007/04/26 19:33:58 anton // All files in libraries: Applied new license text, separate copyright and // updated dates, added standard header where missing. // // Revision 1.16 2006/11/20 20:33:20 anton // Licensing: Applied new license to cisstCommon, cisstVector, cisstNumerical, // cisstInteractive, cisstImage and cisstOSAbstraction. // // Revision 1.15 2006/10/16 20:45:10 anton // cisstVector: Corrected and completed tests on size and strides for the // SetRef on all containers (see #247). // // Revision 1.14 2005/12/02 16:23:54 anton // cisstVector: Added assigment operator from scalar (see ticket #191). // // Revision 1.13 2005/09/27 18:01:25 anton // cisstVector: Use CMN_ASSERT instead of assert for vectors and matrices. // // Revision 1.12 2005/09/26 15:41:47 anton // cisst: Added modelines for emacs and vi. // // Revision 1.11 2005/07/19 15:31:56 anton // vctFixedSizeVectorRef: Marked operator = from same type as deprecated. See // check-in #1236 for vctDynamicVectorRef. // // Revision 1.10 2005/06/16 03:38:29 anton // Port to gcc 3.4 (common, vector and numerical) tested with gcc 3.3 and MS // VC 7.1 (.Net 2003). // // Revision 1.9 2005/05/19 19:29:01 anton // cisst libs: Added the license to cisstCommon and cisstVector // // Revision 1.8 2005/02/08 21:30:26 ofri // vctFixedSize(Const)VectorRef: Corrected syntax error in SetRef(dynamic) : // replaced = with ==. // // Revision 1.7 2005/01/06 18:54:00 anton // cisstVector: Introduction of type CopyType as requested in ticket #113. // // Revision 1.6 2004/11/18 20:57:30 ofri // RE: ticket #92. Redefined all operator= I could find to return a ThisType & // instead of const ThisType &. This included corresponding revision of the // Assign methods, and also definition from scratch of operator= for fixed and // dynamic matrix ref. // // Revision 1.5 2004/11/11 20:35:46 anton // cisstVector: *: Added a vctContainerTraits to centralize the declarations // of size_type, difference_type, reference, const_reference, etc. *: All // iterators are now derived from std::iterator. *: Added some missing typedef // for iterators. // // Revision 1.4 2004/10/26 15:20:52 ofri // Updating subsequence interfaces (ticket #76) and interfaces between fixed // and dynamic vectors/matrices (ticket #72). // *: vctFixedSize(Const)VectorBase::Get(Const)Subsequence now deprecated. // Replaced by Get(Const)Subvector with equal stride to the parent. // *: Added constructors for [Fixed|Dynamic][Vector|Matrix]Ref from the other // storage type. // // Revision 1.3 2004/10/25 19:19:54 anton // cisstVector: Created vctForwardDeclarations.h and removed forward // declarations of classes in all other files. Added some constructors // for vector references to reference fixed size from dynamic and vice versa. // // Revision 1.2 2004/10/25 13:52:05 anton // Doxygen documentation: Cleanup all the useless \ingroup. // // Revision 1.1 2004/08/13 17:47:40 anton // cisstVector: Massive renaming to replace the word "sequence" by "vector" // (see ticket #50) as well as another more systematic naming for the engines. // The changes for the API are as follow: // *: vctFixedLengthSequenceBase -> vctFixedSizeVectorBase (and Const) // *: vctFixedLengthSequenceRef -> vctFixedSizeVectorRef (and Const) // *: vctDynamicSequenceBase -> vctDynamicVectorBase (and Const) // *: vctDynamicSequenceRef -> vctDynamicVectorRef (and Const) // *: vctDynamicSequenceRefOwner -> vctDynamicVectorRefOwner // *: vctFixedStrideSequenceIterator -> vctFixedStrideVectorIterator (and Const) // *: vctVarStrideSequenceIterator -> vctVarStrideVectorIterator (and Const) // *: vctSequenceRecursiveEngines -> vctFixedSizeVectorRecursiveEngines // *: vctSequenceLoopEngines -> vctDynamicVectorLoopEngines // *: vctMatrixLoopEngines -> vctFixedSizeMatrixLoopEngines // *: vctDynamicMatrixEngines -> vctDynamicMatrixLoopEngines // Also updated and corrected the documentation (latex, doxygen, figures) as // well as the tests and examples. // // Revision 1.5 2004/08/11 20:38:28 ofri // Removed redundant subsequence definitions from vctFixedLengthSequenceRef // and vctFixedLengthConstSequenceRef, as they are now defined in the base // types. // Added excluded code in vctFixedLengthConstSequenceBase to conditionally // evaulate a compilation error. Pending decision before including. // // Revision 1.4 2004/07/27 20:08:06 anton // cisstVector: Added some Doxygen documentation. Minor code changes to // keep the dynamic vectors in sync with the fixed size ones. // // Revision 1.3 2004/07/02 16:16:45 anton // Massive renaming in cisstVector for the addition of dynamic size vectors // and matrices. The dynamic vectors are far from ready. // // Revision 1.2 2004/04/06 15:23:15 anton // Doxygen clean-up // // Revision 1.1 2003/11/20 18:31:04 anton // Splitted const and non const classes in two files. Renamed FixedLengthSequence to FixedLengthSequenceRef // // // Revision 1.8 2003/11/11 22:04:50 anton // STRIDE undeclared, uses _stride (idem for size). Added assignement operator from vctFixedLengthConstSequenceBase // // Revision 1.7 2003/11/10 21:40:43 anton // Added operator = // // Revision 1.6 2003/11/03 21:31:31 ofri // Changed the order of template parameters when refering to // vctFixedLengthSequenceBase (_elementType now comes third instead of first). // This change of order does not apply to the definition of vctFixedLengthSequence // itself. // // Revision 1.5 2003/10/20 18:35:19 anton // Changed FixedSizeVectorOperations and FixedSizeVectorTraits to FixedLengthSequence Operations and Traits // // Revision 1.4 2003/10/20 17:07:15 anton // Removed commented code // // Revision 1.3 2003/10/03 19:15:51 anton // Updated doxygen documentation // // Revision 1.2 2003/09/30 18:47:16 anton // Renamed template parameters __stride to _subStride // // Revision 1.1 2003/09/30 14:02:49 anton // creation // // // ****************************************************************************