/Src/Dependencies/Boost/boost/spirit/home/classic/utility/impl/chset.ipp

http://hadesmem.googlecode.com/ · C++ Header · 366 lines · 291 code · 56 blank · 19 comment · 27 complexity · 25190b27d0bdacfb122c020588451b78 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Joel de Guzman
  3. Copyright (c) 2001-2003 Daniel Nuffer
  4. http://spirit.sourceforge.net/
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================*/
  9. #ifndef BOOST_SPIRIT_CHSET_IPP
  10. #define BOOST_SPIRIT_CHSET_IPP
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <boost/limits.hpp>
  13. #include <boost/spirit/home/classic/utility/chset.hpp>
  14. ///////////////////////////////////////////////////////////////////////////////
  15. namespace boost { namespace spirit {
  16. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //
  19. // chset class
  20. //
  21. ///////////////////////////////////////////////////////////////////////////////
  22. namespace utility { namespace impl {
  23. template <typename CharT>
  24. inline void
  25. detach(boost::shared_ptr<basic_chset<CharT> >& ptr)
  26. {
  27. if (!ptr.unique())
  28. ptr = boost::shared_ptr<basic_chset<CharT> >
  29. (new basic_chset<CharT>(*ptr));
  30. }
  31. template <typename CharT>
  32. inline void
  33. detach_clear(boost::shared_ptr<basic_chset<CharT> >& ptr)
  34. {
  35. if (ptr.unique())
  36. ptr->clear();
  37. else
  38. ptr.reset(new basic_chset<CharT>());
  39. }
  40. template <typename CharT, typename CharT2>
  41. void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
  42. CharT2 const* definition)
  43. {
  44. CharT2 ch = *definition++;
  45. while (ch)
  46. {
  47. CharT2 next = *definition++;
  48. if (next == '-')
  49. {
  50. next = *definition++;
  51. if (next == 0)
  52. {
  53. ptr->set(ch);
  54. ptr->set('-');
  55. break;
  56. }
  57. ptr->set(ch, next);
  58. }
  59. else
  60. {
  61. ptr->set(ch);
  62. }
  63. ch = next;
  64. }
  65. }
  66. //////////////////////////////////
  67. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  68. template <typename CharT, typename FakeT>
  69. void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr, chlit<CharT> const &ch,
  70. FakeT)
  71. {
  72. if(ch.ch != (std::numeric_limits<CharT>::min)()) {
  73. ptr->set((std::numeric_limits<CharT>::min)(), ch.ch - 1);
  74. }
  75. if(ch.ch != (std::numeric_limits<CharT>::max)()) {
  76. ptr->set(ch.ch + 1, (std::numeric_limits<CharT>::max)());
  77. }
  78. }
  79. template <typename CharT, typename FakeT>
  80. void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr,
  81. spirit::range<CharT> const &rng, FakeT)
  82. {
  83. if(rng.first != (std::numeric_limits<CharT>::min)()) {
  84. ptr->set((std::numeric_limits<CharT>::min)(), rng.first - 1);
  85. }
  86. if(rng.last != (std::numeric_limits<CharT>::max)()) {
  87. ptr->set(rng.last + 1, (std::numeric_limits<CharT>::max)());
  88. }
  89. }
  90. #endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  91. //////////////////////////////////
  92. }} // namespace utility::impl
  93. template <typename CharT>
  94. inline chset<CharT>::chset()
  95. : ptr(new basic_chset<CharT>()) {}
  96. template <typename CharT>
  97. inline chset<CharT>::chset(chset const& arg_)
  98. : ptr(new basic_chset<CharT>(*arg_.ptr)) {}
  99. template <typename CharT>
  100. inline chset<CharT>::chset(CharT arg_)
  101. : ptr(new basic_chset<CharT>())
  102. { ptr->set(arg_); }
  103. template <typename CharT>
  104. inline chset<CharT>::chset(anychar_parser /*arg*/)
  105. : ptr(new basic_chset<CharT>())
  106. {
  107. ptr->set(
  108. (std::numeric_limits<CharT>::min)(),
  109. (std::numeric_limits<CharT>::max)()
  110. );
  111. }
  112. template <typename CharT>
  113. inline chset<CharT>::chset(nothing_parser arg_)
  114. : ptr(new basic_chset<CharT>()) {}
  115. template <typename CharT>
  116. inline chset<CharT>::chset(chlit<CharT> const& arg_)
  117. : ptr(new basic_chset<CharT>())
  118. { ptr->set(arg_.ch); }
  119. template <typename CharT>
  120. inline chset<CharT>::chset(range<CharT> const& arg_)
  121. : ptr(new basic_chset<CharT>())
  122. { ptr->set(arg_.first, arg_.last); }
  123. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  124. template <typename CharT>
  125. inline chset<CharT>::chset(negated_char_parser<chlit<CharT> > const& arg_)
  126. : ptr(new basic_chset<CharT>())
  127. {
  128. set(arg_);
  129. }
  130. template <typename CharT>
  131. inline chset<CharT>::chset(negated_char_parser<range<CharT> > const& arg_)
  132. : ptr(new basic_chset<CharT>())
  133. {
  134. set(arg_);
  135. }
  136. #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  137. template <typename CharT>
  138. inline chset<CharT>::~chset() {}
  139. template <typename CharT>
  140. inline chset<CharT>&
  141. chset<CharT>::operator=(chset const& rhs)
  142. {
  143. ptr = rhs.ptr;
  144. return *this;
  145. }
  146. template <typename CharT>
  147. inline chset<CharT>&
  148. chset<CharT>::operator=(CharT rhs)
  149. {
  150. utility::impl::detach_clear(ptr);
  151. ptr->set(rhs);
  152. return *this;
  153. }
  154. template <typename CharT>
  155. inline chset<CharT>&
  156. chset<CharT>::operator=(anychar_parser rhs)
  157. {
  158. utility::impl::detach_clear(ptr);
  159. ptr->set(
  160. (std::numeric_limits<CharT>::min)(),
  161. (std::numeric_limits<CharT>::max)()
  162. );
  163. return *this;
  164. }
  165. template <typename CharT>
  166. inline chset<CharT>&
  167. chset<CharT>::operator=(nothing_parser rhs)
  168. {
  169. utility::impl::detach_clear(ptr);
  170. return *this;
  171. }
  172. template <typename CharT>
  173. inline chset<CharT>&
  174. chset<CharT>::operator=(chlit<CharT> const& rhs)
  175. {
  176. utility::impl::detach_clear(ptr);
  177. ptr->set(rhs.ch);
  178. return *this;
  179. }
  180. template <typename CharT>
  181. inline chset<CharT>&
  182. chset<CharT>::operator=(range<CharT> const& rhs)
  183. {
  184. utility::impl::detach_clear(ptr);
  185. ptr->set(rhs.first, rhs.last);
  186. return *this;
  187. }
  188. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  189. template <typename CharT>
  190. inline chset<CharT>&
  191. chset<CharT>::operator=(negated_char_parser<chlit<CharT> > const& rhs)
  192. {
  193. utility::impl::detach_clear(ptr);
  194. set(rhs);
  195. return *this;
  196. }
  197. template <typename CharT>
  198. inline chset<CharT>&
  199. chset<CharT>::operator=(negated_char_parser<range<CharT> > const& rhs)
  200. {
  201. utility::impl::detach_clear(ptr);
  202. set(rhs);
  203. return *this;
  204. }
  205. #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  206. template <typename CharT>
  207. inline void
  208. chset<CharT>::set(range<CharT> const& arg_)
  209. {
  210. utility::impl::detach(ptr);
  211. ptr->set(arg_.first, arg_.last);
  212. }
  213. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  214. template <typename CharT>
  215. inline void
  216. chset<CharT>::set(negated_char_parser<chlit<CharT> > const& arg_)
  217. {
  218. utility::impl::detach(ptr);
  219. if(arg_.positive.ch != (std::numeric_limits<CharT>::min)()) {
  220. ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.ch - 1);
  221. }
  222. if(arg_.positive.ch != (std::numeric_limits<CharT>::max)()) {
  223. ptr->set(arg_.positive.ch + 1, (std::numeric_limits<CharT>::max)());
  224. }
  225. }
  226. template <typename CharT>
  227. inline void
  228. chset<CharT>::set(negated_char_parser<range<CharT> > const& arg_)
  229. {
  230. utility::impl::detach(ptr);
  231. if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
  232. ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
  233. }
  234. if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
  235. ptr->set(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
  236. }
  237. }
  238. #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  239. template <typename CharT>
  240. inline void
  241. chset<CharT>::clear(range<CharT> const& arg_)
  242. {
  243. utility::impl::detach(ptr);
  244. ptr->clear(arg_.first, arg_.last);
  245. }
  246. template <typename CharT>
  247. inline void
  248. chset<CharT>::clear(negated_char_parser<range<CharT> > const& arg_)
  249. {
  250. utility::impl::detach(ptr);
  251. if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
  252. ptr->clear((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
  253. }
  254. if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
  255. ptr->clear(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
  256. }
  257. }
  258. template <typename CharT>
  259. inline bool
  260. chset<CharT>::test(CharT ch) const
  261. { return ptr->test(ch); }
  262. template <typename CharT>
  263. inline chset<CharT>&
  264. chset<CharT>::inverse()
  265. {
  266. utility::impl::detach(ptr);
  267. ptr->inverse();
  268. return *this;
  269. }
  270. template <typename CharT>
  271. inline void
  272. chset<CharT>::swap(chset& x)
  273. { ptr.swap(x.ptr); }
  274. template <typename CharT>
  275. inline chset<CharT>&
  276. chset<CharT>::operator|=(chset const& x)
  277. {
  278. utility::impl::detach(ptr);
  279. *ptr |= *x.ptr;
  280. return *this;
  281. }
  282. template <typename CharT>
  283. inline chset<CharT>&
  284. chset<CharT>::operator&=(chset const& x)
  285. {
  286. utility::impl::detach(ptr);
  287. *ptr &= *x.ptr;
  288. return *this;
  289. }
  290. template <typename CharT>
  291. inline chset<CharT>&
  292. chset<CharT>::operator-=(chset const& x)
  293. {
  294. utility::impl::detach(ptr);
  295. *ptr -= *x.ptr;
  296. return *this;
  297. }
  298. template <typename CharT>
  299. inline chset<CharT>&
  300. chset<CharT>::operator^=(chset const& x)
  301. {
  302. utility::impl::detach(ptr);
  303. *ptr ^= *x.ptr;
  304. return *this;
  305. }
  306. ///////////////////////////////////////////////////////////////////////////////
  307. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  308. }} // namespace boost::spirit
  309. #endif