Whole document tree
    

Whole document tree

gslice.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

gslice.h

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- gslice class.
00002 
00003 // Copyright (C) 1997-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 #ifndef _CPP_BITS_GSLICE_H
00033 #define _CPP_BITS_GSLICE_H 1
00034 
00035 #pragma GCC system_header
00036 
00037 namespace std {
00038     
00039     class gslice
00040     {
00041     public:
00042         gslice ();
00043         gslice (size_t, const valarray<size_t>&, const valarray<size_t>&);
00044         // XXX: the IS says the copy-ctor and copy-assignment operators are
00045         //      synthetized by the compiler but they are just unsuitable
00046         //      for a ref-counted semantic
00047         gslice(const gslice&);
00048         ~gslice();
00049 
00050         // XXX: See the note above.
00051         gslice& operator= (const gslice&);
00052         
00053         size_t           start () const;
00054         valarray<size_t> size () const;
00055         valarray<size_t> stride () const;
00056         
00057     private:
00058         struct _Indexer {
00059             size_t _M_count;
00060             size_t _M_start;
00061             valarray<size_t> _M_size;
00062             valarray<size_t> _M_stride;
00063             valarray<size_t> _M_index;
00064             _Indexer(size_t, const valarray<size_t>&,
00065                      const valarray<size_t>&);
00066             void _M_increment_use() { ++_M_count; }
00067             size_t _M_decrement_use() { return --_M_count; }
00068         };
00069 
00070         _Indexer* _M_index;
00071         
00072         template<typename _Tp> friend class valarray;
00073     };
00074     
00075     inline size_t
00076     gslice::start () const
00077     { return _M_index ? _M_index->_M_start : 0; }
00078     
00079     inline valarray<size_t>
00080     gslice::size () const
00081     { return _M_index ? _M_index->_M_size : valarray<size_t>(); }
00082     
00083     inline valarray<size_t>
00084     gslice::stride () const
00085     { return _M_index ? _M_index->_M_stride : valarray<size_t>(); }
00086     
00087     inline gslice::gslice () : _M_index(0) {}
00088 
00089     inline
00090     gslice::gslice(size_t __o, const valarray<size_t>& __l,
00091                    const valarray<size_t>& __s)
00092             : _M_index(new gslice::_Indexer(__o, __l, __s)) {}
00093 
00094     inline
00095     gslice::gslice(const gslice& __g) : _M_index(__g._M_index)
00096     { if (_M_index) _M_index->_M_increment_use(); }
00097     
00098     inline
00099     gslice::~gslice()
00100     { if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index; }
00101 
00102     inline gslice&
00103     gslice::operator= (const gslice& __g)
00104     {
00105         if (__g._M_index) __g._M_index->_M_increment_use();
00106         if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index;
00107         _M_index = __g._M_index;
00108         return *this;
00109     }
00110             
00111     
00112 } // std::
00113 
00114 
00115 #endif /* _CPP_BITS_GSLICE_H */
00116 
00117 // Local Variables:
00118 // mode:c++
00119 // End:

Generated on Mon Apr 8 03:11:25 2002 for libstdc++-v3 Source by doxygen1.2.15