Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Chris@16: Definition of the predefined macros Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(CPP_MACROMAP_PREDEF_HPP_HK041119) Chris@16: #define CPP_MACROMAP_PREDEF_HPP_HK041119 Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include // time_conversion_helper Chris@16: Chris@16: // this must occur after all of the includes and before any code appears Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // This file contains the definition of functions needed for the management Chris@16: // of static and dynamic predefined macros, such as __DATE__, __TIME__ etc. Chris@16: // Chris@16: // Note: __FILE__, __LINE__ and __INCLUDE_LEVEL__ are handled in the file Chris@16: // cpp_macromap.hpp. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { Chris@16: namespace wave { Chris@16: namespace util { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: class predefined_macros Chris@16: { Chris@16: typedef BOOST_WAVE_STRINGTYPE string_type; Chris@16: Chris@16: public: Chris@16: // list of static predefined macros Chris@16: struct static_macros { Chris@16: char const *name; Chris@16: boost::wave::token_id token_id; Chris@16: char const *value; Chris@16: }; Chris@16: Chris@16: // list of dynamic predefined macros Chris@16: struct dynamic_macros { Chris@16: char const *name; Chris@16: boost::wave::token_id token_id; Chris@16: string_type (predefined_macros:: *generator)() const; Chris@16: }; Chris@16: Chris@16: private: Chris@16: boost::wave::util::time_conversion_helper compilation_time_; Chris@16: string_type datestr_; // __DATE__ Chris@16: string_type timestr_; // __TIME__ Chris@16: string_type version_; // __SPIRIT_PP_VERSION__/__WAVE_VERSION__ Chris@16: string_type versionstr_; // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__ Chris@16: Chris@16: protected: Chris@16: void reset_datestr() Chris@16: { Chris@16: static const char *const monthnames[] = { Chris@16: "Jan", "Feb", "Mar", "Apr", "May", "Jun", Chris@16: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" Chris@16: }; Chris@16: Chris@16: // for some systems sprintf, time_t etc. is in namespace std Chris@16: using namespace std; Chris@16: Chris@16: time_t tt = time(0); Chris@16: struct tm *tb = 0; Chris@16: Chris@16: if (tt != (time_t)-1) { Chris@16: char buffer[sizeof("\"Oct 11 1347\"")+1]; Chris@16: Chris@16: tb = localtime (&tt); Chris@16: sprintf (buffer, "\"%s %2d %4d\"", Chris@16: monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); Chris@16: datestr_ = buffer; Chris@16: } Chris@16: else { Chris@16: datestr_ = "\"??? ?? ????\""; Chris@16: } Chris@16: } Chris@16: Chris@16: void reset_timestr() Chris@16: { Chris@16: // for some systems sprintf, time_t etc. is in namespace std Chris@16: using namespace std; Chris@16: Chris@16: time_t tt = time(0); Chris@16: struct tm *tb = 0; Chris@16: Chris@16: if (tt != (time_t)-1) { Chris@16: char buffer[sizeof("\"12:34:56\"")+1]; Chris@16: Chris@16: tb = localtime (&tt); Chris@16: sprintf (buffer, "\"%02d:%02d:%02d\"", tb->tm_hour, Chris@16: tb->tm_min, tb->tm_sec); Chris@16: timestr_ = buffer; Chris@16: } Chris@16: else { Chris@16: timestr_ = "\"??:??:??\""; Chris@16: } Chris@16: } Chris@16: Chris@16: void reset_version() Chris@16: { Chris@16: char buffer[sizeof("0x00000000")+1]; Chris@16: Chris@16: // for some systems sprintf, time_t etc. is in namespace std Chris@16: using namespace std; Chris@16: Chris@16: // calculate the number of days since Dec 13 2001 Chris@16: // (the day the Wave project was started) Chris@16: tm first_day; Chris@16: Chris@16: using namespace std; // for some systems memset is in namespace std Chris@16: memset (&first_day, 0, sizeof(tm)); Chris@16: first_day.tm_mon = 11; // Dec Chris@16: first_day.tm_mday = 13; // 13 Chris@16: first_day.tm_year = 101; // 2001 Chris@16: Chris@16: long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day))); Chris@16: Chris@16: sprintf(buffer, "0x%02d%1d%1d%04ld", BOOST_WAVE_VERSION_MAJOR, Chris@16: BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR, Chris@16: seconds/(3600*24)); Chris@16: version_ = buffer; Chris@16: } Chris@16: Chris@16: void reset_versionstr() Chris@16: { Chris@16: char buffer[sizeof("\"00.00.00.0000 \"")+sizeof(BOOST_PLATFORM)+sizeof(BOOST_COMPILER)+4]; Chris@16: Chris@16: // for some systems sprintf, time_t etc. is in namespace std Chris@16: using namespace std; Chris@16: Chris@16: // calculate the number of days since Dec 13 2001 Chris@16: // (the day the Wave project was started) Chris@16: tm first_day; Chris@16: Chris@16: memset (&first_day, 0, sizeof(tm)); Chris@16: first_day.tm_mon = 11; // Dec Chris@16: first_day.tm_mday = 13; // 13 Chris@16: first_day.tm_year = 101; // 2001 Chris@16: Chris@16: long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day))); Chris@16: Chris@16: sprintf(buffer, "\"%d.%d.%d.%ld [%s/%s]\"", BOOST_WAVE_VERSION_MAJOR, Chris@16: BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR, Chris@16: seconds/(3600*24), BOOST_PLATFORM, BOOST_COMPILER); Chris@16: versionstr_ = buffer; Chris@16: } Chris@16: Chris@16: // dynamic predefined macros Chris@16: string_type get_date() const { return datestr_; } // __DATE__ Chris@16: string_type get_time() const { return timestr_; } // __TIME__ Chris@16: Chris@16: // __SPIRIT_PP__/__WAVE__ Chris@16: string_type get_version() const Chris@16: { Chris@16: char buffer[sizeof("0x0000")+1]; Chris@16: Chris@16: using namespace std; // for some systems sprintf is in namespace std Chris@16: sprintf(buffer, "0x%02d%1d%1d", BOOST_WAVE_VERSION_MAJOR, Chris@16: BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR); Chris@16: return buffer; Chris@16: } Chris@16: Chris@16: // __WAVE_CONFIG__ Chris@16: string_type get_config() const Chris@16: { Chris@16: char buffer[sizeof("0x00000000")+1]; Chris@16: Chris@16: using namespace std; // for some systems sprintf is in namespace std Chris@16: sprintf(buffer, "0x%08x", BOOST_WAVE_CONFIG); Chris@16: return buffer; Chris@16: } Chris@16: Chris@16: public: Chris@16: predefined_macros() Chris@16: : compilation_time_(__DATE__ " " __TIME__) Chris@16: { Chris@16: reset(); Chris@16: reset_version(); Chris@16: reset_versionstr(); Chris@16: } Chris@16: Chris@16: void reset() Chris@16: { Chris@16: reset_datestr(); Chris@16: reset_timestr(); Chris@16: } Chris@16: Chris@16: // __SPIRIT_PP_VERSION__/__WAVE_VERSION__ Chris@16: string_type get_fullversion() const { return version_; } Chris@16: Chris@16: // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__ Chris@16: string_type get_versionstr() const { return versionstr_; } Chris@16: Chris@16: // C++ mode Chris@16: static_macros const& static_data_cpp(std::size_t i) const Chris@16: { Chris@16: static static_macros data[] = { Chris@16: { "__STDC__", T_INTLIT, "1" }, Chris@16: { "__cplusplus", T_INTLIT, "199711L" }, Chris@16: { 0, T_EOF, 0 } Chris@16: }; Chris@16: BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); Chris@16: return data[i]; Chris@16: } Chris@16: Chris@16: #if BOOST_WAVE_SUPPORT_CPP0X != 0 Chris@16: // C++11 mode Chris@16: static_macros const& static_data_cpp0x(std::size_t i) const Chris@16: { Chris@16: static static_macros data[] = { Chris@16: { "__STDC__", T_INTLIT, "1" }, Chris@16: { "__cplusplus", T_INTLIT, "201103L" }, Chris@16: { "__STDC_VERSION__", T_INTLIT, "199901L" }, Chris@16: { "__STDC_HOSTED__", T_INTLIT, "0" }, Chris@16: { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, Chris@16: { 0, T_EOF, 0 } Chris@16: }; Chris@16: BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); Chris@16: return data[i]; Chris@16: } Chris@16: #endif Chris@16: Chris@16: #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 Chris@16: // C99 mode Chris@16: static_macros const& static_data_c99(std::size_t i) const Chris@16: { Chris@16: static static_macros data[] = { Chris@16: { "__STDC__", T_INTLIT, "1" }, Chris@16: { "__STDC_VERSION__", T_INTLIT, "199901L" }, Chris@16: { "__STDC_HOSTED__", T_INTLIT, "0" }, Chris@16: { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, Chris@16: { 0, T_EOF, 0 } Chris@16: }; Chris@16: BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); Chris@16: return data[i]; Chris@16: } Chris@16: #endif Chris@16: Chris@16: dynamic_macros const& dynamic_data(std::size_t i) const Chris@16: { Chris@16: static dynamic_macros data[] = { Chris@16: { "__DATE__", T_STRINGLIT, &predefined_macros::get_date }, Chris@16: { "__TIME__", T_STRINGLIT, &predefined_macros::get_time }, Chris@16: { "__SPIRIT_PP__", T_INTLIT, &predefined_macros::get_version }, Chris@16: { "__SPIRIT_PP_VERSION__", T_INTLIT, &predefined_macros::get_fullversion }, Chris@16: { "__SPIRIT_PP_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr }, Chris@16: { "__WAVE__", T_INTLIT, &predefined_macros::get_version }, Chris@16: { "__WAVE_VERSION__", T_INTLIT, &predefined_macros::get_fullversion }, Chris@16: { "__WAVE_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr }, Chris@16: { "__WAVE_CONFIG__", T_INTLIT, &predefined_macros::get_config }, Chris@16: { 0, T_EOF, 0 } Chris@16: }; Chris@16: BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); Chris@16: return data[i]; Chris@16: } Chris@16: }; // predefined_macros Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: } // namespace util Chris@16: } // namespace wave Chris@16: } // namespace boost Chris@16: Chris@16: // the suffix header occurs after all of the code Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // !defined(CPP_MACROMAP_PREDEF_HPP_HK041119)