gslice.h

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- gslice class.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
00031 
00032 /** @file gslice.h
00033  *  This is an internal header file, included by other library headers.
00034  *  You should not attempt to use it directly.
00035  */
00036 
00037 #ifndef _CPP_BITS_GSLICE_H
00038 #define _CPP_BITS_GSLICE_H 1
00039 
00040 #pragma GCC system_header
00041 
00042 namespace std {
00043     
00044     class gslice
00045     {
00046     public:
00047         gslice ();
00048         gslice (size_t, const valarray<size_t>&, const valarray<size_t>&);
00049         // XXX: the IS says the copy-ctor and copy-assignment operators are
00050         //      synthetized by the compiler but they are just unsuitable
00051         //      for a ref-counted semantic
00052         gslice(const gslice&);
00053         ~gslice();
00054 
00055         // XXX: See the note above.
00056         gslice& operator= (const gslice&);
00057         
00058         size_t           start () const;
00059         valarray<size_t> size () const;
00060         valarray<size_t> stride () const;
00061         
00062     private:
00063         struct _Indexer {
00064             size_t _M_count;
00065             size_t _M_start;
00066             valarray<size_t> _M_size;
00067             valarray<size_t> _M_stride;
00068             valarray<size_t> _M_index;
00069             _Indexer(size_t, const valarray<size_t>&,
00070                      const valarray<size_t>&);
00071             void _M_increment_use() { ++_M_count; }
00072             size_t _M_decrement_use() { return --_M_count; }
00073         };
00074 
00075         _Indexer* _M_index;
00076         
00077         template<typename _Tp> friend class valarray;
00078     };
00079     
00080     inline size_t
00081     gslice::start () const
00082     { return _M_index ? _M_index->_M_start : 0; }
00083     
00084     inline valarray<size_t>
00085     gslice::size () const
00086     { return _M_index ? _M_index->_M_size : valarray<size_t>(); }
00087     
00088     inline valarray<size_t>
00089     gslice::stride () const
00090     { return _M_index ? _M_index->_M_stride : valarray<size_t>(); }
00091     
00092     inline gslice::gslice () : _M_index(0) {}
00093 
00094     inline
00095     gslice::gslice(size_t __o, const valarray<size_t>& __l,
00096                    const valarray<size_t>& __s)
00097             : _M_index(new gslice::_Indexer(__o, __l, __s)) {}
00098 
00099     inline
00100     gslice::gslice(const gslice& __g) : _M_index(__g._M_index)
00101     { if (_M_index) _M_index->_M_increment_use(); }
00102     
00103     inline
00104     gslice::~gslice()
00105     { if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index; }
00106 
00107     inline gslice&
00108     gslice::operator= (const gslice& __g)
00109     {
00110         if (__g._M_index) __g._M_index->_M_increment_use();
00111         if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index;
00112         _M_index = __g._M_index;
00113         return *this;
00114     }
00115             
00116     
00117 } // std::
00118 
00119 
00120 #endif /* _CPP_BITS_GSLICE_H */
00121 
00122 // Local Variables:
00123 // mode:c++
00124 // End:

Generated on Thu Feb 10 23:22:54 2005 for libstdc++-v3 Source by  doxygen 1.4.0