#ifndef __X10_UTIL_WORKERLOCALHANDLE_H
#define __X10_UTIL_WORKERLOCALHANDLE_H

#include <x10rt.h>


#define X10_LANG_OBJECT_H_NODEPS
#include <x10/lang/Object.h>
#undef X10_LANG_OBJECT_H_NODEPS
#define X10_LANG_FUN_0_0_H_NODEPS
#include <x10/lang/Fun_0_0.h>
#undef X10_LANG_FUN_0_0_H_NODEPS
#define X10_LANG_VOIDFUN_0_1_H_NODEPS
#include <x10/lang/VoidFun_0_1.h>
#undef X10_LANG_VOIDFUN_0_1_H_NODEPS
#define X10_LANG_PLACELOCALHANDLE_H_NODEPS
#include <x10/lang/PlaceLocalHandle.h>
#undef X10_LANG_PLACELOCALHANDLE_H_NODEPS
namespace x10 { namespace lang { 
template<class TPMGL(T)> class PlaceLocalHandle;
} } 
namespace x10 { namespace array { 
template<class TPMGL(T)> class Array;
} } 
namespace x10 { namespace array { 
class Dist;
} } 
namespace x10 { namespace lang { 
class Runtime;
} } 
namespace x10 { namespace util { 

template<class TPMGL(T)> class WorkerLocalHandle;
template <> class WorkerLocalHandle<void>;
template<class TPMGL(T)> class WorkerLocalHandle : 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::Fun_0_0<TPMGL(T)>::template itable<x10::util::WorkerLocalHandle<TPMGL(T)> > _itable_0;
    
    static x10::lang::Any::itable<x10::util::WorkerLocalHandle<TPMGL(T)> > _itable_1;
    
    static typename x10::lang::VoidFun_0_1<TPMGL(T)>::template itable<x10::util::WorkerLocalHandle<TPMGL(T)> > _itable_2;
    
    x10::lang::PlaceLocalHandle<x10aux::ref<x10::array::Array<TPMGL(T)> > >
      FMGL(store);
    
    void _constructor(TPMGL(T) t);
    
    static x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> > _make(TPMGL(T) t);
    
    virtual TPMGL(T) __apply();
    virtual void __apply(TPMGL(T) t);
    virtual x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> > x10__util__WorkerLocalHandle____x10__util__WorkerLocalHandle__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 WorkerLocalHandle<void> : public x10::lang::Object
{
    public:
    static x10aux::RuntimeType rtt;
    static const x10aux::RuntimeType* getRTT() { return & rtt; }
    
};

} } 
#endif // X10_UTIL_WORKERLOCALHANDLE_H

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

#ifndef X10_UTIL_WORKERLOCALHANDLE_H_NODEPS
#define X10_UTIL_WORKERLOCALHANDLE_H_NODEPS
#include <x10/lang/Object.h>
#include <x10/lang/Fun_0_0.h>
#include <x10/lang/VoidFun_0_1.h>
#include <x10/lang/PlaceLocalHandle.h>
#include <x10/array/Array.h>
#include <x10/array/Dist.h>
#include <x10/lang/Runtime.h>
#ifndef X10_UTIL_WORKERLOCALHANDLE_H_GENERICS
#define X10_UTIL_WORKERLOCALHANDLE_H_GENERICS
#endif // X10_UTIL_WORKERLOCALHANDLE_H_GENERICS
#ifndef X10_UTIL_WORKERLOCALHANDLE_H_IMPLEMENTATION
#define X10_UTIL_WORKERLOCALHANDLE_H_IMPLEMENTATION
#include <x10/util/WorkerLocalHandle.h>

