Implement compiler independent dynamic local buffers (Buffer.hh)
[senf.git] / Utils / IteratorTraits.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IteratorTraits public header */
23
24 #ifndef HH_IteratorTraits_
25 #define HH_IteratorTraits_ 1
26
27 // Custom includes
28 #include <vector>
29 #include <string>
30
31 //#include "IteratorTraits.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
33
34 namespace senf {
35
36 // The following is *not* standard mandated but it *is* mandated by TR1 and I know of no
37 // implementation for which this is not correct
38
39 #define SENF_VECTOR_IS_CONTIGUOUS 1
40 #define SENF_STRING_IS_CONTIGUOUS 1
41     
42     /** \brief Check for contiguous mutable storage
43
44         This type trait returns \c true, if \a RandomAccessIterator is an iterator into a contiguous
45         storage area which may be written to. If this is the case, some algorithms may be optimized
46         by directly modifying the underlying storage instead of relying on the STL interface.
47         
48         This trait is predefined to return \c true for pointers and for the iterators of \c
49         std::vector and \c std::basic_string (and so for \c std::string and \c std::wstring). This
50         is \e not required by the current standard. It is however required for \c std::vector in the
51         first corrigendum to the standard, TR1. Furthermore almost all implementations for \c
52         std::vector do follow this approach. 
53
54         For \c std::string the case is different, there are libraries which use reference counting
55         and shared ownership for strings, however no library with which SENF has been tested to date
56         has strings of this variety. If SENF is used with such a standard library implementation,
57         this header has to be adjysted to define the preprocessor symbol \c
58         SENF_STRING_IS_CONTIGUOUS accordingly.
59      */
60     template <class RandomAccessIterator>
61     struct contiguous_storage_iterator
62         : public boost::false_type
63     {};
64
65     template <class T>
66     struct contiguous_storage_iterator<T *>
67         : public boost::true_type
68     {};
69
70 #if defined(SENF_VECTOR_IS_CONTIGUOUS)
71     template <class T, class Alloc>
72     struct contiguous_storage_iterator< typename std::vector<T,Alloc>::iterator >
73         : public boost::true_type
74     {};
75 #endif
76
77 #if defined(SENF_STRING_IS_CONTIGUOUS)
78     template <class CharT, class Traits, class Alloc>
79     struct contiguous_storage_iterator< typename std::basic_string<CharT, Traits, Alloc>::iterator >
80         : public boost::true_type
81     {};
82 #endif
83
84     /** \brief Convert contiguous storage iterator to pointer
85         
86         storage_iterator will convert a contiguous storage iterator into a pointer to the same
87         element in the container. This allows to directly access the containers storage.
88      */
89     template <class Iterator>
90     typename std::iterator_traits<Iterator>::pointer storage_iterator(Iterator i);
91     
92 }
93
94 ///////////////////////////////hh.e////////////////////////////////////////
95 //#include "IteratorTraits.cci"
96 //#include "IteratorTraits.ct"
97 //#include "IteratorTraits.cti"
98 #endif
99
100 \f
101 // Local Variables:
102 // mode: c++
103 // fill-column: 100
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // End: