/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CField.h  -  description
                             -------------------
    begin                : Wed Dec 15 1999
    copyright            : (C) 1999-2005 by Alexey Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library 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 Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifndef __CFIELDS_H__
#define __CFIELDS_H__

#include <string>

#include <sptk3/CBuffer.h>
#include <sptk3/CDateTime.h>
#include <sptk3/CVariant.h>

/// @addtogroup Database Database Support
/// @{

class CQuery;

#include <sptk3/CVariant.h>

class CFieldList;

/// @brief Data field for CDataSource.
///
/// Contains field name, field type, field data and field format information.
class SP_EXPORT CField : public CVariant {
   friend class CFieldList;
protected:
   std::string       m_name;     ///< Field name
public:
   std::string       displayName;///< Optional display field name
public:
   /// Constructor
   /// @param name const char *, field name
   CField(const char *name);

   int               width;      ///< Field width
   int               precision;  ///< Field precision
   int               flags;      ///< Field flags like alignment, etc
   bool              visible;    ///< Is field visible?

   /// Returns field name
   const std::string& fieldName() const { return m_name;           }

   /// Assignment operation
   CField& operator = (const CVariant &C)    { if (this == &C) return *this; setData(C); return *this; };

   /// Assignment operation
   CField& operator = (int value)            { setInteger(value); return *this;  }

   /// Assignment operation
   CField& operator = (unsigned value)       { setInteger(value); return *this;  }

   /// Assignment operation
   CField& operator = (short value)          { setInteger(value); return *this;  }

   /// Assignment operation
   CField& operator = (unsigned short value) { setInteger(value); return *this;  }

   /// Assignment operation
   CField& operator = (float value)          { setFloat(value); return *this;    }

   /// Assignment operation
   CField& operator = (double value)         { setFloat(value); return *this;    }

   /// Assignment operation
   CField& operator = (const char * value)   { setString(value); return *this;   }

   /// Assignment operation
   CField& operator = (const std::string& value) { setString(value.c_str(),value.length()); return *this; }

   /// Assignment operation
   CField& operator = (CDateTime value)      { setDateTime(value); return *this; }

   /// Assignment operation
   CField& operator = (const void *value)    { setImagePtr(value); return *this; }

   /// Better (than in base class) conversion method
   virtual std::string asString() const throw(CException);
};

/// @}

#endif
