Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / algorithm / string / detail / replace_storage.hpp @ 2486

History | View | Annotate | Download (5.8 kB)

1 2486 sjacqu01
//  Boost string_algo library replace_storage.hpp header file  ---------------------------//
2 2486 sjacqu01
3 2486 sjacqu01
//  Copyright Pavol Droba 2002-2003.
4 2486 sjacqu01
//
5 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0.
6 2486 sjacqu01
//    (See accompanying file LICENSE_1_0.txt or copy at
7 2486 sjacqu01
//          http://www.boost.org/LICENSE_1_0.txt)
8 2486 sjacqu01
9 2486 sjacqu01
//  See http://www.boost.org/ for updates, documentation, and revision history.
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
12 2486 sjacqu01
#define BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#include <boost/algorithm/string/config.hpp>
15 2486 sjacqu01
#include <algorithm>
16 2486 sjacqu01
#include <boost/mpl/bool.hpp>
17 2486 sjacqu01
#include <boost/algorithm/string/sequence_traits.hpp>
18 2486 sjacqu01
#include <boost/algorithm/string/detail/sequence.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
namespace boost {
21 2486 sjacqu01
    namespace algorithm {
22 2486 sjacqu01
        namespace detail {
23 2486 sjacqu01
24 2486 sjacqu01
//  storage handling routines -----------------------------------------------//
25 2486 sjacqu01
26 2486 sjacqu01
            template< typename StorageT, typename OutputIteratorT >
27 2486 sjacqu01
            inline OutputIteratorT move_from_storage(
28 2486 sjacqu01
                StorageT& Storage,
29 2486 sjacqu01
                OutputIteratorT DestBegin,
30 2486 sjacqu01
                OutputIteratorT DestEnd )
31 2486 sjacqu01
            {
32 2486 sjacqu01
                OutputIteratorT OutputIt=DestBegin;
33 2486 sjacqu01
34 2486 sjacqu01
                while( !Storage.empty() && OutputIt!=DestEnd )
35 2486 sjacqu01
                {
36 2486 sjacqu01
                    *OutputIt=Storage.front();
37 2486 sjacqu01
                    Storage.pop_front();
38 2486 sjacqu01
                    ++OutputIt;
39 2486 sjacqu01
                }
40 2486 sjacqu01
41 2486 sjacqu01
                return OutputIt;
42 2486 sjacqu01
            }
43 2486 sjacqu01
44 2486 sjacqu01
            template< typename StorageT, typename WhatT >
45 2486 sjacqu01
            inline void copy_to_storage(
46 2486 sjacqu01
                StorageT& Storage,
47 2486 sjacqu01
                const WhatT& What )
48 2486 sjacqu01
            {
49 2486 sjacqu01
                Storage.insert( Storage.end(), ::boost::begin(What), ::boost::end(What) );
50 2486 sjacqu01
            }
51 2486 sjacqu01
52 2486 sjacqu01
53 2486 sjacqu01
//  process segment routine -----------------------------------------------//
54 2486 sjacqu01
55 2486 sjacqu01
            template< bool HasStableIterators >
56 2486 sjacqu01
            struct process_segment_helper
57 2486 sjacqu01
            {
58 2486 sjacqu01
                // Optimized version of process_segment for generic sequence
59 2486 sjacqu01
                template<
60 2486 sjacqu01
                    typename StorageT,
61 2486 sjacqu01
                    typename InputT,
62 2486 sjacqu01
                    typename ForwardIteratorT >
63 2486 sjacqu01
                ForwardIteratorT operator()(
64 2486 sjacqu01
                    StorageT& Storage,
65 2486 sjacqu01
                    InputT& /*Input*/,
66 2486 sjacqu01
                    ForwardIteratorT InsertIt,
67 2486 sjacqu01
                    ForwardIteratorT SegmentBegin,
68 2486 sjacqu01
                    ForwardIteratorT SegmentEnd )
69 2486 sjacqu01
                {
70 2486 sjacqu01
                    // Copy data from the storage until the beginning of the segment
71 2486 sjacqu01
                    ForwardIteratorT It=::boost::algorithm::detail::move_from_storage( Storage, InsertIt, SegmentBegin );
72 2486 sjacqu01
73 2486 sjacqu01
                    // 3 cases are possible :
74 2486 sjacqu01
                    //   a) Storage is empty, It==SegmentBegin
75 2486 sjacqu01
                    //   b) Storage is empty, It!=SegmentBegin
76 2486 sjacqu01
                    //   c) Storage is not empty
77 2486 sjacqu01
78 2486 sjacqu01
                    if( Storage.empty() )
79 2486 sjacqu01
                    {
80 2486 sjacqu01
                        if( It==SegmentBegin )
81 2486 sjacqu01
                        {
82 2486 sjacqu01
                            // Case a) everything is grand, just return end of segment
83 2486 sjacqu01
                            return SegmentEnd;
84 2486 sjacqu01
                        }
85 2486 sjacqu01
                        else
86 2486 sjacqu01
                        {
87 2486 sjacqu01
                            // Case b) move the segment backwards
88 2486 sjacqu01
                            return std::copy( SegmentBegin, SegmentEnd, It );
89 2486 sjacqu01
                        }
90 2486 sjacqu01
                    }
91 2486 sjacqu01
                    else
92 2486 sjacqu01
                    {
93 2486 sjacqu01
                        // Case c) -> shift the segment to the left and keep the overlap in the storage
94 2486 sjacqu01
                        while( It!=SegmentEnd )
95 2486 sjacqu01
                        {
96 2486 sjacqu01
                            // Store value into storage
97 2486 sjacqu01
                            Storage.push_back( *It );
98 2486 sjacqu01
                            // Get the top from the storage and put it here
99 2486 sjacqu01
                            *It=Storage.front();
100 2486 sjacqu01
                            Storage.pop_front();
101 2486 sjacqu01
102 2486 sjacqu01
                            // Advance
103 2486 sjacqu01
                            ++It;
104 2486 sjacqu01
                        }
105 2486 sjacqu01
106 2486 sjacqu01
                        return It;
107 2486 sjacqu01
                    }
108 2486 sjacqu01
                }
109 2486 sjacqu01
            };
110 2486 sjacqu01
111 2486 sjacqu01
            template<>
112 2486 sjacqu01
            struct process_segment_helper< true >
113 2486 sjacqu01
            {
114 2486 sjacqu01
                // Optimized version of process_segment for list-like sequence
115 2486 sjacqu01
                template<
116 2486 sjacqu01
                    typename StorageT,
117 2486 sjacqu01
                    typename InputT,
118 2486 sjacqu01
                    typename ForwardIteratorT >
119 2486 sjacqu01
                ForwardIteratorT operator()(
120 2486 sjacqu01
                    StorageT& Storage,
121 2486 sjacqu01
                    InputT& Input,
122 2486 sjacqu01
                    ForwardIteratorT InsertIt,
123 2486 sjacqu01
                    ForwardIteratorT SegmentBegin,
124 2486 sjacqu01
                    ForwardIteratorT SegmentEnd )
125 2486 sjacqu01
126 2486 sjacqu01
                {
127 2486 sjacqu01
                    // Call replace to do the job
128 2486 sjacqu01
                    ::boost::algorithm::detail::replace( Input, InsertIt, SegmentBegin, Storage );
129 2486 sjacqu01
                    // Empty the storage
130 2486 sjacqu01
                    Storage.clear();
131 2486 sjacqu01
                    // Iterators were not changed, simply return the end of segment
132 2486 sjacqu01
                    return SegmentEnd;
133 2486 sjacqu01
                }
134 2486 sjacqu01
            };
135 2486 sjacqu01
136 2486 sjacqu01
            // Process one segment in the replace_all algorithm
137 2486 sjacqu01
            template<
138 2486 sjacqu01
                typename StorageT,
139 2486 sjacqu01
                typename InputT,
140 2486 sjacqu01
                typename ForwardIteratorT >
141 2486 sjacqu01
            inline ForwardIteratorT process_segment(
142 2486 sjacqu01
                StorageT& Storage,
143 2486 sjacqu01
                InputT& Input,
144 2486 sjacqu01
                ForwardIteratorT InsertIt,
145 2486 sjacqu01
                ForwardIteratorT SegmentBegin,
146 2486 sjacqu01
                ForwardIteratorT SegmentEnd )
147 2486 sjacqu01
            {
148 2486 sjacqu01
                return
149 2486 sjacqu01
                    process_segment_helper<
150 2486 sjacqu01
                        has_stable_iterators<InputT>::value>()(
151 2486 sjacqu01
                                Storage, Input, InsertIt, SegmentBegin, SegmentEnd );
152 2486 sjacqu01
            }
153 2486 sjacqu01
154 2486 sjacqu01
155 2486 sjacqu01
        } // namespace detail
156 2486 sjacqu01
    } // namespace algorithm
157 2486 sjacqu01
} // namespace boost
158 2486 sjacqu01
159 2486 sjacqu01
#endif  // BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP