| 1 | /*============================================================================= | 
|---|
| 2 |     Boost.Wave: A Standard compliant C++ preprocessor library | 
|---|
| 3 |  | 
|---|
| 4 |     Definition of the predefined macros | 
|---|
| 5 |      | 
|---|
| 6 |     http://www.boost.org/ | 
|---|
| 7 |  | 
|---|
| 8 |     Copyright (c) 2001-2005 Hartmut Kaiser. Distributed under the Boost | 
|---|
| 9 |     Software License, Version 1.0. (See accompanying file | 
|---|
| 10 |     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 
|---|
| 11 | =============================================================================*/ | 
|---|
| 12 |  | 
|---|
| 13 | #if !defined(CPP_MACROMAP_PREDEF_HPP_HK041119) | 
|---|
| 14 | #define CPP_MACROMAP_PREDEF_HPP_HK041119 | 
|---|
| 15 |  | 
|---|
| 16 | #include <cstdio> | 
|---|
| 17 | #include <boost/assert.hpp> | 
|---|
| 18 |  | 
|---|
| 19 | #include <boost/wave/wave_config.hpp> | 
|---|
| 20 | #include <boost/wave/token_ids.hpp> | 
|---|
| 21 |  | 
|---|
| 22 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 23 | // | 
|---|
| 24 | // This file contains the definition of functions needed for the management | 
|---|
| 25 | // of static and dynamic predefined macros, such as __DATE__, __TIME__ etc. | 
|---|
| 26 | // | 
|---|
| 27 | // Note: __FILE__, __LINE__ and __INCLUDE_LEVEL__ are handled in the file | 
|---|
| 28 | //       cpp_macromap.hpp. | 
|---|
| 29 | // | 
|---|
| 30 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 31 |  | 
|---|
| 32 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 33 | namespace boost { | 
|---|
| 34 | namespace wave { | 
|---|
| 35 | namespace util { | 
|---|
| 36 |  | 
|---|
| 37 | namespace predefined_macros { | 
|---|
| 38 |  | 
|---|
| 39 | // list of static predefined macros | 
|---|
| 40 |     struct static_macros { | 
|---|
| 41 |         char const *name; | 
|---|
| 42 |         boost::wave::token_id token_id; | 
|---|
| 43 |         char const *value; | 
|---|
| 44 |     }; | 
|---|
| 45 |  | 
|---|
| 46 | // C++ mode  | 
|---|
| 47 |     inline static_macros const &  | 
|---|
| 48 |     static_data_cpp(std::size_t i) | 
|---|
| 49 |     { | 
|---|
| 50 |     static static_macros data[] = { | 
|---|
| 51 |             { "__STDC__", T_INTLIT, "1" }, | 
|---|
| 52 |             { "__cplusplus", T_INTLIT, "199711L" }, | 
|---|
| 53 |             { 0, T_EOF, 0 } | 
|---|
| 54 |         };  | 
|---|
| 55 |         BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); | 
|---|
| 56 |         return data[i]; | 
|---|
| 57 |     } | 
|---|
| 58 |  | 
|---|
| 59 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 | 
|---|
| 60 | // C99 mode | 
|---|
| 61 |     inline static_macros const & | 
|---|
| 62 |     static_data_c99(std::size_t i) | 
|---|
| 63 |     { | 
|---|
| 64 |     static static_macros data[] = { | 
|---|
| 65 |             { "__STDC__", T_INTLIT, "1" }, | 
|---|
| 66 |             { "__STDC_VERSION__", T_INTLIT, "199901L" }, | 
|---|
| 67 |             { "__STDC_HOSTED__", T_INTLIT, "0" }, | 
|---|
| 68 |             { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, | 
|---|
| 69 |             { 0, T_EOF, 0 } | 
|---|
| 70 |         };  | 
|---|
| 71 |         BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); | 
|---|
| 72 |         return data[i]; | 
|---|
| 73 |     } | 
|---|
| 74 | #endif  | 
|---|
| 75 |      | 
|---|
| 76 | // list of dynamic predefined macros | 
|---|
| 77 |     typedef char const * (* get_dynamic_value)(bool); | 
|---|
| 78 |  | 
|---|
| 79 | // __DATE__  | 
|---|
| 80 |     inline  | 
|---|
| 81 |     char const *get_date(bool reset) | 
|---|
| 82 |     { | 
|---|
| 83 |     static std::string datestr; | 
|---|
| 84 |     static const char *const monthnames[] = { | 
|---|
| 85 |             "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 
|---|
| 86 |             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | 
|---|
| 87 |         }; | 
|---|
| 88 |      | 
|---|
| 89 |         if (reset) { | 
|---|
| 90 |             datestr.erase(); | 
|---|
| 91 |         } | 
|---|
| 92 |         else { | 
|---|
| 93 |         // for some systems sprintf, time_t etc. is in namespace std | 
|---|
| 94 |             using namespace std;     | 
|---|
| 95 |  | 
|---|
| 96 |         time_t tt = time(0); | 
|---|
| 97 |         struct tm *tb = 0; | 
|---|
| 98 |  | 
|---|
| 99 |             if (tt != (time_t)-1) { | 
|---|
| 100 |             char buffer[sizeof("\"Oct 11 1347\"")+1]; | 
|---|
| 101 |  | 
|---|
| 102 |                 tb = localtime (&tt); | 
|---|
| 103 |                 sprintf (buffer, "\"%s %2d %4d\"", | 
|---|
| 104 |                     monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); | 
|---|
| 105 |                 datestr = buffer; | 
|---|
| 106 |             } | 
|---|
| 107 |             else { | 
|---|
| 108 |                 datestr = "\"??? ?? ????\""; | 
|---|
| 109 |             } | 
|---|
| 110 |         } | 
|---|
| 111 |         return datestr.c_str(); | 
|---|
| 112 |     } | 
|---|
| 113 |  | 
|---|
| 114 | // __TIME__ | 
|---|
| 115 |     inline  | 
|---|
| 116 |     char const *get_time(bool reset) | 
|---|
| 117 |     { | 
|---|
| 118 |     static std::string timestr; | 
|---|
| 119 |      | 
|---|
| 120 |         if (reset) { | 
|---|
| 121 |             timestr.erase(); | 
|---|
| 122 |         } | 
|---|
| 123 |         else { | 
|---|
| 124 |         // for some systems sprintf, time_t etc. is in namespace std | 
|---|
| 125 |             using namespace std;     | 
|---|
| 126 |  | 
|---|
| 127 |         time_t tt = time(0); | 
|---|
| 128 |         struct tm *tb = 0; | 
|---|
| 129 |  | 
|---|
| 130 |             if (tt != (time_t)-1) { | 
|---|
| 131 |             char buffer[sizeof("\"12:34:56\"")+1]; | 
|---|
| 132 |  | 
|---|
| 133 |                 tb = localtime (&tt); | 
|---|
| 134 |                 sprintf (buffer, "\"%02d:%02d:%02d\"", tb->tm_hour,  | 
|---|
| 135 |                     tb->tm_min, tb->tm_sec); | 
|---|
| 136 |                 timestr = buffer; | 
|---|
| 137 |             } | 
|---|
| 138 |             else { | 
|---|
| 139 |                 timestr = "\"??:??:??\""; | 
|---|
| 140 |             } | 
|---|
| 141 |         } | 
|---|
| 142 |         return timestr.c_str(); | 
|---|
| 143 |     } | 
|---|
| 144 |  | 
|---|
| 145 | // __SPIRIT_PP__/__WAVE__ | 
|---|
| 146 |     inline  | 
|---|
| 147 |     char const *get_version(bool /*reset*/) | 
|---|
| 148 |     { | 
|---|
| 149 |     static std::string versionstr; | 
|---|
| 150 |     char buffer[sizeof("0x0000")+1]; | 
|---|
| 151 |  | 
|---|
| 152 |         using namespace std;    // for some systems sprintf is in namespace std | 
|---|
| 153 |         sprintf(buffer, "0x%02d%1d%1d", BOOST_WAVE_VERSION_MAJOR,  | 
|---|
| 154 |             BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR); | 
|---|
| 155 |         versionstr = buffer; | 
|---|
| 156 |         return versionstr.c_str(); | 
|---|
| 157 |     } | 
|---|
| 158 |      | 
|---|
| 159 | // __SPIRIT_PP_VERSION__/__WAVE_VERSION__ | 
|---|
| 160 |     boost::wave::util::time_conversion_helper const  | 
|---|
| 161 |         compilation_time(__DATE__ " " __TIME__); | 
|---|
| 162 |          | 
|---|
| 163 |     inline  | 
|---|
| 164 |     char const *get_fullversion(bool /*reset*/) | 
|---|
| 165 |     { | 
|---|
| 166 |     static std::string versionstr; | 
|---|
| 167 |     char buffer[sizeof("0x00000000")+1]; | 
|---|
| 168 |  | 
|---|
| 169 |     // for some systems sprintf, time_t etc. is in namespace std | 
|---|
| 170 |         using namespace std;     | 
|---|
| 171 |  | 
|---|
| 172 |     // calculate the number of days since Dec 13 2001  | 
|---|
| 173 |     // (the day the Wave project was started) | 
|---|
| 174 |     tm first_day; | 
|---|
| 175 |  | 
|---|
| 176 |         using namespace std;    // for some systems memset is in namespace std | 
|---|
| 177 |         memset (&first_day, 0, sizeof(tm)); | 
|---|
| 178 |         first_day.tm_mon = 11;           // Dec | 
|---|
| 179 |         first_day.tm_mday = 13;          // 13 | 
|---|
| 180 |         first_day.tm_year = 101;         // 2001 | 
|---|
| 181 |  | 
|---|
| 182 |     long seconds = long(difftime(compilation_time.get_time(),  | 
|---|
| 183 |         mktime(&first_day))); | 
|---|
| 184 |  | 
|---|
| 185 |         sprintf(buffer, "0x%02d%1d%1d%04ld", BOOST_WAVE_VERSION_MAJOR, | 
|---|
| 186 |              BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR,  | 
|---|
| 187 |              seconds/(3600*24)); | 
|---|
| 188 |         versionstr = buffer; | 
|---|
| 189 |         return versionstr.c_str(); | 
|---|
| 190 |     } | 
|---|
| 191 |      | 
|---|
| 192 | // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__ | 
|---|
| 193 |     inline  | 
|---|
| 194 |     char const *get_versionstr(bool /*reset*/) | 
|---|
| 195 |     { | 
|---|
| 196 |     static std::string versionstr; | 
|---|
| 197 |     char buffer[sizeof("\"00.00.00.0000\"")+1]; | 
|---|
| 198 |  | 
|---|
| 199 |     // for some systems sprintf, time_t etc. is in namespace std | 
|---|
| 200 |         using namespace std;     | 
|---|
| 201 |  | 
|---|
| 202 |     // calculate the number of days since Dec 13 2001  | 
|---|
| 203 |     // (the day the Wave project was started) | 
|---|
| 204 |     tm first_day; | 
|---|
| 205 |  | 
|---|
| 206 |         using namespace std;    // for some systems memset is in namespace std | 
|---|
| 207 |         memset (&first_day, 0, sizeof(tm)); | 
|---|
| 208 |         first_day.tm_mon = 11;           // Dec | 
|---|
| 209 |         first_day.tm_mday = 13;          // 13 | 
|---|
| 210 |         first_day.tm_year = 101;         // 2001 | 
|---|
| 211 |  | 
|---|
| 212 |     long seconds = long(difftime(compilation_time.get_time(),  | 
|---|
| 213 |         mktime(&first_day))); | 
|---|
| 214 |  | 
|---|
| 215 |         sprintf(buffer, "\"%d.%d.%d.%ld\"", BOOST_WAVE_VERSION_MAJOR, | 
|---|
| 216 |              BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR,  | 
|---|
| 217 |              seconds/(3600*24)); | 
|---|
| 218 |         versionstr = buffer; | 
|---|
| 219 |         return versionstr.c_str(); | 
|---|
| 220 |     } | 
|---|
| 221 |      | 
|---|
| 222 |     struct dynamic_macros { | 
|---|
| 223 |         char const *name; | 
|---|
| 224 |         boost::wave::token_id token_id; | 
|---|
| 225 |         get_dynamic_value generator; | 
|---|
| 226 |     }; | 
|---|
| 227 |      | 
|---|
| 228 |     inline dynamic_macros const & | 
|---|
| 229 |     dynamic_data(std::size_t i) | 
|---|
| 230 |     { | 
|---|
| 231 |     static dynamic_macros data[] = { | 
|---|
| 232 |             { "__DATE__", T_STRINGLIT, get_date }, | 
|---|
| 233 |             { "__TIME__", T_STRINGLIT, get_time }, | 
|---|
| 234 |             { "__SPIRIT_PP__", T_INTLIT, get_version }, | 
|---|
| 235 |             { "__SPIRIT_PP_VERSION__", T_INTLIT, get_fullversion }, | 
|---|
| 236 |             { "__SPIRIT_PP_VERSION_STR__", T_STRINGLIT, get_versionstr }, | 
|---|
| 237 |             { "__WAVE__", T_INTLIT, get_version }, | 
|---|
| 238 |             { "__WAVE_VERSION__", T_INTLIT, get_fullversion }, | 
|---|
| 239 |             { "__WAVE_VERSION_STR__", T_STRINGLIT, get_versionstr }, | 
|---|
| 240 |             { 0, T_EOF, 0 } | 
|---|
| 241 |         }; | 
|---|
| 242 |         BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); | 
|---|
| 243 |         return data[i]; | 
|---|
| 244 |     } | 
|---|
| 245 |      | 
|---|
| 246 | }   // namespace predefined_macros | 
|---|
| 247 |  | 
|---|
| 248 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 249 | }   // namespace util | 
|---|
| 250 | }   // namespace wave | 
|---|
| 251 | }   // namespace boost | 
|---|
| 252 |  | 
|---|
| 253 | #endif // !defined(CPP_MACROMAP_PREDEF_HPP_HK041119) | 
|---|