Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

935 lines
22 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * rubyiterators.swg
  6. *
  7. * Implement a C++ 'output' iterator for Ruby.
  8. *
  9. * Users can derive form the Iterator to implemet their
  10. * own iterators. As an example (real one since we use it for STL/STD
  11. * containers), the template Iterator_T does the
  12. * implementation for generic C++ iterators.
  13. * ----------------------------------------------------------------------------- */
  14. %include <std_common.i>
  15. %fragment("ConstIterator","header") {
  16. namespace swig {
  17. struct stop_iteration {
  18. };
  19. /**
  20. * Abstract base class used to represent all iterators of STL containers.
  21. */
  22. struct ConstIterator {
  23. public:
  24. typedef ConstIterator self_type;
  25. protected:
  26. GC_VALUE _seq;
  27. protected:
  28. ConstIterator(VALUE seq) : _seq(seq)
  29. {
  30. }
  31. // Random access iterator methods, but not required in Ruby
  32. virtual ptrdiff_t distance(const ConstIterator &x) const
  33. {
  34. throw std::invalid_argument("distance not supported");
  35. }
  36. virtual bool equal (const ConstIterator &x) const
  37. {
  38. throw std::invalid_argument("equal not supported");
  39. }
  40. virtual self_type* advance(ptrdiff_t n)
  41. {
  42. throw std::invalid_argument("advance not supported");
  43. }
  44. public:
  45. virtual ~ConstIterator() {}
  46. // Access iterator method, required by Ruby
  47. virtual VALUE value() const {
  48. throw std::invalid_argument("value not supported");
  49. return Qnil;
  50. };
  51. virtual VALUE setValue( const VALUE& v ) {
  52. throw std::invalid_argument("value= not supported");
  53. return Qnil;
  54. }
  55. virtual self_type* next( size_t n = 1 )
  56. {
  57. return this->advance( n );
  58. }
  59. virtual self_type* previous( size_t n = 1 )
  60. {
  61. ptrdiff_t nn = n;
  62. return this->advance( -nn );
  63. }
  64. virtual VALUE to_s() const {
  65. throw std::invalid_argument("to_s not supported");
  66. return Qnil;
  67. }
  68. virtual VALUE inspect() const {
  69. throw std::invalid_argument("inspect not supported");
  70. return Qnil;
  71. }
  72. virtual ConstIterator *dup() const
  73. {
  74. throw std::invalid_argument("dup not supported");
  75. return NULL;
  76. }
  77. //
  78. // C++ common/needed methods. We emulate a bidirectional
  79. // operator, to be compatible with all the STL.
  80. // The iterator traits will then tell the STL what type of
  81. // iterator we really are.
  82. //
  83. ConstIterator() : _seq( Qnil )
  84. {
  85. }
  86. ConstIterator( const self_type& b ) : _seq( b._seq )
  87. {
  88. }
  89. self_type& operator=( const self_type& b )
  90. {
  91. _seq = b._seq;
  92. return *this;
  93. }
  94. bool operator == (const ConstIterator& x) const
  95. {
  96. return equal(x);
  97. }
  98. bool operator != (const ConstIterator& x) const
  99. {
  100. return ! operator==(x);
  101. }
  102. // Pre-decrement operator
  103. self_type& operator--()
  104. {
  105. return *previous();
  106. }
  107. // Pre-increment operator
  108. self_type& operator++()
  109. {
  110. return *next();
  111. }
  112. // Post-decrement operator
  113. self_type operator--(int)
  114. {
  115. self_type r = *this;
  116. previous();
  117. return r;
  118. }
  119. // Post-increment operator
  120. self_type operator++(int)
  121. {
  122. self_type r = *this;
  123. next();
  124. return r;
  125. }
  126. ConstIterator& operator += (ptrdiff_t n)
  127. {
  128. return *advance(n);
  129. }
  130. ConstIterator& operator -= (ptrdiff_t n)
  131. {
  132. return *advance(-n);
  133. }
  134. ConstIterator* operator + (ptrdiff_t n) const
  135. {
  136. return dup()->advance(n);
  137. }
  138. ConstIterator* operator - (ptrdiff_t n) const
  139. {
  140. return dup()->advance(-n);
  141. }
  142. ptrdiff_t operator - (const ConstIterator& x) const
  143. {
  144. return x.distance(*this);
  145. }
  146. static swig_type_info* descriptor() {
  147. static int init = 0;
  148. static swig_type_info* desc = 0;
  149. if (!init) {
  150. desc = SWIG_TypeQuery("swig::ConstIterator *");
  151. init = 1;
  152. }
  153. return desc;
  154. }
  155. };
  156. /**
  157. * Abstract base class used to represent all non-const iterators of STL containers.
  158. *
  159. */
  160. struct Iterator : public ConstIterator {
  161. public:
  162. typedef Iterator self_type;
  163. protected:
  164. Iterator(VALUE seq) : ConstIterator(seq)
  165. {
  166. }
  167. virtual self_type* advance(ptrdiff_t n)
  168. {
  169. throw std::invalid_argument("operation not supported");
  170. }
  171. public:
  172. static swig_type_info* descriptor() {
  173. static int init = 0;
  174. static swig_type_info* desc = 0;
  175. if (!init) {
  176. desc = SWIG_TypeQuery("swig::Iterator *");
  177. init = 1;
  178. }
  179. return desc;
  180. }
  181. virtual Iterator *dup() const
  182. {
  183. throw std::invalid_argument("dup not supported");
  184. return NULL;
  185. }
  186. virtual self_type* next( size_t n = 1 )
  187. {
  188. return this->advance( n );
  189. }
  190. virtual self_type* previous( size_t n = 1 )
  191. {
  192. ptrdiff_t nn = n;
  193. return this->advance( -nn );
  194. }
  195. bool operator == (const ConstIterator& x) const
  196. {
  197. return equal(x);
  198. }
  199. bool operator != (const Iterator& x) const
  200. {
  201. return ! operator==(x);
  202. }
  203. Iterator& operator += (ptrdiff_t n)
  204. {
  205. return *advance(n);
  206. }
  207. Iterator& operator -= (ptrdiff_t n)
  208. {
  209. return *advance(-n);
  210. }
  211. Iterator* operator + (ptrdiff_t n) const
  212. {
  213. return dup()->advance(n);
  214. }
  215. Iterator* operator - (ptrdiff_t n) const
  216. {
  217. return dup()->advance(-n);
  218. }
  219. ptrdiff_t operator - (const Iterator& x) const
  220. {
  221. return x.distance(*this);
  222. }
  223. };
  224. }
  225. }
  226. %fragment("ConstIterator_T","header",fragment="ConstIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
  227. namespace swig {
  228. /**
  229. * Templated base classes for all custom const_iterators.
  230. *
  231. */
  232. template<typename OutConstIterator>
  233. class ConstIterator_T : public ConstIterator
  234. {
  235. public:
  236. typedef OutConstIterator const_iter;
  237. typedef typename std::iterator_traits<const_iter>::value_type value_type;
  238. typedef ConstIterator_T<const_iter> self_type;
  239. protected:
  240. virtual bool equal (const ConstIterator &iter) const
  241. {
  242. const self_type *iters = dynamic_cast<const self_type *>(&iter);
  243. if (iters) {
  244. return (current == iters->get_current());
  245. } else {
  246. throw std::invalid_argument("bad iterator type");
  247. }
  248. }
  249. virtual ptrdiff_t distance(const ConstIterator &iter) const
  250. {
  251. const self_type *iters = dynamic_cast<const self_type *>(&iter);
  252. if (iters) {
  253. return std::distance(current, iters->get_current());
  254. } else {
  255. throw std::invalid_argument("bad iterator type");
  256. }
  257. }
  258. virtual ConstIterator* advance(ptrdiff_t n)
  259. {
  260. std::advance( current, n );
  261. return this;
  262. }
  263. public:
  264. ConstIterator_T() : ConstIterator(Qnil)
  265. {
  266. }
  267. ConstIterator_T(const_iter curr, VALUE seq = Qnil)
  268. : ConstIterator(seq), current(curr)
  269. {
  270. }
  271. const const_iter& get_current() const
  272. {
  273. return current;
  274. }
  275. const value_type& operator*() const
  276. {
  277. return *current;
  278. }
  279. virtual VALUE inspect() const
  280. {
  281. VALUE ret = rb_str_new2("#<");
  282. ret = rb_str_cat2( ret, rb_obj_classname(_seq) );
  283. ret = rb_str_cat2( ret, "::const_iterator " );
  284. VALUE cur = value();
  285. ret = rb_str_concat( ret, rb_inspect(cur) );
  286. ret = rb_str_cat2( ret, ">" );
  287. return ret;
  288. }
  289. virtual VALUE to_s() const
  290. {
  291. VALUE ret = rb_str_new2( rb_obj_classname(_seq) );
  292. ret = rb_str_cat2( ret, "::const_iterator " );
  293. VALUE cur = value();
  294. ret = rb_str_concat( ret, rb_obj_as_string(cur) );
  295. return ret;
  296. }
  297. protected:
  298. const_iter current;
  299. };
  300. /**
  301. * Templated base classes for all custom non-const iterators.
  302. *
  303. */
  304. template<typename InOutIterator>
  305. class Iterator_T : public Iterator
  306. {
  307. public:
  308. typedef InOutIterator nonconst_iter;
  309. // Make this class iterator STL compatible, by using iterator_traits
  310. typedef typename std::iterator_traits<nonconst_iter >::iterator_category iterator_category;
  311. typedef typename std::iterator_traits<nonconst_iter >::value_type value_type;
  312. typedef typename std::iterator_traits<nonconst_iter >::difference_type difference_type;
  313. typedef typename std::iterator_traits<nonconst_iter >::pointer pointer;
  314. typedef typename std::iterator_traits<nonconst_iter >::reference reference;
  315. typedef Iterator base;
  316. typedef Iterator_T< nonconst_iter > self_type;
  317. protected:
  318. virtual bool equal (const ConstIterator &iter) const
  319. {
  320. const self_type *iters = dynamic_cast<const self_type *>(&iter);
  321. if (iters) {
  322. return (current == iters->get_current());
  323. } else {
  324. throw std::invalid_argument("bad iterator type");
  325. }
  326. }
  327. virtual ptrdiff_t distance(const ConstIterator &iter) const
  328. {
  329. const self_type *iters = dynamic_cast<const self_type *>(&iter);
  330. if (iters) {
  331. return std::distance(current, iters->get_current());
  332. } else {
  333. throw std::invalid_argument("bad iterator type");
  334. }
  335. }
  336. virtual Iterator* advance(ptrdiff_t n)
  337. {
  338. std::advance( current, n );
  339. return this;
  340. }
  341. public:
  342. Iterator_T(nonconst_iter curr, VALUE seq = Qnil)
  343. : Iterator(seq), current(curr)
  344. {
  345. }
  346. const nonconst_iter& get_current() const
  347. {
  348. return current;
  349. }
  350. self_type& operator=( const self_type& b )
  351. {
  352. base::operator=( b );
  353. return *this;
  354. }
  355. self_type& operator=( const value_type& b )
  356. {
  357. *current = b;
  358. return *this;
  359. }
  360. const value_type& operator*() const
  361. {
  362. return *current;
  363. }
  364. value_type& operator*()
  365. {
  366. return *current;
  367. }
  368. virtual VALUE inspect() const
  369. {
  370. VALUE ret = rb_str_new2("#<");
  371. ret = rb_str_cat2( ret, rb_obj_classname(_seq) );
  372. ret = rb_str_cat2( ret, "::iterator " );
  373. VALUE cur = value();
  374. ret = rb_str_concat( ret, rb_inspect(cur) );
  375. ret = rb_str_cat2( ret, ">" );
  376. return ret;
  377. }
  378. virtual VALUE to_s() const
  379. {
  380. VALUE ret = rb_str_new2( rb_obj_classname(_seq) );
  381. ret = rb_str_cat2( ret, "::iterator " );
  382. VALUE cur = value();
  383. ret = rb_str_concat( ret, rb_obj_as_string(cur) );
  384. return ret;
  385. }
  386. protected:
  387. nonconst_iter current;
  388. };
  389. /**
  390. * Auxiliary functor to store the value of a ruby object inside
  391. * a reference of a compatible C++ type. ie: Ruby -> C++
  392. *
  393. */
  394. template <class ValueType>
  395. struct asval_oper
  396. {
  397. typedef ValueType value_type;
  398. typedef bool result_type;
  399. bool operator()(VALUE obj, value_type& v) const
  400. {
  401. return ( swig::asval< value_type >(obj, &v) == SWIG_OK );
  402. }
  403. };
  404. /**
  405. * Auxiliary functor to return a ruby object from a C++ type.
  406. * ie: C++ -> Ruby
  407. *
  408. */
  409. template <class ValueType>
  410. struct from_oper
  411. {
  412. typedef const ValueType& argument_type;
  413. typedef VALUE result_type;
  414. result_type operator()(argument_type v) const
  415. {
  416. return swig::from(v);
  417. }
  418. };
  419. /**
  420. * ConstIterator class for a const_iterator with no end() boundaries.
  421. *
  422. */
  423. template<typename OutConstIterator,
  424. typename ValueType = typename std::iterator_traits<OutConstIterator>::value_type,
  425. typename FromOper = from_oper<ValueType> >
  426. class ConstIteratorOpen_T : public ConstIterator_T<OutConstIterator>
  427. {
  428. public:
  429. FromOper from;
  430. typedef OutConstIterator const_iter;
  431. typedef ValueType value_type;
  432. typedef ConstIterator_T<const_iter> base;
  433. typedef ConstIteratorOpen_T<OutConstIterator, ValueType, FromOper> self_type;
  434. ConstIteratorOpen_T(const_iter curr, VALUE seq = Qnil)
  435. : ConstIterator_T<OutConstIterator>(curr, seq)
  436. {
  437. }
  438. virtual VALUE value() const {
  439. return from(static_cast<const value_type&>(*(base::current)));
  440. }
  441. ConstIterator *dup() const
  442. {
  443. return new self_type(*this);
  444. }
  445. };
  446. /**
  447. * Iterator class for an iterator with no end() boundaries.
  448. *
  449. */
  450. template<typename InOutIterator,
  451. typename ValueType = typename std::iterator_traits<InOutIterator>::value_type,
  452. typename FromOper = from_oper<ValueType>,
  453. typename AsvalOper = asval_oper<ValueType> >
  454. class IteratorOpen_T : public Iterator_T<InOutIterator>
  455. {
  456. public:
  457. FromOper from;
  458. AsvalOper asval;
  459. typedef InOutIterator nonconst_iter;
  460. typedef ValueType value_type;
  461. typedef Iterator_T<nonconst_iter> base;
  462. typedef IteratorOpen_T<InOutIterator, ValueType, FromOper, AsvalOper> self_type;
  463. public:
  464. IteratorOpen_T(nonconst_iter curr, VALUE seq = Qnil)
  465. : Iterator_T<InOutIterator>(curr, seq)
  466. {
  467. }
  468. virtual VALUE value() const {
  469. return from(static_cast<const value_type&>(*(base::current)));
  470. }
  471. virtual VALUE setValue( const VALUE& v )
  472. {
  473. value_type& dst = *base::current;
  474. if ( asval(v, dst) ) return v;
  475. return Qnil;
  476. }
  477. Iterator *dup() const
  478. {
  479. return new self_type(*this);
  480. }
  481. };
  482. /**
  483. * ConstIterator class for a const_iterator where begin() and end() boundaries are known.
  484. *
  485. */
  486. template<typename OutConstIterator,
  487. typename ValueType = typename std::iterator_traits<OutConstIterator>::value_type,
  488. typename FromOper = from_oper<ValueType> >
  489. class ConstIteratorClosed_T : public ConstIterator_T<OutConstIterator>
  490. {
  491. public:
  492. FromOper from;
  493. typedef OutConstIterator const_iter;
  494. typedef ValueType value_type;
  495. typedef ConstIterator_T<const_iter> base;
  496. typedef ConstIteratorClosed_T<OutConstIterator, ValueType, FromOper> self_type;
  497. protected:
  498. virtual ConstIterator* advance(ptrdiff_t n)
  499. {
  500. std::advance( base::current, n );
  501. if ( base::current == end )
  502. throw stop_iteration();
  503. return this;
  504. }
  505. public:
  506. ConstIteratorClosed_T(const_iter curr, const_iter first,
  507. const_iter last, VALUE seq = Qnil)
  508. : ConstIterator_T<OutConstIterator>(curr, seq), begin(first), end(last)
  509. {
  510. }
  511. virtual VALUE value() const {
  512. if (base::current == end) {
  513. throw stop_iteration();
  514. } else {
  515. return from(static_cast<const value_type&>(*(base::current)));
  516. }
  517. }
  518. ConstIterator *dup() const
  519. {
  520. return new self_type(*this);
  521. }
  522. private:
  523. const_iter begin;
  524. const_iter end;
  525. };
  526. /**
  527. * Iterator class for a iterator where begin() and end() boundaries are known.
  528. *
  529. */
  530. template<typename InOutIterator,
  531. typename ValueType = typename std::iterator_traits<InOutIterator>::value_type,
  532. typename FromOper = from_oper<ValueType>,
  533. typename AsvalOper = asval_oper<ValueType> >
  534. class IteratorClosed_T : public Iterator_T<InOutIterator>
  535. {
  536. public:
  537. FromOper from;
  538. AsvalOper asval;
  539. typedef InOutIterator nonconst_iter;
  540. typedef ValueType value_type;
  541. typedef Iterator_T<nonconst_iter> base;
  542. typedef IteratorClosed_T<InOutIterator, ValueType, FromOper, AsvalOper> self_type;
  543. protected:
  544. virtual Iterator* advance(ptrdiff_t n)
  545. {
  546. std::advance( base::current, n );
  547. if ( base::current == end )
  548. throw stop_iteration();
  549. return this;
  550. }
  551. public:
  552. IteratorClosed_T(nonconst_iter curr, nonconst_iter first,
  553. nonconst_iter last, VALUE seq = Qnil)
  554. : Iterator_T<InOutIterator>(curr, seq), begin(first), end(last)
  555. {
  556. }
  557. virtual VALUE value() const {
  558. if (base::current == end) {
  559. throw stop_iteration();
  560. } else {
  561. return from(static_cast<const value_type&>(*(base::current)));
  562. }
  563. }
  564. // Iterator setter method, required by Ruby
  565. virtual VALUE setValue( const VALUE& v )
  566. {
  567. if (base::current == end)
  568. throw stop_iteration();
  569. value_type& dst = *base::current;
  570. if ( asval( v, dst ) ) return v;
  571. return Qnil;
  572. }
  573. Iterator *dup() const
  574. {
  575. return new self_type(*this);
  576. }
  577. private:
  578. nonconst_iter begin;
  579. nonconst_iter end;
  580. };
  581. /* Partial specialization for bools which don't allow de-referencing */
  582. template< typename InOutIterator, typename FromOper, typename AsvalOper >
  583. class IteratorOpen_T< InOutIterator, bool, FromOper, AsvalOper > :
  584. public Iterator_T<InOutIterator>
  585. {
  586. public:
  587. FromOper from;
  588. AsvalOper asval;
  589. typedef InOutIterator nonconst_iter;
  590. typedef bool value_type;
  591. typedef Iterator_T<nonconst_iter> base;
  592. typedef IteratorOpen_T<InOutIterator, bool, FromOper, AsvalOper> self_type;
  593. IteratorOpen_T(nonconst_iter curr, VALUE seq = Qnil)
  594. : Iterator_T<InOutIterator>(curr, seq)
  595. {
  596. }
  597. virtual VALUE value() const {
  598. return from(static_cast<const value_type&>(*(base::current)));
  599. }
  600. virtual VALUE setValue( const VALUE& v )
  601. {
  602. bool tmp = *base::current;
  603. if ( asval( v, tmp ) )
  604. {
  605. *base::current = tmp;
  606. return v;
  607. }
  608. return Qnil;
  609. }
  610. Iterator *dup() const
  611. {
  612. return new self_type(*this);
  613. }
  614. };
  615. /* Partial specialization for bools which don't allow de-referencing */
  616. template< typename InOutIterator, typename FromOper, typename AsvalOper >
  617. class IteratorClosed_T< InOutIterator, bool, FromOper, AsvalOper > :
  618. public Iterator_T<InOutIterator>
  619. {
  620. public:
  621. FromOper from;
  622. AsvalOper asval;
  623. typedef InOutIterator nonconst_iter;
  624. typedef bool value_type;
  625. typedef Iterator_T<nonconst_iter> base;
  626. typedef IteratorClosed_T<InOutIterator, bool, FromOper, AsvalOper> self_type;
  627. protected:
  628. virtual Iterator* advance(ptrdiff_t n)
  629. {
  630. std::advance( base::current, n );
  631. if ( base::current == end )
  632. throw stop_iteration();
  633. return this;
  634. }
  635. public:
  636. IteratorClosed_T(nonconst_iter curr, nonconst_iter first,
  637. nonconst_iter last, VALUE seq = Qnil)
  638. : Iterator_T<InOutIterator>(curr, seq), begin(first), end(last)
  639. {
  640. }
  641. virtual VALUE value() const {
  642. if (base::current == end) {
  643. throw stop_iteration();
  644. } else {
  645. return from(static_cast<const value_type&>(*(base::current)));
  646. }
  647. }
  648. virtual VALUE setValue( const VALUE& v )
  649. {
  650. if (base::current == end)
  651. throw stop_iteration();
  652. bool tmp = *base::current;
  653. if ( asval( v, tmp ) )
  654. {
  655. *base::current = tmp;
  656. return v;
  657. }
  658. return Qnil;
  659. }
  660. Iterator *dup() const
  661. {
  662. return new self_type(*this);
  663. }
  664. private:
  665. nonconst_iter begin;
  666. nonconst_iter end;
  667. };
  668. /**
  669. * Helper function used to wrap a bounded const_iterator. This is to be used in
  670. * a %typemap(out), for example.
  671. *
  672. */
  673. template<typename InOutIter>
  674. inline Iterator*
  675. make_nonconst_iterator(const InOutIter& current, const InOutIter& begin,
  676. const InOutIter& end, VALUE seq = Qnil)
  677. {
  678. return new IteratorClosed_T<InOutIter>(current, begin, end, seq);
  679. }
  680. /**
  681. * Helper function used to wrap an unbounded const_iterator. This is to be used in
  682. * a %typemap(out), for example.
  683. *
  684. */
  685. template<typename InOutIter>
  686. inline Iterator*
  687. make_nonconst_iterator(const InOutIter& current, VALUE seq = Qnil)
  688. {
  689. return new IteratorOpen_T<InOutIter>(current, seq);
  690. }
  691. /**
  692. * Helper function used to wrap a bounded const_iterator. This is to be used in
  693. * a %typemap(out), for example.
  694. *
  695. */
  696. template<typename OutIter>
  697. inline ConstIterator*
  698. make_const_iterator(const OutIter& current, const OutIter& begin,
  699. const OutIter& end, VALUE seq = Qnil)
  700. {
  701. return new ConstIteratorClosed_T<OutIter>(current, begin, end, seq);
  702. }
  703. /**
  704. * Helper function used to wrap an unbounded const_iterator. This is to be used in
  705. * a %typemap(out), for example.
  706. *
  707. */
  708. template<typename OutIter>
  709. inline ConstIterator*
  710. make_const_iterator(const OutIter& current, VALUE seq = Qnil)
  711. {
  712. return new ConstIteratorOpen_T<OutIter>(current, seq);
  713. }
  714. }
  715. }
  716. %fragment("ConstIterator");
  717. //
  718. // This part is just so SWIG is aware of the base abstract iterator class.
  719. //
  720. namespace swig
  721. {
  722. /*
  723. Throw a StopIteration exception
  724. */
  725. %ignore stop_iteration;
  726. struct stop_iteration {};
  727. %typemap(throws) stop_iteration {
  728. (void)$1;
  729. SWIG_Ruby_ExceptionType(NULL, Qnil);
  730. SWIG_fail;
  731. }
  732. /*
  733. Mark methods that return new objects
  734. */
  735. %newobject ConstIterator::dup;
  736. %newobject ConstIterator::operator + (ptrdiff_t n) const;
  737. %newobject ConstIterator::operator - (ptrdiff_t n) const;
  738. %nodirector ConstIterator;
  739. %catches(swig::stop_iteration) ConstIterator::value() const;
  740. %catches(swig::stop_iteration) ConstIterator::incr(size_t n = 1);
  741. %catches(swig::stop_iteration) ConstIterator::decr(size_t n = 1);
  742. %catches(std::invalid_argument) ConstIterator::distance(const ConstIterator &x) const;
  743. %catches(std::invalid_argument) ConstIterator::equal (const ConstIterator &x) const;
  744. %catches(swig::stop_iteration) ConstIterator::next();
  745. %catches(swig::stop_iteration) ConstIterator::previous();
  746. %catches(swig::stop_iteration) ConstIterator::advance(ptrdiff_t n);
  747. %catches(swig::stop_iteration) ConstIterator::operator += (ptrdiff_t n);
  748. %catches(swig::stop_iteration) ConstIterator::operator -= (ptrdiff_t n);
  749. %catches(swig::stop_iteration) ConstIterator::operator + (ptrdiff_t n) const;
  750. %catches(swig::stop_iteration) ConstIterator::operator - (ptrdiff_t n) const;
  751. struct ConstIterator
  752. {
  753. protected:
  754. ConstIterator(VALUE seq);
  755. public:
  756. virtual ~ConstIterator();
  757. // Access iterator method, required by Ruby
  758. virtual VALUE value() const;
  759. // C++ common/needed methods
  760. virtual ConstIterator *dup() const;
  761. virtual VALUE inspect() const;
  762. virtual VALUE to_s() const;
  763. virtual ConstIterator* next(size_t n = 1);
  764. virtual ConstIterator* previous(size_t n = 1);
  765. bool operator == (const ConstIterator& x) const;
  766. ConstIterator* operator + (ptrdiff_t n) const;
  767. ConstIterator* operator - (ptrdiff_t n) const;
  768. ptrdiff_t operator - (const ConstIterator& x) const;
  769. };
  770. struct Iterator : public ConstIterator
  771. {
  772. %rename("value=") setValue( const VALUE& v );
  773. virtual VALUE setValue( const VALUE& v );
  774. virtual Iterator *dup() const;
  775. virtual Iterator* next(size_t n = 1);
  776. virtual Iterator* previous(size_t n = 1);
  777. virtual VALUE inspect() const;
  778. virtual VALUE to_s() const;
  779. bool operator == (const Iterator& x) const;
  780. Iterator* operator + (ptrdiff_t n) const;
  781. Iterator* operator - (ptrdiff_t n) const;
  782. ptrdiff_t operator - (const Iterator& x) const;
  783. };
  784. }