#ifndef X10_UTIL_WORKERLOCALHANDLE__CLOSURE__1_CLOSURE
#define X10_UTIL_WORKERLOCALHANDLE__CLOSURE__1_CLOSURE
#include <x10/lang/Closure.h>
#include <x10/lang/Fun_0_0.h>
template<class TPMGL(T)> class x10_util_WorkerLocalHandle__closure__1 : public x10::lang::Closure {
    public:
    
    static typename x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > >::template itable <x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > > _itable;
    static x10aux::itable_entry _itables[2];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    // closure body
    x10aux::ref<x10::array::Array<TPMGL(T)> > __apply() {
        
        //#line 23 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10Return_c
        return x10::array::Array<TPMGL(T)>::_make(x10::lang::Runtime::FMGL(MAX_THREADS),
                                                  t);
        
    }
    
    // captured environment
    TPMGL(T) t;
    
    x10aux::serialization_id_t _get_serialization_id() {
        return _serialization_id;
    }
    
    void _serialize_body(x10aux::serialization_buffer &buf) {
        buf.write(this->t);
    }
    
    template<class __T> static x10aux::ref<__T> _deserialize(x10aux::deserialization_buffer &buf) {
        x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >* storage = x10aux::alloc<x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > >();
        buf.record_reference(x10aux::ref<x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > >(storage));
        TPMGL(T) that_t = buf.read<TPMGL(T)>();
        x10aux::ref<x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > > this_ = new (storage) x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >(that_t);
        return this_;
    }
    
    x10_util_WorkerLocalHandle__closure__1(TPMGL(T) t) : t(t) { }
    
    static const x10aux::serialization_id_t _serialization_id;
    
    static const x10aux::RuntimeType* getRTT() { return x10aux::getRTT<x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > > >(); }
    virtual const x10aux::RuntimeType *_type() const { return x10aux::getRTT<x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > > >(); }
    
    x10aux::ref<x10::lang::String> toString() {
        return x10aux::string_utils::lit(this->toNativeString());
    }
    
    const char* toNativeString() {
        return "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10:23";
    }

};

template<class TPMGL(T)> typename x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > >::template itable <x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > >x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::_itable(&x10::lang::Reference::equals, &x10::lang::Closure::hashCode, &x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::__apply, &x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::toString, &x10::lang::Closure::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::_itables[2] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > > >, &x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::_itable),x10aux::itable_entry(NULL, NULL)};

template<class TPMGL(T)> const x10aux::serialization_id_t x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10_util_WorkerLocalHandle__closure__1<TPMGL(T) >::template _deserialize<x10::lang::Reference>,x10aux::CLOSURE_KIND_NOT_ASYNC);

#endif // X10_UTIL_WORKERLOCALHANDLE__CLOSURE__1_CLOSURE
template<class TPMGL(T)> typename x10::lang::Fun_0_0<TPMGL(T)>::template itable<x10::util::WorkerLocalHandle<TPMGL(T)> >  x10::util::WorkerLocalHandle<TPMGL(T)>::_itable_0(&x10::util::WorkerLocalHandle<TPMGL(T)>::equals, &x10::util::WorkerLocalHandle<TPMGL(T)>::hashCode, &x10::util::WorkerLocalHandle<TPMGL(T)>::__apply, &x10::util::WorkerLocalHandle<TPMGL(T)>::toString, &x10::util::WorkerLocalHandle<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10::lang::Any::itable<x10::util::WorkerLocalHandle<TPMGL(T)> >  x10::util::WorkerLocalHandle<TPMGL(T)>::_itable_1(&x10::util::WorkerLocalHandle<TPMGL(T)>::equals, &x10::util::WorkerLocalHandle<TPMGL(T)>::hashCode, &x10::util::WorkerLocalHandle<TPMGL(T)>::toString, &x10::util::WorkerLocalHandle<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::lang::VoidFun_0_1<TPMGL(T)>::template itable<x10::util::WorkerLocalHandle<TPMGL(T)> >  x10::util::WorkerLocalHandle<TPMGL(T)>::_itable_2(&x10::util::WorkerLocalHandle<TPMGL(T)>::equals, &x10::util::WorkerLocalHandle<TPMGL(T)>::hashCode, &x10::util::WorkerLocalHandle<TPMGL(T)>::__apply, &x10::util::WorkerLocalHandle<TPMGL(T)>::toString, &x10::util::WorkerLocalHandle<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10::util::WorkerLocalHandle<TPMGL(T)>::_itables[4] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >, &_itable_0), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Any>, &_itable_1), x10aux::itable_entry(&x10aux::getRTT<x10::lang::VoidFun_0_1<TPMGL(T)> >, &_itable_2), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<x10::util::WorkerLocalHandle<TPMGL(T)> >())};

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

