#ifndef __X10_UTIL_ARRAYBUILDER_H
#define __X10_UTIL_ARRAYBUILDER_H

#include <x10rt.h>


#define X10_LANG_OBJECT_H_NODEPS
#include <x10/lang/Object.h>
#undef X10_LANG_OBJECT_H_NODEPS
#define X10_UTIL_BUILDER_H_NODEPS
#include <x10/util/Builder.h>
#undef X10_UTIL_BUILDER_H_NODEPS
namespace x10 { namespace array { 
template<class TPMGL(T)> class Array;
} } 
namespace x10 { namespace util { 
template<class TPMGL(T)> class GrowableIndexedMemoryChunk;
} } 
namespace x10 { namespace lang { 
class Int;
} } 
namespace x10 { namespace util { 

template<class TPMGL(T)> class ArrayBuilder;
template <> class ArrayBuilder<void>;
template<class TPMGL(T)> class ArrayBuilder : public x10::lang::Object   {
    public:
    RTT_H_DECLS_CLASS
    
    static x10aux::itable_entry _itables[3];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    static typename x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > >::template itable<x10::util::ArrayBuilder<TPMGL(T)> > _itable_0;
    
    static x10::lang::Any::itable<x10::util::ArrayBuilder<TPMGL(T)> > _itable_1;
    
    x10aux::ref<x10::util::GrowableIndexedMemoryChunk<TPMGL(T)> > FMGL(buf);
    
    void _constructor();
    
    static x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > _make();
    
    void _constructor(x10_int size);
    
    static x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > _make(x10_int size);
    
    virtual x10aux::ref<x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > > >
      add(TPMGL(T) x);
    virtual x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > insert(
      x10_int loc, x10aux::ref<x10::array::Array<TPMGL(T)> > items);
    virtual x10_int length();
    virtual x10aux::ref<x10::array::Array<TPMGL(T)> > result();
    virtual x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > x10__util__ArrayBuilder____x10__util__ArrayBuilder__this(
      );
    
    // 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 ArrayBuilder<void> : public x10::lang::Object
{
    public:
    static x10aux::RuntimeType rtt;
    static const x10aux::RuntimeType* getRTT() { return & rtt; }
    
};

} } 
#endif // X10_UTIL_ARRAYBUILDER_H

namespace x10 { namespace util { 
template<class TPMGL(T)> class ArrayBuilder;
} } 

#ifndef X10_UTIL_ARRAYBUILDER_H_NODEPS
#define X10_UTIL_ARRAYBUILDER_H_NODEPS
#include <x10/lang/Object.h>
#include <x10/util/Builder.h>
#include <x10/array/Array.h>
#include <x10/util/GrowableIndexedMemoryChunk.h>
#include <x10/lang/Int.h>
#ifndef X10_UTIL_ARRAYBUILDER_H_GENERICS
#define X10_UTIL_ARRAYBUILDER_H_GENERICS
#endif // X10_UTIL_ARRAYBUILDER_H_GENERICS
#ifndef X10_UTIL_ARRAYBUILDER_H_IMPLEMENTATION
#define X10_UTIL_ARRAYBUILDER_H_IMPLEMENTATION
#include <x10/util/ArrayBuilder.h>

template<class TPMGL(T)> typename x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > >::template itable<x10::util::ArrayBuilder<TPMGL(T)> >  x10::util::ArrayBuilder<TPMGL(T)>::_itable_0(&x10::util::ArrayBuilder<TPMGL(T)>::add, &x10::util::ArrayBuilder<TPMGL(T)>::equals, &x10::util::ArrayBuilder<TPMGL(T)>::hashCode, &x10::util::ArrayBuilder<TPMGL(T)>::result, &x10::util::ArrayBuilder<TPMGL(T)>::toString, &x10::util::ArrayBuilder<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10::lang::Any::itable<x10::util::ArrayBuilder<TPMGL(T)> >  x10::util::ArrayBuilder<TPMGL(T)>::_itable_1(&x10::util::ArrayBuilder<TPMGL(T)>::equals, &x10::util::ArrayBuilder<TPMGL(T)>::hashCode, &x10::util::ArrayBuilder<TPMGL(T)>::toString, &x10::util::ArrayBuilder<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10::util::ArrayBuilder<TPMGL(T)>::_itables[3] = {x10aux::itable_entry(&x10aux::getRTT<x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > > >, &_itable_0), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Any>, &_itable_1), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<x10::util::ArrayBuilder<TPMGL(T)> >())};

//#line 15 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10FieldDecl_c

//#line 17 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::util::ArrayBuilder<TPMGL(T)>::_constructor(
                           ) {
    
    //#line 17 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::lang::Object::_constructor();
    
    //#line 17 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.AssignPropertyCall_c
    
    //#line 18 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->FMGL(buf) = x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::_make();
}
template<class TPMGL(T)> x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > x10::util::ArrayBuilder<TPMGL(T)>::_make(
                           ) {
    x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::ArrayBuilder<TPMGL(T)> >(), 0, sizeof(x10::util::ArrayBuilder<TPMGL(T)>))) x10::util::ArrayBuilder<TPMGL(T)>();
    this_->_constructor();
    return this_;
}



