#ifndef __X10_IO_READERITERATOR_H
#define __X10_IO_READERITERATOR_H

#include <x10rt.h>


#define X10_LANG_OBJECT_H_NODEPS
#include <x10/lang/Object.h>
#undef X10_LANG_OBJECT_H_NODEPS
#define X10_LANG_ITERATOR_H_NODEPS
#include <x10/lang/Iterator.h>
#undef X10_LANG_ITERATOR_H_NODEPS
#define X10_LANG_ITERABLE_H_NODEPS
#include <x10/lang/Iterable.h>
#undef X10_LANG_ITERABLE_H_NODEPS
namespace x10 { namespace io { 
class Reader;
} } 
namespace x10 { namespace io { 
template<class TPMGL(T)> class Marshal;
} } 
namespace x10 { namespace util { 
template<class TPMGL(T)> class Box;
} } 
namespace x10 { namespace lang { 
class Boolean;
} } 
namespace x10 { namespace util { 
class NoSuchElementException;
} } 
namespace x10 { namespace io { 
class IOException;
} } 
namespace x10 { namespace io { 

template<class TPMGL(T)> class ReaderIterator;
template <> class ReaderIterator<void>;
template<class TPMGL(T)> class ReaderIterator : public x10::lang::Object 
 {
    public:
    RTT_H_DECLS_CLASS
    
    static x10aux::itable_entry _itables[4];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    static typename x10::lang::Iterator<TPMGL(T)>::template itable<x10::io::ReaderIterator<TPMGL(T)> > _itable_0;
    
    static x10::lang::Any::itable<x10::io::ReaderIterator<TPMGL(T)> > _itable_1;
    
    static typename x10::lang::Iterable<TPMGL(T)>::template itable<x10::io::ReaderIterator<TPMGL(T)> > _itable_2;
    
    x10aux::ref<x10::io::Reader> FMGL(r);
    
    x10aux::ref<x10::io::Marshal<TPMGL(T)> > FMGL(m);
    
    x10aux::ref<x10::util::Box<TPMGL(T)> > FMGL(next);
    
    void _constructor(x10aux::ref<x10::io::Marshal<TPMGL(T)> > m, x10aux::ref<x10::io::Reader> r);
    
    static x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> > _make(x10aux::ref<x10::io::Marshal<TPMGL(T)> > m,
                                                                 x10aux::ref<x10::io::Reader> r);
    
    virtual x10aux::ref<x10::lang::Iterator<TPMGL(T)> > iterator(
      );
    virtual TPMGL(T) next();
    virtual x10_boolean hasNext();
    virtual x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> > x10__io__ReaderIterator____x10__io__ReaderIterator__this(
      );
    void __fieldInitializers42343();
    
    // Serialization
    public: static const x10aux::serialization_id_t _serialization_id;
    
    public: virtual x10aux::serialization_id_t _get_serialization_id() {
         return _serialization_id;
    }
    
    public: virtual void _serialize_body(x10aux::serialization_buffer& buf);
    
    public: static x10aux::ref<x10::lang::Reference> _deserializer(x10aux::deserialization_buffer& buf);
    
    public: void _deserialize_body(x10aux::deserialization_buffer& buf);
    
};
template <> class ReaderIterator<void> : public x10::lang::Object
{
    public:
    static x10aux::RuntimeType rtt;
    static const x10aux::RuntimeType* getRTT() { return & rtt; }
    
};

} } 
#endif // X10_IO_READERITERATOR_H

namespace x10 { namespace io { 
template<class TPMGL(T)> class ReaderIterator;
} } 

#ifndef X10_IO_READERITERATOR_H_NODEPS
#define X10_IO_READERITERATOR_H_NODEPS
#include <x10/lang/Object.h>
#include <x10/lang/Iterator.h>
#include <x10/lang/Iterable.h>
#include <x10/io/Reader.h>
#include <x10/io/Marshal.h>
#include <x10/util/Box.h>
#include <x10/lang/Boolean.h>
#include <x10/util/NoSuchElementException.h>
#include <x10/io/IOException.h>
#ifndef X10_IO_READERITERATOR_H_GENERICS
#define X10_IO_READERITERATOR_H_GENERICS
#endif // X10_IO_READERITERATOR_H_GENERICS
#ifndef X10_IO_READERITERATOR_H_IMPLEMENTATION
#define X10_IO_READERITERATOR_H_IMPLEMENTATION
#include <x10/io/ReaderIterator.h>

