//------------------------------------------------------------------------------
//    module ddata.h                                                          //
//                                                                            //
//    Class TDataData encapsulates some necessary information from the learn  //
//    data file like # variables, minima, maxima, feature, weights ...        //
//    Counted object: use Release() to delete!                                //
//    See below or http://www.newty.de/pnc2/sdocu.html for more information.  //
//                                                                            //
//    copyright (c) 1999-2003 by Lars Haendel                                 //
//    home: www.newty.de                                                      //
//                                                                            //
//    This program is free software; you can redistribute it and/or modify    //
//    it under the terms of the GNU General Public License as published by    //
//    the Free Software Foundation as version 2 of the License.               //
//                                                                            //
//    This program is distributed in the hope that it will be useful,         //
//    but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//    GNU General Public License for more details.                            //
//                                                                            //
//    You should have received a copy of the GNU General Public License       //
//    along with this program; if not, write to the Free Software             //
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               //
//                                                                            //
//------------------------------------------------------------------------------


#ifndef _DDATA_H
#define _DDATA_H


#include "data.h"    // due to:  TData


//----------------------------------------------------------------------------------------------------------------------
class TDataData
{
public:

   // constructor/destructor
   enum TNormType { ByFourSigma, ByRange, ByAverageDistance};
   TDataData(const TData*const& data, const TNormType& type, const float& overlapFac);
   TDataData();
   void Release() const;

   const TDataData* GetObject() const { ref++; return this; };


   const int OriginalColumnInFile(const int& actId) const { return TData::OriginalColumnInFile(actId, outcol);};
   const int ActualColumnInData(const int& oriId)   const { return TData::ActualColumnInData(oriId, outcol);};

   // functions to get statistics and weights
   inline const float*const& Min()                    const { return min;     };
   inline const float*const& NormFac()                const { return normFac; };
   inline const float*const& Weights()                const { return weight;  };

   inline const bool IsSymbolic  (const int& j) const { return type[j]==TData::symb; };
   inline const int& nIntegerMaxMin(const int& j) const { return _nIntegerMaxMin[j]; };

   #ifndef RELEASE      // obsolete in release versions
   inline const int& nSymbolsFound(const int& j) const { return _nSymbolsFound[j]; };
   #endif
   inline const TData::TVarType& VarType (const int& j) const { return type[j]; };

   inline const int& OutputColumn() const { return outcol; };

   inline const float& MeanY() const { return meanY; };

   inline const int& nVar() const { return _nVar; };
   inline const int& nTup() const { return _nTup; };
   inline const int& nInp() const { return _nInp; };

   inline const char* FileName() const { return szFilename; };

   void Save(ofstream& file) const;          // save to file (ofstream)
   void Load(ifstream& file, int& line);     // load from file (ifstream)

private:

   ~TDataData();              // private destructor, use Release() instead
   mutable int ref;           // reference counter, objects deletes itself if there are no more references
   bool f_Loaded;

   void Allocate(const int& __nVar);

   TData::TVarType* type;     // variable types
   char szFilename[STS];      // file from which data was originally loaded

   float *min, *weight;       // minima and weights of each variable
   float *normFac;            // factor used to normalise component wise distances
   int* _nIntegerMaxMin;      // # symbols for each variable calculated as maximal minus minimal symbol
                              // value, '0' indicates that variable is continous
   #ifndef RELEASE            // obsolete in release versions
   int* _nSymbolsFound;       // real # symbols for each variable, '0' indicates that variable is continous
   #endif

   int _nVar, _nInp, outcol, _nTup; // # variables, # inputs (Calculated as: _nVar-1), output column and # data tuples
   float meanY;                     // mean output value
};
#endif