#ifndef __X10_UTIL_STACK_H
#define __X10_UTIL_STACK_H

#include <x10rt.h>


#define X10_UTIL_ARRAYLIST_H_NODEPS
#include <x10/util/ArrayList.h>
#undef X10_UTIL_ARRAYLIST_H_NODEPS
namespace x10 { namespace lang { 
class Boolean;
} } 
namespace x10 { namespace lang { 
class Int;
} } 
namespace x10 { namespace array { 
template<class TPMGL(T)> class Array;
} } 
namespace x10 { namespace util { 

template<class TPMGL(T)> class Stack;
template <> class Stack<void>;
template<class TPMGL(T)> class Stack : public x10::util::ArrayList<TPMGL(T)>
  {
    public:
    RTT_H_DECLS_CLASS
    
    static x10aux::itable_entry _itables[8];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    static typename x10::util::Container<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_0;
    
    static x10::lang::Any::itable<x10::util::Stack<TPMGL(T)> > _itable_1;
    
    static typename x10::lang::Iterable<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_2;
    
    static typename x10::util::Collection<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_3;
    
    static typename x10::util::List<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_4;
    
    static typename x10::util::Indexed<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_5;
    
    static typename x10::lang::Settable<x10_int, TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> > _itable_6;
    
    void _constructor();
    
    static x10aux::ref<x10::util::Stack<TPMGL(T)> > _make();
    
    virtual x10_boolean push(TPMGL(T) v);
    virtual TPMGL(T) pop();
    virtual x10aux::ref<x10::array::Array<TPMGL(T)> > pop(x10_int k);
    virtual TPMGL(T) peek();
    virtual x10_int search(TPMGL(T) v);
    virtual x10aux::ref<x10::util::Stack<TPMGL(T)> > x10__util__Stack____x10__util__Stack__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 Stack<void> : public x10::util::ArrayList<void>
{
    public:
    static x10aux::RuntimeType rtt;
    static const x10aux::RuntimeType* getRTT() { return & rtt; }
    
};

} } 
#endif // X10_UTIL_STACK_H

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

#ifndef X10_UTIL_STACK_H_NODEPS
#define X10_UTIL_STACK_H_NODEPS
#include <x10/util/ArrayList.h>
#include <x10/lang/Boolean.h>
#include <x10/lang/Int.h>
#include <x10/array/Array.h>
#ifndef X10_UTIL_STACK_H_GENERICS
#define X10_UTIL_STACK_H_GENERICS
#endif // X10_UTIL_STACK_H_GENERICS
#ifndef X10_UTIL_STACK_H_IMPLEMENTATION
#define X10_UTIL_STACK_H_IMPLEMENTATION
#include <x10/util/Stack.h>

template<class TPMGL(T)> typename x10::util::Container<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_0(&x10::util::Stack<TPMGL(T)>::clone, &x10::util::Stack<TPMGL(T)>::contains, &x10::util::Stack<TPMGL(T)>::containsAll, &x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::isEmpty, &x10::util::Stack<TPMGL(T)>::iterator, &x10::util::Stack<TPMGL(T)>::size, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10::lang::Any::itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_1(&x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::lang::Iterable<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_2(&x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::iterator, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::util::Collection<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_3(&x10::util::Stack<TPMGL(T)>::add, &x10::util::Stack<TPMGL(T)>::addAll, &x10::util::Stack<TPMGL(T)>::addAllWhere, &x10::util::Stack<TPMGL(T)>::clear, &x10::util::Stack<TPMGL(T)>::clone, &x10::util::Stack<TPMGL(T)>::contains, &x10::util::Stack<TPMGL(T)>::containsAll, &x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::isEmpty, &x10::util::Stack<TPMGL(T)>::iterator, &x10::util::Stack<TPMGL(T)>::remove, &x10::util::Stack<TPMGL(T)>::removeAll, &x10::util::Stack<TPMGL(T)>::removeAllWhere, &x10::util::Stack<TPMGL(T)>::retainAll, &x10::util::Stack<TPMGL(T)>::size, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::util::List<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_4(&x10::util::Stack<TPMGL(T)>::add, &x10::util::Stack<TPMGL(T)>::addAll, &x10::util::Stack<TPMGL(T)>::addAllWhere, &x10::util::Stack<TPMGL(T)>::addBefore, &x10::util::Stack<TPMGL(T)>::clear, &x10::util::Stack<TPMGL(T)>::clone, &x10::util::Stack<TPMGL(T)>::contains, &x10::util::Stack<TPMGL(T)>::containsAll, &x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::getFirst, &x10::util::Stack<TPMGL(T)>::getLast, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::indexOf, &x10::util::Stack<TPMGL(T)>::indexOf, &x10::util::Stack<TPMGL(T)>::indices, &x10::util::Stack<TPMGL(T)>::isEmpty, &x10::util::Stack<TPMGL(T)>::iterator, &x10::util::Stack<TPMGL(T)>::iteratorFrom, &x10::util::Stack<TPMGL(T)>::lastIndexOf, &x10::util::Stack<TPMGL(T)>::lastIndexOf, &x10::util::Stack<TPMGL(T)>::__apply, &x10::util::Stack<TPMGL(T)>::__set, &x10::util::Stack<TPMGL(T)>::remove, &x10::util::Stack<TPMGL(T)>::removeAll, &x10::util::Stack<TPMGL(T)>::removeAllWhere, &x10::util::Stack<TPMGL(T)>::removeAt, &x10::util::Stack<TPMGL(T)>::removeFirst, &x10::util::Stack<TPMGL(T)>::removeLast, &x10::util::Stack<TPMGL(T)>::retainAll, &x10::util::Stack<TPMGL(T)>::reverse, &x10::util::Stack<TPMGL(T)>::size, &x10::util::Stack<TPMGL(T)>::sort, &x10::util::Stack<TPMGL(T)>::sort, &x10::util::Stack<TPMGL(T)>::subList, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::util::Indexed<TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_5(&x10::util::Stack<TPMGL(T)>::clone, &x10::util::Stack<TPMGL(T)>::contains, &x10::util::Stack<TPMGL(T)>::containsAll, &x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::isEmpty, &x10::util::Stack<TPMGL(T)>::iterator, &x10::util::Stack<TPMGL(T)>::__apply, &x10::util::Stack<TPMGL(T)>::size, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> typename x10::lang::Settable<x10_int, TPMGL(T)>::template itable<x10::util::Stack<TPMGL(T)> >  x10::util::Stack<TPMGL(T)>::_itable_6(&x10::util::Stack<TPMGL(T)>::equals, &x10::util::Stack<TPMGL(T)>::hashCode, &x10::util::Stack<TPMGL(T)>::__set, &x10::util::Stack<TPMGL(T)>::toString, &x10::util::Stack<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10::util::Stack<TPMGL(T)>::_itables[8] = {x10aux::itable_entry(&x10aux::getRTT<x10::util::Container<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(&x10aux::getRTT<x10::util::Collection<TPMGL(T)> >, &_itable_3), x10aux::itable_entry(&x10aux::getRTT<x10::util::List<TPMGL(T)> >, &_itable_4), x10aux::itable_entry(&x10aux::getRTT<x10::util::Indexed<TPMGL(T)> >, &_itable_5), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Settable<x10_int, TPMGL(T)> >, &_itable_6), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<x10::util::Stack<TPMGL(T)> >())};

//#line 15 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::util::Stack<TPMGL(T)>::_constructor() {
    
    //#line 15 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::util::ArrayList<TPMGL(T)>::_constructor();
    
    //#line 15 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.AssignPropertyCall_c
    
}
template<class TPMGL(T)> x10aux::ref<x10::util::Stack<TPMGL(T)> > x10::util::Stack<TPMGL(T)>::_make(
                           ) {
    x10aux::ref<x10::util::Stack<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::Stack<TPMGL(T)> >(), 0, sizeof(x10::util::Stack<TPMGL(T)>))) x10::util::Stack<TPMGL(T)>();
    this_->_constructor();
    return this_;
}



//#line 18 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10_boolean x10::util::Stack<TPMGL(T)>::push(
  TPMGL(T) v) {
    
    //#line 18 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->add(
             v);
    
}

//#line 21 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::Stack<TPMGL(T)>::pop(
  ) {
    
    //#line 21 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->removeLast();
    
}

//#line 23 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::array::Array<TPMGL(T)> >
  x10::util::Stack<TPMGL(T)>::pop(x10_int k) {
    
    //#line 24 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10LocalDecl_c
    x10_int n = ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->size();
    
    //#line 25 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10If_c
    if (((n) < (k))) {
        
        //#line 26 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
        return X10_NULL;
        
    }
    
    //#line 27 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->moveSectionToArray(
             ((x10_int) ((n) - (k))), ((x10_int) ((n) - (((x10_int)1)))));
    
}

