ratio_static_string.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // ratio_io
  2. //
  3. // (C) Copyright 2010 Vicente J. Botet Escriba
  4. // Use, modification and distribution are subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt).
  7. //
  8. // This code was adapted by Vicente from Howard Hinnant's experimental work
  9. // on chrono i/o under lvm/libc++ to Boost
  10. #ifndef BOOST_RATIO_RATIO_STATIC_STRING_HPP
  11. #define BOOST_RATIO_RATIO_STATIC_STRING_HPP
  12. /*
  13. ratio_static_string synopsis
  14. #include <ratio>
  15. #include <string>
  16. namespace boost
  17. {
  18. template <class Ratio, class CharT>
  19. struct ratio_static_string
  20. {
  21. typedef basic_str<CharT, ...> short_name;
  22. typedef basic_str<CharT, ...> long_name;
  23. };
  24. } // boost
  25. */
  26. #include <boost/config.hpp>
  27. #include <boost/ratio/ratio.hpp>
  28. #include <boost/static_string/basic_str.hpp>
  29. //#include <sstream>
  30. #if defined(BOOST_NO_CXX11_UNICODE_LITERALS) || defined(BOOST_NO_CXX11_CHAR16_T) || defined(BOOST_NO_CXX11_CHAR32_T)
  31. //~ #define BOOST_RATIO_HAS_UNICODE_SUPPORT
  32. #else
  33. #define BOOST_RATIO_HAS_UNICODE_SUPPORT 1
  34. #endif
  35. namespace boost {
  36. template <class Ratio, class CharT>
  37. struct ratio_static_string;
  38. // atto
  39. template <>
  40. struct ratio_static_string<atto, char>
  41. {
  42. typedef static_string::str_1<'a'>::type short_name;
  43. typedef static_string::str_4<'a','t','t','o'>::type long_name;
  44. };
  45. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  46. template <>
  47. struct ratio_static_string<atto, char16_t>
  48. {
  49. typedef static_string::u16str_1<u'a'>::type short_name;
  50. typedef static_string::u16str_4<u'a',u't',u't',u'o'>::type long_name;
  51. };
  52. template <>
  53. struct ratio_static_string<atto, char32_t>
  54. {
  55. typedef static_string::u32str_1<U'a'>::type short_name;
  56. typedef static_string::u32str_4<U'a',U't',U't',U'o'>::type long_name;
  57. };
  58. #endif
  59. #ifndef BOOST_NO_STD_WSTRING
  60. template <>
  61. struct ratio_static_string<atto, wchar_t>
  62. {
  63. typedef static_string::wstr_1<L'a'>::type short_name;
  64. typedef static_string::wstr_4<L'a',L't',L't',L'o'>::type long_name;
  65. };
  66. #endif
  67. // femto
  68. template <>
  69. struct ratio_static_string<femto, char>
  70. {
  71. typedef static_string::str_1<'f'>::type short_name;
  72. typedef static_string::str_5<'f','e','m','t','o'>::type long_name;
  73. };
  74. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  75. template <>
  76. struct ratio_static_string<femto, char16_t>
  77. {
  78. typedef static_string::u16str_1<u'f'>::type short_name;
  79. typedef static_string::u16str_5<u'f',u'e',u'm',u't',u'o'>::type long_name;
  80. };
  81. template <>
  82. struct ratio_static_string<femto, char32_t>
  83. {
  84. typedef static_string::u32str_1<U'f'>::type short_name;
  85. typedef static_string::u32str_5<U'f',U'e',U'm',U't',U'o'>::type long_name;
  86. };
  87. #endif
  88. #ifndef BOOST_NO_STD_WSTRING
  89. template <>
  90. struct ratio_static_string<femto, wchar_t>
  91. {
  92. typedef static_string::wstr_1<L'f'>::type short_name;
  93. typedef static_string::wstr_5<L'f',L'e',L'm',L't',L'o'>::type long_name;
  94. };
  95. #endif
  96. // pico
  97. template <>
  98. struct ratio_static_string<pico, char>
  99. {
  100. typedef static_string::str_1<'p'>::type short_name;
  101. typedef static_string::str_4<'p','i','c','o'>::type long_name;
  102. };
  103. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  104. template <>
  105. struct ratio_static_string<pico, char16_t>
  106. {
  107. typedef static_string::u16str_1<u'p'>::type short_name;
  108. typedef static_string::u16str_4<u'p',u'i',u'c',u'o'>::type long_name;
  109. };
  110. template <>
  111. struct ratio_static_string<pico, char32_t>
  112. {
  113. typedef static_string::u32str_1<U'p'>::type short_name;
  114. typedef static_string::u32str_4<U'p',U'i',U'c',U'o'>::type long_name;
  115. };
  116. #endif
  117. #ifndef BOOST_NO_STD_WSTRING
  118. template <>
  119. struct ratio_static_string<pico, wchar_t>
  120. {
  121. typedef static_string::wstr_1<L'p'>::type short_name;
  122. typedef static_string::wstr_4<L'p',L'i',L'c',L'o'>::type long_name;
  123. };
  124. #endif
  125. // nano
  126. template <>
  127. struct ratio_static_string<nano, char>
  128. {
  129. typedef static_string::str_1<'n'>::type short_name;
  130. typedef static_string::str_4<'n','a','n','o'>::type long_name;
  131. };
  132. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  133. template <>
  134. struct ratio_static_string<nano, char16_t>
  135. {
  136. typedef static_string::u16str_1<u'n'>::type short_name;
  137. typedef static_string::u16str_4<u'n',u'a',u'n',u'o'>::type long_name;
  138. };
  139. template <>
  140. struct ratio_static_string<nano, char32_t>
  141. {
  142. typedef static_string::u32str_1<U'n'>::type short_name;
  143. typedef static_string::u32str_4<U'n',U'a',U'n',U'o'>::type long_name;
  144. };
  145. #endif
  146. #ifndef BOOST_NO_STD_WSTRING
  147. template <>
  148. struct ratio_static_string<nano, wchar_t>
  149. {
  150. typedef static_string::wstr_1<L'n'>::type short_name;
  151. typedef static_string::wstr_4<L'n',L'a',L'n',L'o'>::type long_name;
  152. };
  153. #endif
  154. // micro
  155. template <>
  156. struct ratio_static_string<micro, char>
  157. {
  158. typedef static_string::str_2<'\xC2','\xB5'>::type short_name;
  159. typedef static_string::str_5<'m','i','c','r','o'>::type long_name;
  160. };
  161. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  162. template <>
  163. struct ratio_static_string<micro, char16_t>
  164. {
  165. typedef static_string::u16str_1<u'\xB5'>::type short_name;
  166. typedef static_string::u16str_5<u'm',u'i',u'c',u'r',u'o'>::type long_name;
  167. };
  168. template <>
  169. struct ratio_static_string<micro, char32_t>
  170. {
  171. typedef static_string::u32str_1<U'\xB5'>::type short_name;
  172. typedef static_string::u32str_5<U'm',U'i',U'c',U'r',U'o'>::type long_name;
  173. };
  174. #endif
  175. #ifndef BOOST_NO_STD_WSTRING
  176. template <>
  177. struct ratio_static_string<micro, wchar_t>
  178. {
  179. typedef static_string::wstr_1<L'\xB5'>::type short_name;
  180. typedef static_string::wstr_5<L'm',L'i',L'c',L'r',L'o'>::type long_name;
  181. };
  182. #endif
  183. // milli
  184. template <>
  185. struct ratio_static_string<milli, char>
  186. {
  187. typedef static_string::str_1<'m'>::type short_name;
  188. typedef static_string::str_5<'m','i','l','l','i'>::type long_name;
  189. };
  190. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  191. template <>
  192. struct ratio_static_string<milli, char16_t>
  193. {
  194. typedef static_string::u16str_1<u'm'>::type short_name;
  195. typedef static_string::u16str_5<u'm',u'i',u'l',u'l',u'i'>::type long_name;
  196. };
  197. template <>
  198. struct ratio_static_string<milli, char32_t>
  199. {
  200. typedef static_string::u32str_1<U'm'>::type short_name;
  201. typedef static_string::u32str_5<U'm',U'i',U'l',U'l',U'i'>::type long_name;
  202. };
  203. #endif
  204. #ifndef BOOST_NO_STD_WSTRING
  205. template <>
  206. struct ratio_static_string<milli, wchar_t>
  207. {
  208. typedef static_string::wstr_1<L'm'>::type short_name;
  209. typedef static_string::wstr_5<L'm',L'i',L'l',L'l',L'i'>::type long_name;
  210. };
  211. #endif
  212. // centi
  213. template <>
  214. struct ratio_static_string<centi, char>
  215. {
  216. typedef static_string::str_1<'c'>::type short_name;
  217. typedef static_string::str_5<'c','e','n','t','i'>::type long_name;
  218. };
  219. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  220. template <>
  221. struct ratio_static_string<centi, char16_t>
  222. {
  223. typedef static_string::u16str_1<u'c'>::type short_name;
  224. typedef static_string::u16str_5<u'c',u'e',u'n',u't',u'i'>::type long_name;
  225. };
  226. template <>
  227. struct ratio_static_string<centi, char32_t>
  228. {
  229. typedef static_string::u32str_1<U'c'>::type short_name;
  230. typedef static_string::u32str_5<U'c',U'e',U'n',U't',U'i'>::type long_name;
  231. };
  232. #endif
  233. #ifndef BOOST_NO_STD_WSTRING
  234. template <>
  235. struct ratio_static_string<centi, wchar_t>
  236. {
  237. typedef static_string::wstr_1<L'c'>::type short_name;
  238. typedef static_string::wstr_5<L'c',L'e',L'n',L't',L'i'>::type long_name;
  239. };
  240. #endif
  241. // deci
  242. template <>
  243. struct ratio_static_string<deci, char>
  244. {
  245. typedef static_string::str_1<'d'>::type short_name;
  246. typedef static_string::str_4<'d','e','c','i'>::type long_name;
  247. };
  248. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  249. template <>
  250. struct ratio_static_string<deci, char16_t>
  251. {
  252. typedef static_string::u16str_1<u'd'>::type short_name;
  253. typedef static_string::u16str_4<u'd',u'e',u'c',u'i'>::type long_name;
  254. };
  255. template <>
  256. struct ratio_static_string<deci, char32_t>
  257. {
  258. typedef static_string::u32str_1<U'd'>::type short_name;
  259. typedef static_string::u32str_4<U'd',U'e',U'c',U'i'>::type long_name;
  260. };
  261. #endif
  262. #ifndef BOOST_NO_STD_WSTRING
  263. template <>
  264. struct ratio_static_string<deci, wchar_t>
  265. {
  266. typedef static_string::wstr_1<L'd'>::type short_name;
  267. typedef static_string::wstr_4<L'd',L'e',L'c',L'i'>::type long_name;
  268. };
  269. #endif
  270. // deca
  271. template <>
  272. struct ratio_static_string<deca, char>
  273. {
  274. typedef static_string::str_2<'d','a'>::type short_name;
  275. typedef static_string::str_4<'d','e','c','a'>::type long_name;
  276. };
  277. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  278. template <>
  279. struct ratio_static_string<deca, char16_t>
  280. {
  281. typedef static_string::u16str_2<u'd',u'a'>::type short_name;
  282. typedef static_string::u16str_4<u'd',u'e',u'c',u'a'>::type long_name;
  283. };
  284. template <>
  285. struct ratio_static_string<deca, char32_t>
  286. {
  287. typedef static_string::u32str_2<U'd',U'a'>::type short_name;
  288. typedef static_string::u32str_4<U'd',U'e',U'c',U'a'>::type long_name;
  289. };
  290. #endif
  291. #ifndef BOOST_NO_STD_WSTRING
  292. template <>
  293. struct ratio_static_string<deca, wchar_t>
  294. {
  295. typedef static_string::wstr_2<L'd',L'a'>::type short_name;
  296. typedef static_string::wstr_4<L'd',L'e',L'c',L'a'>::type long_name;
  297. };
  298. #endif
  299. // hecto
  300. template <>
  301. struct ratio_static_string<hecto, char>
  302. {
  303. typedef static_string::str_1<'h'>::type short_name;
  304. typedef static_string::str_5<'h','e','c','t','o'>::type long_name;
  305. };
  306. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  307. template <>
  308. struct ratio_static_string<hecto, char16_t>
  309. {
  310. typedef static_string::u16str_1<u'h'>::type short_name;
  311. typedef static_string::u16str_5<u'h',u'e',u'c',u't',u'o'>::type long_name;
  312. };
  313. template <>
  314. struct ratio_static_string<hecto, char32_t>
  315. {
  316. typedef static_string::u32str_1<U'h'>::type short_name;
  317. typedef static_string::u32str_5<U'h',U'e',U'c',U't',U'o'>::type long_name;
  318. };
  319. #endif
  320. #ifndef BOOST_NO_STD_WSTRING
  321. template <>
  322. struct ratio_static_string<hecto, wchar_t>
  323. {
  324. typedef static_string::wstr_1<L'h'>::type short_name;
  325. typedef static_string::wstr_5<L'h',L'e',L'c',L't',L'o'>::type long_name;
  326. };
  327. #endif
  328. // kilo
  329. template <>
  330. struct ratio_static_string<kilo, char>
  331. {
  332. typedef static_string::str_1<'k'>::type short_name;
  333. typedef static_string::str_4<'k','i','l','o'>::type long_name;
  334. };
  335. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  336. template <>
  337. struct ratio_static_string<kilo, char16_t>
  338. {
  339. typedef static_string::u16str_1<u'k'>::type short_name;
  340. typedef static_string::u16str_4<u'k',u'i',u'l',u'o'>::type long_name;
  341. };
  342. template <>
  343. struct ratio_static_string<kilo, char32_t>
  344. {
  345. typedef static_string::u32str_1<U'k'>::type short_name;
  346. typedef static_string::u32str_4<U'k',U'i',U'l',U'o'>::type long_name;
  347. };
  348. #endif
  349. #ifndef BOOST_NO_STD_WSTRING
  350. template <>
  351. struct ratio_static_string<kilo, wchar_t>
  352. {
  353. typedef static_string::wstr_1<L'k'>::type short_name;
  354. typedef static_string::wstr_4<L'k',L'i',L'l',L'o'>::type long_name;
  355. };
  356. #endif
  357. // mega
  358. template <>
  359. struct ratio_static_string<mega, char>
  360. {
  361. typedef static_string::str_1<'M'>::type short_name;
  362. typedef static_string::str_4<'m','e','g','a'>::type long_name;
  363. };
  364. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  365. template <>
  366. struct ratio_static_string<mega, char16_t>
  367. {
  368. typedef static_string::u16str_1<u'M'>::type short_name;
  369. typedef static_string::u16str_4<u'm',u'e',u'g',u'a'>::type long_name;
  370. };
  371. template <>
  372. struct ratio_static_string<mega, char32_t>
  373. {
  374. typedef static_string::u32str_1<U'M'>::type short_name;
  375. typedef static_string::u32str_4<U'm',U'e',U'g',U'a'>::type long_name;
  376. };
  377. #endif
  378. #ifndef BOOST_NO_STD_WSTRING
  379. template <>
  380. struct ratio_static_string<mega, wchar_t>
  381. {
  382. typedef static_string::wstr_1<L'M'>::type short_name;
  383. typedef static_string::wstr_4<L'm',L'e',L'g',L'a'>::type long_name;
  384. };
  385. #endif
  386. // giga
  387. template <>
  388. struct ratio_static_string<giga, char>
  389. {
  390. typedef static_string::str_1<'G'>::type short_name;
  391. typedef static_string::str_4<'g','i','g','a'>::type long_name;
  392. };
  393. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  394. template <>
  395. struct ratio_static_string<giga, char16_t>
  396. {
  397. typedef static_string::u16str_1<u'G'>::type short_name;
  398. typedef static_string::u16str_4<u'g',u'i',u'g',u'a'>::type long_name;
  399. };
  400. template <>
  401. struct ratio_static_string<giga, char32_t>
  402. {
  403. typedef static_string::u32str_1<U'G'>::type short_name;
  404. typedef static_string::u32str_4<U'g',U'i',U'g',U'a'>::type long_name;
  405. };
  406. #endif
  407. #ifndef BOOST_NO_STD_WSTRING
  408. template <>
  409. struct ratio_static_string<giga, wchar_t>
  410. {
  411. typedef static_string::wstr_1<L'G'>::type short_name;
  412. typedef static_string::wstr_4<L'g',L'i',L'g',L'a'>::type long_name;
  413. };
  414. #endif
  415. // tera
  416. template <>
  417. struct ratio_static_string<tera, char>
  418. {
  419. typedef static_string::str_1<'T'>::type short_name;
  420. typedef static_string::str_4<'t','e','r','a'>::type long_name;
  421. };
  422. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  423. template <>
  424. struct ratio_static_string<tera, char16_t>
  425. {
  426. typedef static_string::u16str_1<u'T'>::type short_name;
  427. typedef static_string::u16str_4<u't',u'e',u'r',u'a'>::type long_name;
  428. };
  429. template <>
  430. struct ratio_static_string<tera, char32_t>
  431. {
  432. typedef static_string::u32str_1<U'T'>::type short_name;
  433. typedef static_string::u32str_4<U't',U'e',U'r',U'a'>::type long_name;
  434. };
  435. #endif
  436. #ifndef BOOST_NO_STD_WSTRING
  437. template <>
  438. struct ratio_static_string<tera, wchar_t>
  439. {
  440. typedef static_string::wstr_1<L'T'>::type short_name;
  441. typedef static_string::wstr_4<L'r',L'e',L'r',L'a'>::type long_name;
  442. };
  443. #endif
  444. // peta
  445. template <>
  446. struct ratio_static_string<peta, char>
  447. {
  448. typedef static_string::str_1<'P'>::type short_name;
  449. typedef static_string::str_4<'p','e','t','a'>::type long_name;
  450. };
  451. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  452. template <>
  453. struct ratio_static_string<peta, char16_t>
  454. {
  455. typedef static_string::u16str_1<u'P'>::type short_name;
  456. typedef static_string::u16str_4<u'p',u'e',u't',u'a'>::type long_name;
  457. };
  458. template <>
  459. struct ratio_static_string<peta, char32_t>
  460. {
  461. typedef static_string::u32str_1<U'P'>::type short_name;
  462. typedef static_string::u32str_4<U'p',U'e',U't',U'a'>::type long_name;
  463. };
  464. #endif
  465. #ifndef BOOST_NO_STD_WSTRING
  466. template <>
  467. struct ratio_static_string<peta, wchar_t>
  468. {
  469. typedef static_string::wstr_1<L'P'>::type short_name;
  470. typedef static_string::wstr_4<L'p',L'e',L't',L'a'>::type long_name;
  471. };
  472. #endif
  473. // exa
  474. template <>
  475. struct ratio_static_string<exa, char>
  476. {
  477. typedef static_string::str_1<'E'>::type short_name;
  478. typedef static_string::str_3<'e','x','a'>::type long_name;
  479. };
  480. #ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
  481. template <>
  482. struct ratio_static_string<exa, char16_t>
  483. {
  484. typedef static_string::u16str_1<u'E'>::type short_name;
  485. typedef static_string::u16str_3<u'e',u'x',u'a'>::type long_name;
  486. };
  487. template <>
  488. struct ratio_static_string<exa, char32_t>
  489. {
  490. typedef static_string::u32str_1<U'E'>::type short_name;
  491. typedef static_string::u32str_3<U'e',U'x',U'a'>::type long_name;
  492. };
  493. #endif
  494. #ifndef BOOST_NO_STD_WSTRING
  495. template <>
  496. struct ratio_static_string<exa, wchar_t>
  497. {
  498. typedef static_string::wstr_1<L'E'>::type short_name;
  499. typedef static_string::wstr_3<L'e',L'x',L'a'>::type long_name;
  500. };
  501. #endif
  502. }
  503. #endif // BOOST_RATIO_RATIO_STATIC_STRING_HPP