#ifndef VTABLE_H
#define VTABLE_H

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

/**
* This class represents the <TABLE> (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 <TABLE> element from the given VOTABLE file,
		* the xpath denotes the position of the <TABLE> element to be  opened.
		*
		* Example -
		* To read the first <TABLE> in the first <RESOURCE>
		* use "/RESOURCE[1]/TABLE[1]" in the xpath.
		* To read a <TABLE> with ID as 'ycat' use "/RESOURCE[1]/TABLE[@ID='ycat']"
		* in the xpath. 
		*
		* Make sure that the xpath points to a single <TABLE> element,
		* else VOERROR will be returned. 
		*
		* 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 <TABLE> element from the given VOTABLE file,
		* the xpath denotes the position of the <TABLE> element to be  opened.
		*
		* Example -
		* To read the first <TABLE> in the first <RESOURCE>
		* use "/RESOURCE[1]/TABLE[1]" in the xpath.
		* To read a <TABLE> with ID as 'ycat' use "/RESOURCE[1]/TABLE[@ID='ycat']"
		* in the xpath. 
		*
		* Make sure that the xpath points to a single <TABLE> 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 tmd; 
		TableData td;
		char * ID;
		char * name;
		char * ref;

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

};

#endif