//#line 31 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::Stack<TPMGL(T)>::peek(
  ) {
    
    //#line 31 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->getLast();
    
}

//#line 40 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10_int x10::util::Stack<TPMGL(T)>::search(
  TPMGL(T) v) {
    
    //#line 41 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10LocalDecl_c
    x10_int i = ((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->lastIndexOf(
                  v);
    
    //#line 42 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10If_c
    if (((i) >= (((x10_int)0)))) {
        
        //#line 43 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
        return ((x10_int) ((((x10aux::ref<x10::util::Stack<TPMGL(T)> >)this)->size()) - (i)));
        
    } else {
        
        //#line 45 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/Stack.x10": x10.ast.X10Return_c
        return ((x10_int)-1);
        
    }
    
}

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

template<class TPMGL(T)> void x10::util::Stack<TPMGL(T)>::_serialize_body(x10aux::serialization_buffer& buf) {
    x10::util::ArrayList<TPMGL(T)>::_serialize_body(buf);
    
}

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

template<class TPMGL(T)> void x10::util::Stack<TPMGL(T)>::_deserialize_body(x10aux::deserialization_buffer& buf) {
    x10::util::ArrayList<TPMGL(T)>::_deserialize_body(buf);
    
}

template<class TPMGL(T)> x10aux::RuntimeType x10::util::Stack<TPMGL(T)>::rtt;
template<class TPMGL(T)> void x10::util::Stack<TPMGL(T)>::_initRTT() {
    const x10aux::RuntimeType *canonical = x10aux::getRTT<x10::util::Stack<void> >();
    if (rtt.initStageOne(canonical)) return;
    const x10aux::RuntimeType* parents[1] = { x10aux::getRTT<x10::util::ArrayList<TPMGL(T)> >()};
    const x10aux::RuntimeType* params[1] = { x10aux::getRTT<TPMGL(T)>()};
    x10aux::RuntimeType::Variance variances[1] = { x10aux::RuntimeType::invariant};
    const char *baseName = "x10.util.Stack";
    rtt.initStageTwo(baseName, x10aux::RuntimeType::class_kind, 1, parents, 1, params, variances);
}
#endif // X10_UTIL_STACK_H_IMPLEMENTATION
#endif // __X10_UTIL_STACK_H_NODEPS
