#ifdef __GNUG__
#pragma implementation
#endif
namespace sc {
#define Array_declare(Type) \
class Array ## Type { \
  protected: \
    int _length; \
    int _managed; \
    Type * _array; \
  public: \
    Array ## Type():_length(0),_managed(0),_array(0) {} \
    Array ## Type(const Array ## Type&a):_length(0),_managed(0),_array(0) {operator=(a);} \
    Array ## Type(Type* data,int size):_length(size),_managed(0),_array(data){} \
    Array ## Type(int size):_length(0),_managed(0),_array(0) { set_length(size); } \
    ~Array ## Type() { clear(); } \
    int size() const { return _length; }; \
    void clear() { set_length(0); } \
    void set_length(int size) { \
        if (_array && _managed) delete[] _array; \
        _managed = 1; \
        if (size) _array = new Type [ size ]; \
        else _array = 0; \
        _length = size; \
      } \
    void resize(int size) { \
        Type*tmp=_array; \
        if (size) _array = new Type [ size ]; \
        else _array = 0; \
        int maxi; \
        if (size < _length) maxi = size; \
        else maxi = _length; \
        for (int i=0; i<maxi; i++) _array[i] = tmp[i]; \
        if (_managed && tmp) delete[] tmp; \
        _managed = 1; \
        _length = size; \
      } \
    Array ## Type& operator = (const Array ## Type & s) { \
        if (_managed && _array) delete[] _array; \
        _managed = 1; \
        _length = s._length; \
        if (_length) _array = new Type [ _length ]; \
        else _array = 0; \
        for (int i=0; i<_length; i++) { \
            _array[i] = s._array[i]; \
          } \
        return (*this); \
      } \
    Type& operator[] (int i) const { \
        if (i<0 || i>=_length) { \
            ExEnv::err0() << "Array::operator[](" << i << ") " \
                 << "out of range (" << _length << "0" << std::endl; \
            abort(); \
          }; \
        return _array[i]; \
      } \
    Type& operator() (int i) const { \
        if (i<0 || i>=_length) { \
            ExEnv::err0() << "Array::operator()(" << i << ") " \
                 << "out of range (" << _length << "0" << std::endl; \
            abort(); \
          }; \
        return _array[i]; \
      } \
    void push_back(const Type &d) { \
        resize(_length+1); \
        _array[_length-1] = d; \
    } \
    void pop_back() { \
        resize(_length-1); \
    } \
};
}
