source: NonGTP/Boost/boost/spirit/symbols/impl/symbols.ipp @ 857

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