//#line 21 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::util::ArrayBuilder<TPMGL(T)>::_constructor(
                           x10_int size) {
    
    //#line 21 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::lang::Object::_constructor();
    
    //#line 21 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.AssignPropertyCall_c
    
    //#line 22 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->FMGL(buf) =
      x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::_make(size);
}
template<class TPMGL(T)> x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > x10::util::ArrayBuilder<TPMGL(T)>::_make(
                           x10_int size) {
    x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::ArrayBuilder<TPMGL(T)> >(), 0, sizeof(x10::util::ArrayBuilder<TPMGL(T)>))) x10::util::ArrayBuilder<TPMGL(T)>();
    this_->_constructor(size);
    return this_;
}



//#line 25 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > > >
  x10::util::ArrayBuilder<TPMGL(T)>::add(TPMGL(T) x) {
    
    //#line 26 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": Eval of x10.ast.X10Call_c
    x10aux::nullCheck(((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->
                        FMGL(buf))->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::add(
      x);
    
    //#line 27 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10Return_c
    return x10aux::class_cast_unchecked<x10aux::ref<x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > > > >(((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this));
    
}

//#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >
  x10::util::ArrayBuilder<TPMGL(T)>::insert(x10_int loc, x10aux::ref<x10::array::Array<TPMGL(T)> > items) {
    
    //#line 31 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": Eval of x10.ast.X10Call_c
    x10aux::nullCheck(((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->
                        FMGL(buf))->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::insert(
      loc, x10aux::nullCheck(items)->x10::array::Array<TPMGL(T)>::raw());
    
    //#line 32 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this);
    
}

//#line 35 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10_int x10::util::ArrayBuilder<TPMGL(T)>::length(
  ) {
    
    //#line 36 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10Return_c
    return x10aux::nullCheck(((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->
                               FMGL(buf))->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::length();
    
}

//#line 39 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::array::Array<TPMGL(T)> >
  x10::util::ArrayBuilder<TPMGL(T)>::result() {
    
    //#line 40 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10Return_c
    return x10aux::nullCheck(((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this)->
                               FMGL(buf))->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::toArray();
    
}

//#line 14 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >
  x10::util::ArrayBuilder<TPMGL(T)>::x10__util__ArrayBuilder____x10__util__ArrayBuilder__this(
  ) {
    
    //#line 14 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/ArrayBuilder.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::ArrayBuilder<TPMGL(T)> >)this);
    
}
template<class TPMGL(T)> const x10aux::serialization_id_t x10::util::ArrayBuilder<TPMGL(T)>::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10::util::ArrayBuilder<TPMGL(T)>::_deserializer, x10aux::CLOSURE_KIND_NOT_ASYNC);

template<class TPMGL(T)> void x10::util::ArrayBuilder<TPMGL(T)>::_serialize_body(x10aux::serialization_buffer& buf) {
    x10::lang::Object::_serialize_body(buf);
    buf.write(this->FMGL(buf));
    
}

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

template<class TPMGL(T)> void x10::util::ArrayBuilder<TPMGL(T)>::_deserialize_body(x10aux::deserialization_buffer& buf) {
    x10::lang::Object::_deserialize_body(buf);
    FMGL(buf) = buf.read<x10aux::ref<x10::util::GrowableIndexedMemoryChunk<TPMGL(T)> > >();
}

template<class TPMGL(T)> x10aux::RuntimeType x10::util::ArrayBuilder<TPMGL(T)>::rtt;
template<class TPMGL(T)> void x10::util::ArrayBuilder<TPMGL(T)>::_initRTT() {
    const x10aux::RuntimeType *canonical = x10aux::getRTT<x10::util::ArrayBuilder<void> >();
    if (rtt.initStageOne(canonical)) return;
    const x10aux::RuntimeType* parents[2] = { x10aux::getRTT<x10::lang::Object>(), x10aux::getRTT<x10::util::Builder<TPMGL(T), x10aux::ref<x10::array::Array<TPMGL(T)> > > >()};
    const x10aux::RuntimeType* params[1] = { x10aux::getRTT<TPMGL(T)>()};
    x10aux::RuntimeType::Variance variances[1] = { x10aux::RuntimeType::invariant};
    const char *baseName = "x10.util.ArrayBuilder";
    rtt.initStageTwo(baseName, x10aux::RuntimeType::class_kind, 2, parents, 1, params, variances);
}
#endif // X10_UTIL_ARRAYBUILDER_H_IMPLEMENTATION
#endif // __X10_UTIL_ARRAYBUILDER_H_NODEPS
