File indexing completed on 2025-01-18 09:53:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #if !defined(BOOST_CPP_MACROMAP_PREDEF_HPP_HK041119)
0014 #define BOOST_CPP_MACROMAP_PREDEF_HPP_HK041119
0015
0016 #include <cstdio>
0017 #include <boost/assert.hpp>
0018 #include <boost/format.hpp>
0019
0020 #include <boost/wave/wave_config.hpp>
0021 #include <boost/wave/wave_config_constant.hpp>
0022 #include <boost/wave/token_ids.hpp>
0023 #include <boost/wave/util/time_conversion_helper.hpp> // time_conversion_helper
0024
0025
0026 #ifdef BOOST_HAS_ABI_HEADERS
0027 #include BOOST_ABI_PREFIX
0028 #endif
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 namespace boost {
0042 namespace wave {
0043 namespace util {
0044
0045
0046 class predefined_macros
0047 {
0048 typedef BOOST_WAVE_STRINGTYPE string_type;
0049
0050 public:
0051
0052 struct static_macros {
0053 char const *name;
0054 boost::wave::token_id token_id;
0055 char const *value;
0056 };
0057
0058
0059 struct dynamic_macros {
0060 char const *name;
0061 boost::wave::token_id token_id;
0062 string_type (predefined_macros:: *generator)() const;
0063 };
0064
0065 private:
0066 boost::wave::util::time_conversion_helper compilation_time_;
0067 string_type datestr_;
0068 string_type timestr_;
0069 string_type version_;
0070 string_type versionstr_;
0071
0072 static string_type strconv(std::string const & ss)
0073 {
0074 return string_type(ss.c_str());
0075 }
0076
0077 protected:
0078 void reset_datestr()
0079 {
0080 static const char *const monthnames[] = {
0081 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
0082 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
0083 };
0084
0085
0086 using namespace std;
0087
0088 time_t tt = time(0);
0089 struct tm *tb = 0;
0090
0091 if (tt != (time_t)-1) {
0092 tb = localtime (&tt);
0093 datestr_ = strconv((boost::format("\"%s %2d %4d\"")
0094 % monthnames[tb->tm_mon]
0095 % tb->tm_mday
0096 % (tb->tm_year + 1900)).str());
0097 }
0098 else {
0099 datestr_ = "\"??? ?? ????\"";
0100 }
0101 }
0102
0103 void reset_timestr()
0104 {
0105
0106 using namespace std;
0107
0108 time_t tt = time(0);
0109 struct tm *tb = 0;
0110
0111 if (tt != (time_t)-1) {
0112 tb = localtime (&tt);
0113 timestr_ = strconv((boost::format("\"%02d:%02d:%02d\"")
0114 % tb->tm_hour
0115 % tb->tm_min
0116 % tb->tm_sec).str());
0117 }
0118 else {
0119 timestr_ = "\"??:??:??\"";
0120 }
0121 }
0122
0123 void reset_version()
0124 {
0125
0126 using namespace std;
0127
0128
0129
0130 tm first_day;
0131
0132 using namespace std;
0133 memset (&first_day, 0, sizeof(tm));
0134 first_day.tm_mon = 11;
0135 first_day.tm_mday = 13;
0136 first_day.tm_year = 101;
0137
0138 long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day)));
0139
0140 version_ = strconv((boost::format("0x%02d%1d%1d%04ld")
0141 % BOOST_WAVE_VERSION_MAJOR
0142 % BOOST_WAVE_VERSION_MINOR
0143 % BOOST_WAVE_VERSION_SUBMINOR
0144 % (seconds/(3600*24))).str());
0145 }
0146
0147 void reset_versionstr()
0148 {
0149
0150 using namespace std;
0151
0152
0153
0154 tm first_day;
0155
0156 memset (&first_day, 0, sizeof(tm));
0157 first_day.tm_mon = 11;
0158 first_day.tm_mday = 13;
0159 first_day.tm_year = 101;
0160
0161 long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day)));
0162
0163 versionstr_ = strconv((boost::format("\"%d.%d.%d.%ld [%s/%s]\"")
0164 % BOOST_WAVE_VERSION_MAJOR
0165 % BOOST_WAVE_VERSION_MINOR
0166 % BOOST_WAVE_VERSION_SUBMINOR
0167 % (seconds/(3600*24))
0168 % BOOST_PLATFORM
0169 % BOOST_COMPILER).str());
0170 }
0171
0172
0173 string_type get_date() const { return datestr_; }
0174 string_type get_time() const { return timestr_; }
0175
0176
0177 string_type get_version() const
0178 {
0179 return strconv((boost::format("0x%02d%1d%1d")
0180 % BOOST_WAVE_VERSION_MAJOR
0181 % BOOST_WAVE_VERSION_MINOR
0182 % BOOST_WAVE_VERSION_SUBMINOR).str());
0183 }
0184
0185
0186 string_type get_config() const
0187 {
0188 return strconv((boost::format("0x%08x") % BOOST_WAVE_CONFIG).str());
0189 }
0190
0191 public:
0192 predefined_macros()
0193 : compilation_time_(__DATE__ " " __TIME__)
0194 {
0195 reset();
0196 reset_version();
0197 reset_versionstr();
0198 }
0199
0200 void reset()
0201 {
0202 reset_datestr();
0203 reset_timestr();
0204 }
0205
0206
0207 string_type get_fullversion() const { return version_; }
0208
0209
0210 string_type get_versionstr() const { return versionstr_; }
0211
0212
0213 static_macros const& static_data_cpp(std::size_t i) const
0214 {
0215 static static_macros data[] = {
0216 { "__STDC__", T_INTLIT, "1" },
0217 { "__cplusplus", T_INTLIT, "199711L" },
0218 { 0, T_EOF, 0 }
0219 };
0220 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
0221 return data[i];
0222 }
0223
0224 #if BOOST_WAVE_SUPPORT_CPP0X != 0
0225
0226 static_macros const& static_data_cpp0x(std::size_t i) const
0227 {
0228 static static_macros data[] = {
0229 { "__STDC__", T_INTLIT, "1" },
0230 { "__cplusplus", T_INTLIT, "201103L" },
0231 { "__STDC_VERSION__", T_INTLIT, "199901L" },
0232 { "__STDC_HOSTED__", T_INTLIT, "0" },
0233 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },
0234 { 0, T_EOF, 0 }
0235 };
0236 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
0237 return data[i];
0238 }
0239 #endif
0240
0241 #if BOOST_WAVE_SUPPORT_CPP2A != 0
0242
0243 static_macros const& static_data_cpp2a(std::size_t i) const
0244 {
0245 static static_macros data[] = {
0246 { "__STDC__", T_INTLIT, "1" },
0247 { "__cplusplus", T_INTLIT, "202002L" },
0248 { "__STDC_VERSION__", T_INTLIT, "199901L" },
0249 { "__STDC_HOSTED__", T_INTLIT, "0" },
0250 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },
0251 { 0, T_EOF, 0 }
0252 };
0253 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
0254 return data[i];
0255 }
0256 #endif
0257
0258 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0259
0260 static_macros const& static_data_c99(std::size_t i) const
0261 {
0262 static static_macros data[] = {
0263 { "__STDC__", T_INTLIT, "1" },
0264 { "__STDC_VERSION__", T_INTLIT, "199901L" },
0265 { "__STDC_HOSTED__", T_INTLIT, "0" },
0266 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },
0267 { 0, T_EOF, 0 }
0268 };
0269 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
0270 return data[i];
0271 }
0272 #endif
0273
0274 dynamic_macros const& dynamic_data(std::size_t i) const
0275 {
0276 static dynamic_macros data[] = {
0277 { "__DATE__", T_STRINGLIT, &predefined_macros::get_date },
0278 { "__TIME__", T_STRINGLIT, &predefined_macros::get_time },
0279 { "__SPIRIT_PP__", T_INTLIT, &predefined_macros::get_version },
0280 { "__SPIRIT_PP_VERSION__", T_INTLIT, &predefined_macros::get_fullversion },
0281 { "__SPIRIT_PP_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr },
0282 { "__WAVE__", T_INTLIT, &predefined_macros::get_version },
0283 { "__WAVE_VERSION__", T_INTLIT, &predefined_macros::get_fullversion },
0284 { "__WAVE_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr },
0285 { "__WAVE_CONFIG__", T_INTLIT, &predefined_macros::get_config },
0286 { 0, T_EOF, 0 }
0287 };
0288 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
0289 return data[i];
0290 }
0291 };
0292
0293
0294 }
0295 }
0296 }
0297
0298
0299 #ifdef BOOST_HAS_ABI_HEADERS
0300 #include BOOST_ABI_SUFFIX
0301 #endif
0302
0303 #endif