#ifndef VTABLE_H
#define VTABLE_H

#include "global.h"
#include "TableMetaData.h"
#include "TableData.h"

/**
* This class represents &lt;TABLE&gt; (Virtual Table) element in a Resource.
*
* A virtual table is a memory representation of a Table in VOTable. 
* A VTable consists of metadata and data.
*
*/
//* Date created - 02 May 2002

class VTable {

	public:

		/**
		* Default Constructor.
		*/
		VTable();    // Constructor:  initialize variables, allocate space.

		//VTable(TableMetaData tmd, TableData td, char *ID, char *name, char *ref);

		/**
		* Constructs a 'VTable' from a &lt;TABLE&gt; element from the given VOTABLE file,
		* the xpath denotes the position of the &lt;TABLE&gt; element to be  opened.
		*
		* Example -
		* To read the first &lt;TABLE&gt; in the first <RESOURCE>
		* use "/RESOURCE[1]/TABLE[1]" in the xpath.
		* To read a &lt;TABLE&gt; with ID as 'ycat' use "/RESOURCE[1]/TABLE[@ID='ycat']"
		* in the xpath. 
		*
		* Make sure that the xpath points to a single &lt;TABLE&gt; element,
		* else VOERROR will be returned. Note that xpath is case sensitive. 
		*
		* Currently the parameter 'iomode' is ignored since all
		* files are opened in 'readonly' mode.
		*/
		VTable(const char * filename, const char * path, int iomode, int * status);

		/**
		* Destructor
		*/
		~VTable();

		/**
		* Assignment Operator Overloaded.
		*/
		VTable operator=(const VTable &v);

		/**
		* Copy Constructor
		*/
		VTable(const VTable &v);

		/**
		* Opens a &lt;TABLE&gt; element from the given VOTABLE file,
		* the xpath denotes the position of the &lt;TABLE&gt; element to be  opened.
		*
		* Example -
		* To read the first &lt;TABLE&gt; in the first <RESOURCE>
		* use "/RESOURCE[1]/TABLE[1]" in the xpath.
		* To read a &lt;TABLE&gt; with ID as 'ycat' use "/RESOURCE[1]/TABLE[@ID='ycat']"
		* in the xpath. 
		*
		* Make sure that the xpath points to a single &lt;TABLE&gt; element,
		* else VOERROR will be returned. 
		*
		* Currently the parameter 'iomode' is ignored since all
		* files are opened in 'readonly' mode.
		*/ 
		int openFile(const char * filename, 
			const char * path, int iomode, int * status);

		/**
		* Close the VTable.
		*/
		int closeFile(int * status);

		// Set MetaData
		int setMetaData(TableMetaData tmd, int * status);

		// Set Table Data
		int setData(TableData td, int * status);

		// Set Table name
		int setName(char * name, int * status);

		// Set Table ID.
		int setID(char * ID, int * status);

		// Set Table Reference
		int setRef(char * ref, int * status);

		/**
		* Gets the 'TableMetaData'.
		*/
		int getMetaData(TableMetaData &tmd, int * status);

		/**
		* Gets the 'TableData'.
		*/
		int getData(TableData &td, int * status);

		/**
		* Gets 'name'.
		*/
		int getName(char * &name, int * status);

		/**
		* Gets 'ID'.
		*/
		int getID(char * &ID, int * status);

		/**
		* Gets 'Ref'.
		*/
		int getRef(char * &ref, int * status);

	private:
		
		TableMetaData m_tmd; 
		TableData m_td;
		char * m_ID;
		char * m_name;
		char * m_ref;

		void cleanup(void);
		void makecopy(const VTable &v);
		void init(void);

};

#endif