]> git.lyx.org Git - lyx.git/blob - boost/boost/tokenizer.hpp
64-bit fix to boost::format.
[lyx.git] / boost / boost / tokenizer.hpp
1 // Boost tokenizer.hpp  -----------------------------------------------------//
2
3 // © Copyright Jeremy Siek and John R. Bandela 2001. 
4
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all
7 // copies. This software is provided "as is" without express or
8 // implied warranty, and with no claim as to its suitability for any
9 // purpose.
10
11 // See http://www.boost.org/libs/tokenizer for documenation
12
13 // Revision History:
14 // 03 Jul 2003   John Bandela
15 //      Converted to new iterator adapter
16 // 02 Feb 2002   Jeremy Siek
17 //      Removed tabs and a little cleanup.
18
19 #ifndef BOOST_TOKENIZER_JRB070303_HPP_
20 #define BOOST_TOKENIZER_JRB070303_HPP_
21
22 #include <boost/token_iterator.hpp>
23 #include <cassert>
24 namespace boost {
25
26   
27   //===========================================================================
28   // A container-view of a tokenized "sequence"
29   template <
30     typename TokenizerFunc = char_delimiters_separator<char>, 
31     typename Iterator = std::string::const_iterator,
32     typename Type = std::string
33   >
34   class tokenizer {
35   private:
36     typedef token_iterator_generator<TokenizerFunc,Iterator,Type> TGen;
37         
38     // It seems that MSVC does not like the unqualified use of iterator,
39     // Thus we use iter internally when it is used unqualified and
40     // the users of this class will always qualify iterator.     
41     typedef typename TGen::type iter;
42     
43   public:
44     
45     typedef iter iterator;
46     typedef iter const_iterator;
47     typedef Type value_type;
48     typedef value_type& reference;
49     typedef const value_type& const_reference;
50     typedef value_type* pointer;
51     typedef const pointer const_pointer;
52     typedef void size_type;
53     typedef void difference_type;
54
55     tokenizer(Iterator first, Iterator last,
56               const TokenizerFunc& f = TokenizerFunc()) 
57       : first_(first), last_(last), f_(f) { }
58         
59     template <typename Container>
60     tokenizer(const Container& c)
61       : first_(c.begin()), last_(c.end()), f_() { }
62     
63     template <typename Container>
64     tokenizer(const Container& c,const TokenizerFunc& f)
65       : first_(c.begin()), last_(c.end()), f_(f) { }
66     
67     void assign(Iterator first, Iterator last){
68       first_ = first;
69       last_ = last;
70     }
71     
72     void assign(Iterator first, Iterator last, const TokenizerFunc& f){
73       assign(first,last);
74       f_ = f;
75     }
76     
77     template <typename Container>
78     void assign(const Container& c){
79       assign(c.begin(),c.end());
80     }
81     
82     
83     template <typename Container>
84     void assign(const Container& c, const TokenizerFunc& f){
85       assign(c.begin(),c.end(),f);
86     }
87     
88     iter begin() const { return iter(f_,first_,last_); }
89     iter end() const { return iter(f_,last_,last_); }
90         
91   private:
92     Iterator first_;
93     Iterator last_;
94     TokenizerFunc f_;
95   };
96
97
98 } // namespace boost
99
100 #endif