template<class TPMGL(T)> typename x10::lang::Iterator<TPMGL(T)>::template itable<x10::io::ReaderIterator<TPMGL(T)> >  x10::io::ReaderIterator<TPMGL(T)>::_itable_0(&x10::io::ReaderIterator<TPMGL(T)>::equals, &x10::io::ReaderIterator<TPMGL(T)>::hasNext, &x10::io::ReaderIterator<TPMGL(T)>::hashCode, &x10::io::ReaderIterator<TPMGL(T)>::next, &x10::io::ReaderIterator<TPMGL(T)>::toString, &x10::io::ReaderIterator<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10::lang::Any::itable<x10::io::ReaderIterator<TPMGL(T)> >  x10::io::ReaderIterator<TPMGL(T)>::_itable_1(&x10::io::ReaderIterator<TPMGL(T)>::equals, &x10::io::ReaderIterator<TPMGL(T)>::hashCode, &x10::io::ReaderIterator<TPMGL(T)>::toString, &x10::io::ReaderIterator<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::lang::Iterable<TPMGL(T)>::template itable<x10::io::ReaderIterator<TPMGL(T)> >  x10::io::ReaderIterator<TPMGL(T)>::_itable_2(&x10::io::ReaderIterator<TPMGL(T)>::equals, &x10::io::ReaderIterator<TPMGL(T)>::hashCode, &x10::io::ReaderIterator<TPMGL(T)>::iterator, &x10::io::ReaderIterator<TPMGL(T)>::toString, &x10::io::ReaderIterator<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10::io::ReaderIterator<TPMGL(T)>::_itables[4] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Iterator<TPMGL(T)> >, &_itable_0), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Any>, &_itable_1), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Iterable<TPMGL(T)> >, &_itable_2), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<x10::io::ReaderIterator<TPMGL(T)> >())};

//#line 31 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10FieldDecl_c

//#line 32 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10FieldDecl_c

//#line 33 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10FieldDecl_c

//#line 35 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::io::ReaderIterator<TPMGL(T)>::_constructor(
                           x10aux::ref<x10::io::Marshal<TPMGL(T)> > m, x10aux::ref<x10::io::Reader> r) {
    
    //#line 35 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::lang::Object::_constructor();
    
    //#line 35 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.AssignPropertyCall_c
    
    //#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10Call_c
    ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->x10::io::ReaderIterator<TPMGL(T)>::__fieldInitializers42343();
    
    //#line 36 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->FMGL(m) = m;
    
    //#line 37 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->FMGL(r) = r;
}
template<class TPMGL(T)> x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> > x10::io::ReaderIterator<TPMGL(T)>::_make(
                           x10aux::ref<x10::io::Marshal<TPMGL(T)> > m,
                           x10aux::ref<x10::io::Reader> r) {
    x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::io::ReaderIterator<TPMGL(T)> >(), 0, sizeof(x10::io::ReaderIterator<TPMGL(T)>))) x10::io::ReaderIterator<TPMGL(T)>();
    this_->_constructor(m, r);
    return this_;
}



//#line 42 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::lang::Iterator<TPMGL(T)> >
  x10::io::ReaderIterator<TPMGL(T)>::iterator() {
    
    //#line 42 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this);
    
}

