Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:43

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     http://www.boost.org/
0005 
0006     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0007     Software License, Version 1.0. (See accompanying file
0008     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 
0011 #if !defined(BOOST_TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED)
0012 #define BOOST_TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED
0013 
0014 #include <ctime>
0015 #include <cstring>
0016 
0017 #include <boost/config.hpp>
0018 #include <boost/spirit/include/classic_core.hpp>
0019 #include <boost/spirit/include/classic_symbols.hpp>
0020 #include <boost/spirit/include/classic_assign_actor.hpp>
0021 #include <boost/spirit/include/classic_push_back_actor.hpp>
0022 
0023 #if !defined(spirit_append_actor)
0024 #define spirit_append_actor(actor) boost::spirit::classic::push_back_a(actor)
0025 #define spirit_assign_actor(actor) boost::spirit::classic::assign_a(actor)
0026 #endif // !defined(spirit_append_actor)
0027 
0028 // this must occur after all of the includes and before any code appears
0029 #ifdef BOOST_HAS_ABI_HEADERS
0030 #include BOOST_ABI_PREFIX
0031 #endif
0032 
0033 ///////////////////////////////////////////////////////////////////////////////
0034 namespace boost {
0035 namespace wave {
0036 namespace util {
0037 
0038 namespace time_conversion {
0039 
0040     using namespace std;    // some systems have std::tm etc. in namespace std
0041 
0042 ///////////////////////////////////////////////////////////////////////////////
0043 //  define, whether the rule's should generate some debug output
0044 #define TRACE_CPP_TIME_CONVERSION \
0045     (BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_TIME_CONVERSION) \
0046     /**/
0047 
0048 ///////////////////////////////////////////////////////////////////////////////
0049 //  Grammar for parsing a date/time string generated by the C++ compiler from
0050 //  __DATE__ and __TIME__
0051     class time_conversion_grammar :
0052         public boost::spirit::classic::grammar<time_conversion_grammar>
0053     {
0054     public:
0055         time_conversion_grammar() : fYearIsCorrected(false)
0056         {
0057             using namespace std;        // some systems have memset in std
0058             memset (&time_stamp, 0, sizeof(tm));
0059             BOOST_SPIRIT_DEBUG_TRACE_RULE_NAME(*this, "time_conversion_grammar",
0060                 TRACE_CPP_TIME_CONVERSION);
0061         }
0062 
0063         template <typename ScannerT>
0064         struct definition {
0065 
0066             definition(time_conversion_grammar const &self)
0067             {
0068                 using boost::spirit::classic::int_p;
0069                 using boost::spirit::classic::add;
0070 
0071             char const *m[] = {
0072                     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
0073                     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
0074                 };
0075 
0076                 for (int i = 0; i < 12; ++i)
0077                     add (month, m[i], i);
0078 
0079                 time_rule       // expected format is 'Dec 29 2001 11:23:59'
0080                     =   month[spirit_assign_actor(self.time_stamp.tm_mon)]
0081                     >>  int_p[spirit_assign_actor(self.time_stamp.tm_mday)]
0082                     >>  int_p[spirit_assign_actor(self.time_stamp.tm_year)]
0083                     >>  int_p[spirit_assign_actor(self.time_stamp.tm_hour)] >> ':'
0084                     >>  int_p[spirit_assign_actor(self.time_stamp.tm_min)] >> ':'
0085                     >>  int_p[spirit_assign_actor(self.time_stamp.tm_sec)]
0086                     ;
0087 
0088                 BOOST_SPIRIT_DEBUG_TRACE_RULE(time_rule, TRACE_CPP_TIME_CONVERSION);
0089             }
0090 
0091             boost::spirit::classic::rule<ScannerT> time_rule;
0092             boost::spirit::classic::symbols<> month;
0093 
0094             boost::spirit::classic::rule<ScannerT> const&
0095             start() const { return time_rule; }
0096         };
0097 
0098         void correct_year()
0099         {
0100             if (!fYearIsCorrected) {
0101                 time_stamp.tm_year -= 1900;
0102                 fYearIsCorrected = true;
0103             }
0104         }
0105 
0106         mutable tm time_stamp;
0107         bool fYearIsCorrected;
0108     };
0109 
0110 ///////////////////////////////////////////////////////////////////////////////
0111 // calculate the time of the compilation as a std::time_t to ensure correctness
0112 // of the saved dfa table
0113     class time_conversion_helper
0114     {
0115     public:
0116         time_conversion_helper(char const *act_time) : compile_time(0)
0117         {
0118             using namespace boost::spirit::classic;
0119 
0120         time_conversion_grammar g;
0121         parse_info<> pi = parse (act_time, g, space_p);
0122 
0123             if (pi.hit) {
0124                 g.correct_year();
0125                 compile_time = mktime(&g.time_stamp);
0126             }
0127             BOOST_ASSERT(0 != compile_time);
0128         }
0129 
0130         time_t get_time() const { return compile_time; }
0131 
0132     private:
0133         time_t compile_time;
0134     };
0135 
0136 ///////////////////////////////////////////////////////////////////////////////
0137 #undef TRACE_CPP_TIME_CONVERSION
0138 }   // namespace time_conversion
0139 
0140 // import time_conversion into the boost::wave::util namespace
0141 using namespace time_conversion;
0142 
0143 ///////////////////////////////////////////////////////////////////////////////
0144 }   // namespace util
0145 }   // namespace wave
0146 }   // namespace boost
0147 
0148 // the suffix header occurs after all of the code
0149 #ifdef BOOST_HAS_ABI_HEADERS
0150 #include BOOST_ABI_SUFFIX
0151 #endif
0152 
0153 #endif // !defined(BOOST_TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED)