/* -*- 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: vctDynamicVectorRefOwner.h,v 1.9 2007/04/26 19:33:58 anton Exp $ Author(s): Ofri Sadowsky, Anton Deguet Created on: 2004-07-01 (C) Copyright 2004-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 --- */ #ifndef _vctDynamicVectorRefOwner_h #define _vctDynamicVectorRefOwner_h /*! \file \brief Declaration of vctDynamicVectorRefOwner */ #include /*! \ingroup cisstVector This templated class stores a pointer, a size, and a stride, and allows element access, but does not provide any other operations, and does not own the data */ template class vctDynamicVectorRefOwner { public: /* define most types from vctContainerTraits */ VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType); /* iterators are container specific */ typedef vctVarStrideVectorConstIterator const_iterator; typedef vctVarStrideVectorIterator iterator; typedef vctVarStrideVectorConstIterator const_reverse_iterator; typedef vctVarStrideVectorIterator reverse_iterator; vctDynamicVectorRefOwner() : Size(0) , Stride(1) , Data(0) {} vctDynamicVectorRefOwner(size_type size, value_type * data, stride_type stride = 1) : Size(size) , Stride(stride) , Data(data) {} void SetRef(size_type size, value_type * data, stride_type stride = 1) { Size = size; Stride = stride; Data = data; } size_type size(void) const { return Size; } stride_type stride(void) const { return Stride; } pointer Pointer(int index = 0) { return Data + Stride * index; } const_pointer Pointer(int index = 0) const { return Data + Stride * index; } const_iterator begin(void) const { return const_iterator(Data, Stride); } const_iterator end(void) const { return const_iterator(Data + Size * Stride, Stride); } iterator begin(void) { return iterator(Data, Stride); } iterator end(void) { return iterator(Data + Size * Stride, Stride); } const_reverse_iterator rbegin(void) const { return const_reverse_iterator(Data + (Size-1) * Stride, -Stride); } const_reverse_iterator rend(void) const { return const_reverse_iterator(Data - Stride, -Stride); } reverse_iterator rbegin(void) { return reverse_iterator(Data + (Size-1) * Stride, -Stride); } reverse_iterator rend(void) { return reverse_iterator(Data - Stride, -Stride); } protected: size_type Size; int Stride; value_type* Data; }; #endif // _vctDynamicVectorRefOwner_h // **************************************************************************** // Change History // **************************************************************************** // // $Log: vctDynamicVectorRefOwner.h,v $ // Revision 1.9 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.8 2006/11/20 20:33:20 anton // Licensing: Applied new license to cisstCommon, cisstVector, cisstNumerical, // cisstInteractive, cisstImage and cisstOSAbstraction. // // Revision 1.7 2005/09/26 15:41:47 anton // cisst: Added modelines for emacs and vi. // // Revision 1.6 2005/05/19 19:29:01 anton // cisst libs: Added the license to cisstCommon and cisstVector // // Revision 1.5 2005/02/03 20:25:44 ofri // Added method vctDynamicVectorOwner::stride(), which, apparently, was absent // so far. // // Revision 1.4 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.3 2004/10/25 13:52:05 anton // Doxygen documentation: Cleanup all the useless \ingroup. // // Revision 1.2 2004/08/16 19:19:49 anton // cisstVector: Replaced a couple of "value_type *" by typedefed "pointer" // and "const value_type *" by "const_pointer". // // 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/07/06 19:42:50 ofri // Giving the dynamic vector classes "standard look and feel" in terms of type // members, constructors, and indentations. I made sure that the corresponding // example compiles and runs successfully. // // Revision 1.4 2004/07/06 17:47:11 anton // Dynamic Sequences: // *: Compilation error re. const and const_iterator // *: Added some iterator methods to sequences // *: Compilation errors re. the order (size, stride, data) in constructor. The order is now (size, data, stride = 1) everywhere to be consistant // *: The method Resize is now resize (STL spelling) // // Revision 1.3 2004/07/06 00:53:16 ofri // Added reverse iterators to vctDynamicVectorOwner and vctDynamicSequenceRefOwner. // Fixed some bugs in vctDynamicVectorOwner. // // Revision 1.2 2004/07/02 20:14:07 anton // Code for VarStrideVectorIterator. Added the class as well as some code to // try it. An example is provided in examples/vectorTutorial/main.cpp. // // Revision 1.1 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. // // // ****************************************************************************