/*
 * I1D.h
 *
 * Interface for classes that contain 1D pointer-based matrices.
 * Contains static methods for creating and deleting 1D pointer-based matrices.
 *
 *  Created on: Feb 7, 2014
 *      Author: godin
 */

#ifndef I1D_H_
#define I1D_H_

#include <stddef.h>

template <typename T>
class I1D
{
public:

    virtual ~I1D() {};

    virtual T* getPtr1d() = 0;
    virtual int getM() const = 0;

    // Allocates a 1D pointer array of size m*n
    // If extra is true, and extra entry is allocated at array[m][0];
    static T* New1D( int m, bool extra = false )
    {
        T* array = NULL;
        if( m > 0 )
        {
            array = new T[m + ( extra ? 1 : 0 ) ];

        }
        return array;
    }

    static void Delete1D( T* array )
    {
        if( NULL != array )
        {
            delete[] array;
        }
    }

protected:
    // Protected constructors for abstract base class
    I1D() {}
    I1D( const I1D& ) {}

};

;

#endif /* I1D_H_ */