//#line 44 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::io::ReaderIterator<TPMGL(T)>::next(
  ) {
    
    //#line 45 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10If_c
    if (!(((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->hasNext()))
    {
        
        //#line 46 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": polyglot.ast.Throw_c
        x10aux::throwException(x10aux::nullCheck(x10::util::NoSuchElementException::_make()));
    }
    
    //#line 47 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10LocalDecl_c
    TPMGL(T) x = x10aux::nullCheck(((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
                                     FMGL(next))->FMGL(value);
    
    //#line 48 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
      FMGL(next) = X10_NULL;
    
    //#line 49 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10Return_c
    return x;
    
}

//#line 52 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10_boolean x10::io::ReaderIterator<TPMGL(T)>::hasNext(
  ) {
    
    //#line 53 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10If_c
    if ((x10aux::struct_equals(((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
                                 FMGL(next), X10_NULL))) {
        
        //#line 54 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": polyglot.ast.Try_c
        try {
            
            //#line 55 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10LocalDecl_c
            TPMGL(T) x = x10aux::nullCheck(((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
                                             FMGL(r))->template read<TPMGL(T) >(
                           ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
                             FMGL(m));
            
            //#line 56 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10FieldAssign_c
            ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
              FMGL(next) = x10::util::Box<TPMGL(T)>::_make(x);
        }
        catch (x10aux::__ref& __ref__968) {
            x10aux::ref<x10::lang::Throwable>& __exc__ref__968 = (x10aux::ref<x10::lang::Throwable>&)__ref__968;
            if (x10aux::instanceof<x10aux::ref<x10::io::IOException> >(__exc__ref__968)) {
                x10aux::ref<x10::io::IOException> id__117 =
                  static_cast<x10aux::ref<x10::io::IOException> >(__exc__ref__968);
                {
                    
                    //#line 59 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10Return_c
                    return false;
                    
                }
            } else
            throw;
        }
    }
    
    //#line 62 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10Return_c
    return true;
    
}

//#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >
  x10::io::ReaderIterator<TPMGL(T)>::x10__io__ReaderIterator____x10__io__ReaderIterator__this(
  ) {
    
    //#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this);
    
}

//#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> void x10::io::ReaderIterator<TPMGL(T)>::__fieldInitializers42343(
  ) {
    
    //#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/io/ReaderIterator.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> >)this)->
      FMGL(next) = X10_NULL;
}
template<class TPMGL(T)> const x10aux::serialization_id_t x10::io::ReaderIterator<TPMGL(T)>::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10::io::ReaderIterator<TPMGL(T)>::_deserializer, x10aux::CLOSURE_KIND_NOT_ASYNC);

template<class TPMGL(T)> void x10::io::ReaderIterator<TPMGL(T)>::_serialize_body(x10aux::serialization_buffer& buf) {
    x10::lang::Object::_serialize_body(buf);
    buf.write(this->FMGL(r));
    buf.write(this->FMGL(m));
    buf.write(this->FMGL(next));
    
}

template<class TPMGL(T)> x10aux::ref<x10::lang::Reference> x10::io::ReaderIterator<TPMGL(T)>::_deserializer(x10aux::deserialization_buffer& buf) {
    x10aux::ref<x10::io::ReaderIterator<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::io::ReaderIterator<TPMGL(T)> >(), 0, sizeof(x10::io::ReaderIterator<TPMGL(T)>))) x10::io::ReaderIterator<TPMGL(T)>();
    buf.record_reference(this_);
    this_->_deserialize_body(buf);
    return this_;
}

template<class TPMGL(T)> void x10::io::ReaderIterator<TPMGL(T)>::_deserialize_body(x10aux::deserialization_buffer& buf) {
    x10::lang::Object::_deserialize_body(buf);
    FMGL(r) = buf.read<x10aux::ref<x10::io::Reader> >();
    FMGL(m) = buf.read<x10aux::ref<x10::io::Marshal<TPMGL(T)> > >();
    FMGL(next) = buf.read<x10aux::ref<x10::util::Box<TPMGL(T)> > >();
}

template<class TPMGL(T)> x10aux::RuntimeType x10::io::ReaderIterator<TPMGL(T)>::rtt;
template<class TPMGL(T)> void x10::io::ReaderIterator<TPMGL(T)>::_initRTT() {
    const x10aux::RuntimeType *canonical = x10aux::getRTT<x10::io::ReaderIterator<void> >();
    if (rtt.initStageOne(canonical)) return;
    const x10aux::RuntimeType* parents[3] = { x10aux::getRTT<x10::lang::Object>(), x10aux::getRTT<x10::lang::Iterator<TPMGL(T)> >(), x10aux::getRTT<x10::lang::Iterable<TPMGL(T)> >()};
    const x10aux::RuntimeType* params[1] = { x10aux::getRTT<TPMGL(T)>()};
    x10aux::RuntimeType::Variance variances[1] = { x10aux::RuntimeType::invariant};
    const char *baseName = "x10.io.ReaderIterator";
    rtt.initStageTwo(baseName, x10aux::RuntimeType::class_kind, 3, parents, 1, params, variances);
}
#endif // X10_IO_READERITERATOR_H_IMPLEMENTATION
#endif // __X10_IO_READERITERATOR_H_NODEPS
