/src/contrib/boost/spirit/home/classic/utility/impl/chset_operators.ipp

http://pythonocc.googlecode.com/ · C++ Header · 666 lines · 463 code · 82 blank · 121 comment · 8 complexity · c28f5d9391e755ef422740e752d73427 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Joel de Guzman
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #ifndef BOOST_SPIRIT_CHSET_OPERATORS_IPP
  9. #define BOOST_SPIRIT_CHSET_OPERATORS_IPP
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include <boost/limits.hpp>
  12. ///////////////////////////////////////////////////////////////////////////////
  13. namespace boost { namespace spirit {
  14. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  15. ///////////////////////////////////////////////////////////////////////////////
  16. //
  17. // chset free operators implementation
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. template <typename CharT>
  21. inline chset<CharT>
  22. operator|(chset<CharT> const& a, chset<CharT> const& b)
  23. {
  24. return chset<CharT>(a) |= b;
  25. }
  26. //////////////////////////////////
  27. template <typename CharT>
  28. inline chset<CharT>
  29. operator-(chset<CharT> const& a, chset<CharT> const& b)
  30. {
  31. return chset<CharT>(a) -= b;
  32. }
  33. //////////////////////////////////
  34. template <typename CharT>
  35. inline chset<CharT>
  36. operator~(chset<CharT> const& a)
  37. {
  38. return chset<CharT>(a).inverse();
  39. }
  40. //////////////////////////////////
  41. template <typename CharT>
  42. inline chset<CharT>
  43. operator&(chset<CharT> const& a, chset<CharT> const& b)
  44. {
  45. return chset<CharT>(a) &= b;
  46. }
  47. //////////////////////////////////
  48. template <typename CharT>
  49. inline chset<CharT>
  50. operator^(chset<CharT> const& a, chset<CharT> const& b)
  51. {
  52. return chset<CharT>(a) ^= b;
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////
  55. //
  56. // range <--> chset free operators implementation
  57. //
  58. ///////////////////////////////////////////////////////////////////////////////
  59. template <typename CharT>
  60. inline chset<CharT>
  61. operator|(chset<CharT> const& a, range<CharT> const& b)
  62. {
  63. chset<CharT> a_(a);
  64. a_.set(b);
  65. return a_;
  66. }
  67. //////////////////////////////////
  68. template <typename CharT>
  69. inline chset<CharT>
  70. operator&(chset<CharT> const& a, range<CharT> const& b)
  71. {
  72. chset<CharT> a_(a);
  73. if(b.first != (std::numeric_limits<CharT>::min)()) {
  74. a_.clear(range<CharT>((std::numeric_limits<CharT>::min)(), b.first - 1));
  75. }
  76. if(b.last != (std::numeric_limits<CharT>::max)()) {
  77. a_.clear(range<CharT>(b.last + 1, (std::numeric_limits<CharT>::max)()));
  78. }
  79. return a_;
  80. }
  81. //////////////////////////////////
  82. template <typename CharT>
  83. inline chset<CharT>
  84. operator-(chset<CharT> const& a, range<CharT> const& b)
  85. {
  86. chset<CharT> a_(a);
  87. a_.clear(b);
  88. return a_;
  89. }
  90. //////////////////////////////////
  91. template <typename CharT>
  92. inline chset<CharT>
  93. operator^(chset<CharT> const& a, range<CharT> const& b)
  94. {
  95. return a ^ chset<CharT>(b);
  96. }
  97. //////////////////////////////////
  98. template <typename CharT>
  99. inline chset<CharT>
  100. operator|(range<CharT> const& a, chset<CharT> const& b)
  101. {
  102. chset<CharT> b_(b);
  103. b_.set(a);
  104. return b_;
  105. }
  106. //////////////////////////////////
  107. template <typename CharT>
  108. inline chset<CharT>
  109. operator&(range<CharT> const& a, chset<CharT> const& b)
  110. {
  111. chset<CharT> b_(b);
  112. if(a.first != (std::numeric_limits<CharT>::min)()) {
  113. b_.clear(range<CharT>((std::numeric_limits<CharT>::min)(), a.first - 1));
  114. }
  115. if(a.last != (std::numeric_limits<CharT>::max)()) {
  116. b_.clear(range<CharT>(a.last + 1, (std::numeric_limits<CharT>::max)()));
  117. }
  118. return b_;
  119. }
  120. //////////////////////////////////
  121. template <typename CharT>
  122. inline chset<CharT>
  123. operator-(range<CharT> const& a, chset<CharT> const& b)
  124. {
  125. return chset<CharT>(a) - b;
  126. }
  127. //////////////////////////////////
  128. template <typename CharT>
  129. inline chset<CharT>
  130. operator^(range<CharT> const& a, chset<CharT> const& b)
  131. {
  132. return chset<CharT>(a) ^ b;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. //
  136. // literal primitives <--> chset free operators implementation
  137. //
  138. ///////////////////////////////////////////////////////////////////////////////
  139. template <typename CharT>
  140. inline chset<CharT>
  141. operator|(chset<CharT> const& a, CharT b)
  142. {
  143. return a | chset<CharT>(b);
  144. }
  145. //////////////////////////////////
  146. template <typename CharT>
  147. inline chset<CharT>
  148. operator&(chset<CharT> const& a, CharT b)
  149. {
  150. return a & chset<CharT>(b);
  151. }
  152. //////////////////////////////////
  153. template <typename CharT>
  154. inline chset<CharT>
  155. operator-(chset<CharT> const& a, CharT b)
  156. {
  157. return a - chset<CharT>(b);
  158. }
  159. //////////////////////////////////
  160. template <typename CharT>
  161. inline chset<CharT>
  162. operator^(chset<CharT> const& a, CharT b)
  163. {
  164. return a ^ chset<CharT>(b);
  165. }
  166. //////////////////////////////////
  167. template <typename CharT>
  168. inline chset<CharT>
  169. operator|(CharT a, chset<CharT> const& b)
  170. {
  171. return chset<CharT>(a) | b;
  172. }
  173. //////////////////////////////////
  174. template <typename CharT>
  175. inline chset<CharT>
  176. operator&(CharT a, chset<CharT> const& b)
  177. {
  178. return chset<CharT>(a) & b;
  179. }
  180. //////////////////////////////////
  181. template <typename CharT>
  182. inline chset<CharT>
  183. operator-(CharT a, chset<CharT> const& b)
  184. {
  185. return chset<CharT>(a) - b;
  186. }
  187. //////////////////////////////////
  188. template <typename CharT>
  189. inline chset<CharT>
  190. operator^(CharT a, chset<CharT> const& b)
  191. {
  192. return chset<CharT>(a) ^ b;
  193. }
  194. ///////////////////////////////////////////////////////////////////////////////
  195. //
  196. // chlit <--> chset free operators implementation
  197. //
  198. ///////////////////////////////////////////////////////////////////////////////
  199. template <typename CharT>
  200. inline chset<CharT>
  201. operator|(chset<CharT> const& a, chlit<CharT> const& b)
  202. {
  203. return a | chset<CharT>(b.ch);
  204. }
  205. //////////////////////////////////
  206. template <typename CharT>
  207. inline chset<CharT>
  208. operator&(chset<CharT> const& a, chlit<CharT> const& b)
  209. {
  210. return a & chset<CharT>(b.ch);
  211. }
  212. //////////////////////////////////
  213. template <typename CharT>
  214. inline chset<CharT>
  215. operator-(chset<CharT> const& a, chlit<CharT> const& b)
  216. {
  217. return a - chset<CharT>(b.ch);
  218. }
  219. //////////////////////////////////
  220. template <typename CharT>
  221. inline chset<CharT>
  222. operator^(chset<CharT> const& a, chlit<CharT> const& b)
  223. {
  224. return a ^ chset<CharT>(b.ch);
  225. }
  226. //////////////////////////////////
  227. template <typename CharT>
  228. inline chset<CharT>
  229. operator|(chlit<CharT> const& a, chset<CharT> const& b)
  230. {
  231. return chset<CharT>(a.ch) | b;
  232. }
  233. //////////////////////////////////
  234. template <typename CharT>
  235. inline chset<CharT>
  236. operator&(chlit<CharT> const& a, chset<CharT> const& b)
  237. {
  238. return chset<CharT>(a.ch) & b;
  239. }
  240. //////////////////////////////////
  241. template <typename CharT>
  242. inline chset<CharT>
  243. operator-(chlit<CharT> const& a, chset<CharT> const& b)
  244. {
  245. return chset<CharT>(a.ch) - b;
  246. }
  247. //////////////////////////////////
  248. template <typename CharT>
  249. inline chset<CharT>
  250. operator^(chlit<CharT> const& a, chset<CharT> const& b)
  251. {
  252. return chset<CharT>(a.ch) ^ b;
  253. }
  254. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  255. ///////////////////////////////////////////////////////////////////////////////
  256. //
  257. // negated_char_parser <--> chset free operators implementation
  258. //
  259. ///////////////////////////////////////////////////////////////////////////////
  260. template <typename CharT, typename ParserT>
  261. inline chset<CharT>
  262. operator|(chset<CharT> const& a, negated_char_parser<ParserT> const& b)
  263. {
  264. return a | chset<CharT>(b);
  265. }
  266. //////////////////////////////////
  267. template <typename CharT, typename ParserT>
  268. inline chset<CharT>
  269. operator&(chset<CharT> const& a, negated_char_parser<ParserT> const& b)
  270. {
  271. return a & chset<CharT>(b);
  272. }
  273. //////////////////////////////////
  274. template <typename CharT, typename ParserT>
  275. inline chset<CharT>
  276. operator-(chset<CharT> const& a, negated_char_parser<ParserT> const& b)
  277. {
  278. return a - chset<CharT>(b);
  279. }
  280. //////////////////////////////////
  281. template <typename CharT, typename ParserT>
  282. inline chset<CharT>
  283. operator^(chset<CharT> const& a, negated_char_parser<ParserT> const& b)
  284. {
  285. return a ^ chset<CharT>(b);
  286. }
  287. //////////////////////////////////
  288. template <typename CharT, typename ParserT>
  289. inline chset<CharT>
  290. operator|(negated_char_parser<ParserT> const& a, chset<CharT> const& b)
  291. {
  292. return chset<CharT>(a) | b;
  293. }
  294. //////////////////////////////////
  295. template <typename CharT, typename ParserT>
  296. inline chset<CharT>
  297. operator&(negated_char_parser<ParserT> const& a, chset<CharT> const& b)
  298. {
  299. return chset<CharT>(a) & b;
  300. }
  301. //////////////////////////////////
  302. template <typename CharT, typename ParserT>
  303. inline chset<CharT>
  304. operator-(negated_char_parser<ParserT> const& a, chset<CharT> const& b)
  305. {
  306. return chset<CharT>(a) - b;
  307. }
  308. //////////////////////////////////
  309. template <typename CharT, typename ParserT>
  310. inline chset<CharT>
  311. operator^(negated_char_parser<ParserT> const& a, chset<CharT> const& b)
  312. {
  313. return chset<CharT>(a) ^ b;
  314. }
  315. #else // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  316. ///////////////////////////////////////////////////////////////////////////////
  317. //
  318. // negated_char_parser<range> <--> chset free operators implementation
  319. //
  320. ///////////////////////////////////////////////////////////////////////////////
  321. template <typename CharT>
  322. inline chset<CharT>
  323. operator|(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
  324. {
  325. return a | chset<CharT>(b);
  326. }
  327. //////////////////////////////////
  328. template <typename CharT>
  329. inline chset<CharT>
  330. operator&(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
  331. {
  332. return a & chset<CharT>(b);
  333. }
  334. //////////////////////////////////
  335. template <typename CharT>
  336. inline chset<CharT>
  337. operator-(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
  338. {
  339. return a - chset<CharT>(b);
  340. }
  341. //////////////////////////////////
  342. template <typename CharT>
  343. inline chset<CharT>
  344. operator^(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
  345. {
  346. return a ^ chset<CharT>(b);
  347. }
  348. //////////////////////////////////
  349. template <typename CharT>
  350. inline chset<CharT>
  351. operator|(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
  352. {
  353. return chset<CharT>(a) | b;
  354. }
  355. //////////////////////////////////
  356. template <typename CharT>
  357. inline chset<CharT>
  358. operator&(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
  359. {
  360. return chset<CharT>(a) & b;
  361. }
  362. //////////////////////////////////
  363. template <typename CharT>
  364. inline chset<CharT>
  365. operator-(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
  366. {
  367. return chset<CharT>(a) - b;
  368. }
  369. //////////////////////////////////
  370. template <typename CharT>
  371. inline chset<CharT>
  372. operator^(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
  373. {
  374. return chset<CharT>(a) ^ b;
  375. }
  376. ///////////////////////////////////////////////////////////////////////////////
  377. //
  378. // negated_char_parser<chlit> <--> chset free operators implementation
  379. //
  380. ///////////////////////////////////////////////////////////////////////////////
  381. template <typename CharT>
  382. inline chset<CharT>
  383. operator|(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
  384. {
  385. return a | chset<CharT>(b);
  386. }
  387. //////////////////////////////////
  388. template <typename CharT>
  389. inline chset<CharT>
  390. operator&(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
  391. {
  392. return a & chset<CharT>(b);
  393. }
  394. //////////////////////////////////
  395. template <typename CharT>
  396. inline chset<CharT>
  397. operator-(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
  398. {
  399. return a - chset<CharT>(b);
  400. }
  401. //////////////////////////////////
  402. template <typename CharT>
  403. inline chset<CharT>
  404. operator^(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
  405. {
  406. return a ^ chset<CharT>(b);
  407. }
  408. //////////////////////////////////
  409. template <typename CharT>
  410. inline chset<CharT>
  411. operator|(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
  412. {
  413. return chset<CharT>(a) | b;
  414. }
  415. //////////////////////////////////
  416. template <typename CharT>
  417. inline chset<CharT>
  418. operator&(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
  419. {
  420. return chset<CharT>(a) & b;
  421. }
  422. //////////////////////////////////
  423. template <typename CharT>
  424. inline chset<CharT>
  425. operator-(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
  426. {
  427. return chset<CharT>(a) - b;
  428. }
  429. //////////////////////////////////
  430. template <typename CharT>
  431. inline chset<CharT>
  432. operator^(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
  433. {
  434. return chset<CharT>(a) ^ b;
  435. }
  436. #endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  437. ///////////////////////////////////////////////////////////////////////////////
  438. //
  439. // anychar_parser <--> chset free operators
  440. //
  441. // Where a is chset and b is a anychar_parser, and vice-versa, implements:
  442. //
  443. // a | b, a & b, a - b, a ^ b
  444. //
  445. ///////////////////////////////////////////////////////////////////////////////
  446. namespace impl {
  447. template <typename CharT>
  448. inline BOOST_SPIRIT_CLASSIC_NS::range<CharT> const&
  449. full()
  450. {
  451. static BOOST_SPIRIT_CLASSIC_NS::range<CharT> full_(
  452. (std::numeric_limits<CharT>::min)(),
  453. (std::numeric_limits<CharT>::max)());
  454. return full_;
  455. }
  456. template <typename CharT>
  457. inline BOOST_SPIRIT_CLASSIC_NS::range<CharT> const&
  458. empty()
  459. {
  460. static BOOST_SPIRIT_CLASSIC_NS::range<CharT> empty_;
  461. return empty_;
  462. }
  463. }
  464. //////////////////////////////////
  465. template <typename CharT>
  466. inline chset<CharT>
  467. operator|(chset<CharT> const&, anychar_parser)
  468. {
  469. return chset<CharT>(impl::full<CharT>());
  470. }
  471. //////////////////////////////////
  472. template <typename CharT>
  473. inline chset<CharT>
  474. operator&(chset<CharT> const& a, anychar_parser)
  475. {
  476. return a;
  477. }
  478. //////////////////////////////////
  479. template <typename CharT>
  480. inline chset<CharT>
  481. operator-(chset<CharT> const&, anychar_parser)
  482. {
  483. return chset<CharT>();
  484. }
  485. //////////////////////////////////
  486. template <typename CharT>
  487. inline chset<CharT>
  488. operator^(chset<CharT> const& a, anychar_parser)
  489. {
  490. return ~a;
  491. }
  492. //////////////////////////////////
  493. template <typename CharT>
  494. inline chset<CharT>
  495. operator|(anychar_parser, chset<CharT> const& /*b*/)
  496. {
  497. return chset<CharT>(impl::full<CharT>());
  498. }
  499. //////////////////////////////////
  500. template <typename CharT>
  501. inline chset<CharT>
  502. operator&(anychar_parser, chset<CharT> const& b)
  503. {
  504. return b;
  505. }
  506. //////////////////////////////////
  507. template <typename CharT>
  508. inline chset<CharT>
  509. operator-(anychar_parser, chset<CharT> const& b)
  510. {
  511. return ~b;
  512. }
  513. //////////////////////////////////
  514. template <typename CharT>
  515. inline chset<CharT>
  516. operator^(anychar_parser, chset<CharT> const& b)
  517. {
  518. return ~b;
  519. }
  520. ///////////////////////////////////////////////////////////////////////////////
  521. //
  522. // nothing_parser <--> chset free operators implementation
  523. //
  524. ///////////////////////////////////////////////////////////////////////////////
  525. template <typename CharT>
  526. inline chset<CharT>
  527. operator|(chset<CharT> const& a, nothing_parser)
  528. {
  529. return a;
  530. }
  531. //////////////////////////////////
  532. template <typename CharT>
  533. inline chset<CharT>
  534. operator&(chset<CharT> const& /*a*/, nothing_parser)
  535. {
  536. return impl::empty<CharT>();
  537. }
  538. //////////////////////////////////
  539. template <typename CharT>
  540. inline chset<CharT>
  541. operator-(chset<CharT> const& a, nothing_parser)
  542. {
  543. return a;
  544. }
  545. //////////////////////////////////
  546. template <typename CharT>
  547. inline chset<CharT>
  548. operator^(chset<CharT> const& a, nothing_parser)
  549. {
  550. return a;
  551. }
  552. //////////////////////////////////
  553. template <typename CharT>
  554. inline chset<CharT>
  555. operator|(nothing_parser, chset<CharT> const& b)
  556. {
  557. return b;
  558. }
  559. //////////////////////////////////
  560. template <typename CharT>
  561. inline chset<CharT>
  562. operator&(nothing_parser, chset<CharT> const& /*b*/)
  563. {
  564. return impl::empty<CharT>();
  565. }
  566. //////////////////////////////////
  567. template <typename CharT>
  568. inline chset<CharT>
  569. operator-(nothing_parser, chset<CharT> const& /*b*/)
  570. {
  571. return impl::empty<CharT>();
  572. }
  573. //////////////////////////////////
  574. template <typename CharT>
  575. inline chset<CharT>
  576. operator^(nothing_parser, chset<CharT> const& b)
  577. {
  578. return b;
  579. }
  580. ///////////////////////////////////////////////////////////////////////////////
  581. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  582. }} // namespace boost::spirit
  583. #endif