Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52189 - trunk/boost/spirit/home/support/detail/lexer
From: jamin.hanson_at_[hidden]
Date: 2009-04-05 08:25:57


Author: ben_hanson
Date: 2009-04-05 08:25:56 EDT (Sun, 05 Apr 2009)
New Revision: 52189
URL: http://svn.boost.org/trac/boost/changeset/52189

Log:
New data() interface on state_machine.
Text files modified:
   trunk/boost/spirit/home/support/detail/lexer/state_machine.hpp | 88 ++++++++++++++-------------------------
   1 files changed, 32 insertions(+), 56 deletions(-)

Modified: trunk/boost/spirit/home/support/detail/lexer/state_machine.hpp
==============================================================================
--- trunk/boost/spirit/home/support/detail/lexer/state_machine.hpp (original)
+++ trunk/boost/spirit/home/support/detail/lexer/state_machine.hpp 2009-04-05 08:25:56 EDT (Sun, 05 Apr 2009)
@@ -1,5 +1,5 @@
 // state_machine.hpp
-// Copyright (c) 2007-2008 Ben Hanson (http://www.benhanson.net/)
+// Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -10,6 +10,7 @@
 #include "conversion/char_state_machine.hpp"
 #include "consts.hpp"
 #include <deque>
+#include "internals.hpp"
 #include <map>
 #include "containers/ptr_vector.hpp"
 #include "size_t.hpp"
@@ -224,42 +225,39 @@
     friend class iterator;
 #endif
 
- basic_state_machine () :
- _seen_BOL_assertion (false),
- _seen_EOL_assertion (false)
+ basic_state_machine ()
     {
     }
 
     void clear ()
     {
- _lookup.clear ();
- _dfa_alphabet.clear ();
- _dfa.clear ();
- _seen_BOL_assertion = false;
- _seen_EOL_assertion = false;
+ _internals.clear ();
         _csm.clear ();
     }
 
     bool empty () const
     {
         // Don't include _csm in this test, as irrelevant to state.
- return _lookup->empty () && _dfa_alphabet.empty () &&
- _dfa->empty ();
+ return _internals._lookup->empty () &&
+ _internals._dfa_alphabet.empty () &&
+ _internals._dfa->empty ();
     }
 
     std::size_t size () const
     {
- return _dfa->size ();
+ return _internals._dfa->size ();
     }
 
     bool operator == (const basic_state_machine &rhs_) const
     {
         // Don't include _csm in this test, as irrelevant to state.
- return _lookup == rhs_._lookup &&
- _dfa_alphabet == rhs_._dfa_alphabet &&
- _dfa == rhs_._dfa &&
- _seen_BOL_assertion == rhs_._seen_BOL_assertion &&
- _seen_EOL_assertion == rhs_._seen_EOL_assertion;
+ return _internals._lookup == rhs_._internals._lookup &&
+ _internals._dfa_alphabet == rhs_._internals._dfa_alphabet &&
+ _internals._dfa == rhs_._internals._dfa &&
+ _internals._seen_BOL_assertion ==
+ rhs_._internals._seen_BOL_assertion &&
+ _internals._seen_EOL_assertion ==
+ rhs_._internals._seen_EOL_assertion;
     }
 
     iterator begin () const
@@ -269,7 +267,7 @@
         iter_._sm = const_cast<basic_state_machine *>(this);
         check_for_csm ();
 
- if (!_csm.empty())
+ if (!_csm.empty ())
         {
             const typename detail::basic_char_state_machine<CharT>::
                 state_vector *ptr_ = &_csm._sm_vector[0];
@@ -304,26 +302,17 @@
 
     void swap (basic_state_machine &sm_)
     {
- _lookup->swap (*sm_._lookup);
- _dfa_alphabet.swap (sm_._dfa_alphabet);
- _dfa->swap (*sm_._dfa);
- std::swap (_seen_BOL_assertion, sm_._seen_BOL_assertion);
- std::swap (_seen_EOL_assertion, sm_._seen_EOL_assertion);
+ _internals.swap (sm_._internals);
         _csm.swap (sm_._csm);
     }
 
-// VC++ 6, 7.1 and 8 can't cope with template friend classes!
-#if !(defined _MSC_VER && _MSC_VER < 1500)
-private:
-#endif
- typedef std::vector<std::size_t> size_t_vector;
- typedef detail::ptr_vector<size_t_vector> size_t_vector_vector;
+ const detail::internals &data () const
+ {
+ return _internals;
+ }
 
- size_t_vector_vector _lookup;
- size_t_vector _dfa_alphabet;
- size_t_vector_vector _dfa;
- bool _seen_BOL_assertion;
- bool _seen_EOL_assertion;
+private:
+ detail::internals _internals;
     mutable detail::basic_char_state_machine<CharT> _csm;
 
     void check_for_csm () const
@@ -338,7 +327,7 @@
     {
         const std::size_t max_ = sizeof (CharT) == 1 ?
             num_chars : num_wchar_ts;
- const std::size_t start_states_ = _dfa->size ();
+ const std::size_t start_states_ = _internals._dfa->size ();
 
         sm_.clear ();
         sm_._sm_vector.resize (start_states_);
@@ -346,13 +335,15 @@
         for (std::size_t start_state_index_ = 0;
             start_state_index_ < start_states_; ++start_state_index_)
         {
- const size_t_vector *lu_ = _lookup[start_state_index_];
- const std::size_t alphabet_ = _dfa_alphabet[start_state_index_] - dfa_offset;
+ const detail::internals::size_t_vector *lu_ =
+ _internals._lookup[start_state_index_];
+ const std::size_t alphabet_ =
+ _internals._dfa_alphabet[start_state_index_] - dfa_offset;
             std::vector<std::basic_string<CharT> > chars_ (alphabet_);
- const std::size_t states_ = _dfa[start_state_index_]->size () /
- (alphabet_ + dfa_offset);
- const std::size_t *read_ptr_ = &_dfa[start_state_index_]->
- front () + alphabet_ + dfa_offset;
+ const std::size_t states_ = _internals._dfa[start_state_index_]->
+ size () / (alphabet_ + dfa_offset);
+ const std::size_t *read_ptr_ = &_internals.
+ _dfa[start_state_index_]->front () + alphabet_ + dfa_offset;
 
             sm_._sm_vector[start_state_index_].resize (states_ - 1);
 
@@ -424,21 +415,6 @@
             }
         }
     }
-
-#if !(defined _MSC_VER && _MSC_VER < 1500)
- template<typename ChT, typename Traits>
- friend class basic_file_input;
-
- template<typename ChT, typename Traits>
- friend class basic_generator;
-
- template<typename FwdIter, typename Traits>
- friend class basic_input;
-
- template<typename ChT, class Archive>
- friend void serialise (basic_state_machine &sm_, Archive &ar_,
- unsigned int version_);
-#endif
 };
 
 typedef basic_state_machine<char> state_machine;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk