1 // Copyright (C) 2007 Timothy Brownawell <tbrownaw@gmail.com>
2 //
3 // This program is made available under the GNU GPL version 2.0 or
4 // greater. See the accompanying file COPYING for details.
5 //
6 // This program is distributed WITHOUT ANY WARRANTY; without even the
7 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE.
9 
10 #ifndef __VOCAB_CAST_HH
11 #define __VOCAB_CAST_HH
12 
13 #include <algorithm>
14 
15 // You probably won't use this yourself, but it's needed by...
16 template<typename To, typename From>
17 To typecast_vocab(From const & from)
18 { return To(from(), from.made_from); }
19 
20 // There are a few places where we want to typecast an entire
21 // container full of vocab types.
22 template<typename From, typename To>
typecast_vocab_container(From const & from,To & to)23 void typecast_vocab_container(From const & from, To & to)
24 {
25   std::transform(from.begin(), from.end(), std::inserter(to, to.end()),
26                  &typecast_vocab<typename To::value_type,
27                  typename From::value_type>);
28 }
29 
30 // You won't use this directly either.
31 template<typename To, typename From>
32 To add_decoration(From const & from)
33 {
34   return To(from);
35 }
36 
37 // There are also some places that want to decorate a container full
38 // of vocab types.
39 template<typename From, typename To>
add_decoration_to_container(From const & from,To & to)40 void add_decoration_to_container(From const & from, To & to)
41 {
42   std::transform(from.begin(), from.end(), std::inserter(to, to.end()),
43                  &add_decoration<typename To::value_type,
44                  typename From::value_type>);
45 }
46 
47 template<typename From, typename To>
vocabify_container(From const & from,To & to)48 void vocabify_container(From const & from, To & to)
49 {
50   add_decoration_to_container(from, to);
51 }
52 
53 #endif
54 
55 // Local Variables:
56 // mode: C++
57 // fill-column: 76
58 // c-file-style: "gnu"
59 // indent-tabs-mode: nil
60 // End:
61 // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
62