//#line 22 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::util::WorkerLocalHandle<TPMGL(T)>::_constructor(
                           TPMGL(T) t) {
    
    //#line 22 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::lang::Object::_constructor();
    
    //#line 22 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.AssignPropertyCall_c
    
    //#line 23 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> >)this)->
      FMGL(store) = x10::lang::PlaceLocalHandle<void>::template make<x10aux::ref<x10::array::Array<TPMGL(T)> > >(
                      x10::array::Dist::makeUnique(), x10aux::ref<x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > > >(x10aux::ref<x10_util_WorkerLocalHandle__closure__1<TPMGL(T) > >(new (x10aux::alloc<x10::lang::Fun_0_0<x10aux::ref<x10::array::Array<TPMGL(T)> > > >(sizeof(x10_util_WorkerLocalHandle__closure__1<TPMGL(T)>)))x10_util_WorkerLocalHandle__closure__1<TPMGL(T)>(t))));
}
template<class TPMGL(T)> x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> > x10::util::WorkerLocalHandle<TPMGL(T)>::_make(
                           TPMGL(T) t) {
    x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::WorkerLocalHandle<TPMGL(T)> >(), 0, sizeof(x10::util::WorkerLocalHandle<TPMGL(T)>))) x10::util::WorkerLocalHandle<TPMGL(T)>();
    this_->_constructor(t);
    return this_;
}



//#line 26 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::WorkerLocalHandle<TPMGL(T)>::__apply(
  ) {
    
    //#line 27 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10Return_c
    return x10aux::nullCheck(((x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> >)this)->
                               FMGL(store)->x10::lang::PlaceLocalHandle<x10aux::ref<x10::array::Array<TPMGL(T)> > >::__apply())->x10::array::Array<TPMGL(T)>::__apply(
             x10::lang::Runtime::workerId());
    
}

//#line 30 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> void x10::util::WorkerLocalHandle<TPMGL(T)>::__apply(
  TPMGL(T) t) {
    
    //#line 31 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/WorkerLocalHandle.x10": Eval of x10.ast.X10Call_c
    x10aux::nullCheck(((x10aux::ref<x10::util::WorkerLocalHandle<TPMGL(T)> >)this)->
                        FMGL(store)->x10::lang::PlaceLocalHandle<x10aux::ref<x10::array::Array<TPMGL(T)> > >::__apply())->x10::array::Array<TPMGL(T)>::__set(
      x10::lang::Runtime::workerId(), t);
}

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

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

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

template<class TPMGL(T)> void x10::util::WorkerLocalHandle<TPMGL(T)>::_deserialize_body(x10aux::deserialization_buffer& buf) {
    x10::lang::Object::_deserialize_body(buf);
    FMGL(store) = buf.read<x10::lang::PlaceLocalHandle<x10aux::ref<x10::array::Array<TPMGL(T)> > > >();
}

template<class TPMGL(T)> x10aux::RuntimeType x10::util::WorkerLocalHandle<TPMGL(T)>::rtt;
template<class TPMGL(T)> void x10::util::WorkerLocalHandle<TPMGL(T)>::_initRTT() {
    const x10aux::RuntimeType *canonical = x10aux::getRTT<x10::util::WorkerLocalHandle<void> >();
    if (rtt.initStageOne(canonical)) return;
    const x10aux::RuntimeType* parents[3] = { x10aux::getRTT<x10::lang::Object>(), x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >(), x10aux::getRTT<x10::lang::VoidFun_0_1<TPMGL(T)> >()};
    const x10aux::RuntimeType* params[1] = { x10aux::getRTT<TPMGL(T)>()};
    x10aux::RuntimeType::Variance variances[1] = { x10aux::RuntimeType::invariant};
    const char *baseName = "x10.util.WorkerLocalHandle";
    rtt.initStageTwo(baseName, x10aux::RuntimeType::class_kind, 3, parents, 1, params, variances);
}
#endif // X10_UTIL_WORKERLOCALHANDLE_H_IMPLEMENTATION
#endif // __X10_UTIL_WORKERLOCALHANDLE_H_NODEPS
