Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2003 Joel de Guzman
|
Chris@16
|
3 http://spirit.sourceforge.net/
|
Chris@16
|
4
|
Chris@16
|
5 Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 =============================================================================*/
|
Chris@16
|
9 #ifndef BOOST_SPIRIT_SYMBOLS_IPP
|
Chris@16
|
10 #define BOOST_SPIRIT_SYMBOLS_IPP
|
Chris@16
|
11
|
Chris@16
|
12 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
13 #include <boost/spirit/home/classic/symbols/impl/tst.ipp>
|
Chris@16
|
14 #include <boost/detail/workaround.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 // MSVC: void warning about the use of 'this' pointer in constructors
|
Chris@16
|
17 #if defined(BOOST_MSVC)
|
Chris@16
|
18 #pragma warning(push)
|
Chris@16
|
19 #pragma warning(disable : 4355)
|
Chris@16
|
20 #endif
|
Chris@16
|
21
|
Chris@16
|
22 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
23 namespace boost { namespace spirit {
|
Chris@16
|
24
|
Chris@16
|
25 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
26
|
Chris@16
|
27 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
28 //
|
Chris@16
|
29 // symbols class implementation
|
Chris@16
|
30 //
|
Chris@16
|
31 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
32 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
33 inline symbols<T, CharT, SetT>::symbols()
|
Chris@16
|
34 : SetT()
|
Chris@16
|
35 , add(*this)
|
Chris@16
|
36 {
|
Chris@16
|
37 }
|
Chris@16
|
38
|
Chris@16
|
39 //////////////////////////////////
|
Chris@16
|
40 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
41 symbols<T, CharT, SetT>::symbols(symbols const& other)
|
Chris@16
|
42 : SetT(other)
|
Chris@16
|
43 // Tru64 CXX seems to be confused by the explicit call of the default
|
Chris@16
|
44 // constructor and generates wrong code which invalidates the just contructed
|
Chris@16
|
45 // first base class in the line above.
|
Chris@16
|
46 #if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590041))
|
Chris@16
|
47 , parser<symbols<T, CharT, SetT> >()
|
Chris@16
|
48 #endif
|
Chris@16
|
49 , add(*this)
|
Chris@16
|
50 {
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 //////////////////////////////////
|
Chris@16
|
54 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
55 inline symbols<T, CharT, SetT>::~symbols()
|
Chris@16
|
56 {}
|
Chris@16
|
57
|
Chris@16
|
58 //////////////////////////////////
|
Chris@16
|
59 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
60 inline symbols<T, CharT, SetT>&
|
Chris@16
|
61 symbols<T, CharT, SetT>::operator=(symbols const& other)
|
Chris@16
|
62 {
|
Chris@16
|
63 SetT::operator=(other);
|
Chris@16
|
64 return *this;
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 //////////////////////////////////
|
Chris@16
|
68 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
69 inline symbol_inserter<T, SetT> const&
|
Chris@16
|
70 symbols<T, CharT, SetT>::operator=(CharT const* str)
|
Chris@16
|
71 {
|
Chris@16
|
72 return add, str;
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
76 //
|
Chris@16
|
77 // Symbol table utilities
|
Chris@16
|
78 //
|
Chris@16
|
79 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
80 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
81 inline T*
|
Chris@16
|
82 find(symbols<T, CharT, SetT> const& table, CharT const* sym)
|
Chris@16
|
83 {
|
Chris@16
|
84 CharT const* last = sym;
|
Chris@16
|
85 while (*last)
|
Chris@16
|
86 last++;
|
Chris@16
|
87 scanner<CharT const *> scan(sym, last);
|
Chris@16
|
88 T* result = table.find(scan);
|
Chris@16
|
89 return scan.at_end()? result: 0;
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 //////////////////////////////////
|
Chris@16
|
93 template <typename T, typename CharT, typename SetT>
|
Chris@16
|
94 inline T*
|
Chris@16
|
95 add(symbols<T, CharT, SetT>& table, CharT const* sym, T const& data)
|
Chris@16
|
96 {
|
Chris@16
|
97 CharT const* first = sym;
|
Chris@16
|
98 CharT const* last = sym;
|
Chris@16
|
99 while (*last)
|
Chris@16
|
100 last++;
|
Chris@16
|
101 scanner<CharT const *> scan(first, last);
|
Chris@16
|
102 if (table.find(scan) && scan.at_end())
|
Chris@16
|
103 return 0; // symbol already contained in symbol table
|
Chris@16
|
104 table.add(sym, last, data);
|
Chris@16
|
105 first = sym;
|
Chris@16
|
106 return table.find(scan); // refind the inserted symbol
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
110 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
111
|
Chris@16
|
112 }} // namespace boost::spirit
|
Chris@16
|
113
|
Chris@16
|
114 #if defined(BOOST_MSVC)
|
Chris@16
|
115 #pragma warning(pop)
|
Chris@16
|
116 #endif
|
Chris@16
|
117
|
Chris@16
|
118 #endif
|