// Change History:
// DART Data Transfer
// 12/03/03 AV Development: Code cleanup. const/none const
// 11/13/03 AV Development: Change Descr::Get to return long descr if no short

#ifndef DRS_VECTORDEF_H
#define DRS_VECTORDEF_H

#include <cstring>
#include <vector>

#include  "retrieve/at_retrieve.h"
#include  "drs/drs_type.h"

class DRS_Application;
class DRS_Database;
class DRS_Vector;

////////////////////////////////////////////////////////
// DRS_VectorDef class
////////////////////////////////////////////////////////
class DRS_VectorDef
{
private:
    struct Descr
    {
        std::string Caption;
        std::string Short;
        std::string ID;
        void Clear() { Caption.clear(); Short.clear(); ID.clear(); }
        Descr & operator = (const DRS_Descriptor & rhs)
            { Caption = (char *)rhs.Caption; Short = (char *)rhs.Descr; ID = (char *)rhs.ID;
                return *this; }
        Descr & operator = (const Descr & rhs)
            { Caption = rhs.Caption; Short = rhs.Short; ID = rhs.ID; return *this; }
        const byte * Get(bool isLong) const {if(isLong && Caption.length()) return (const byte*) Caption.c_str();
            if(Short.length()) return (const byte*) Short.c_str();
            return (const byte*) Caption.c_str(); }
        uint MaxLen() const { uint l = std::max(Caption.length(), Short.length());
            return std::max(l, ID.length()); }
    };
    uint VectorId;
    std::vector<Descr> AddressDescr;
    Descr FormulaDescr;
    Descr PeriodDescr;
    bool HasAddr;
    bool AllowAll;
public:
    DRS_VectorDef() : VectorId(MAXUINT), HasAddr(false) {}
    DRS_VectorDef(DRS_Application * appl, uint vectID, uint * a = NULL, uint f = MAXUINT, uint p = MAXUINT, bool all = true);
    DRS_VectorDef(DRS_Vector * vect, uint * a = NULL, uint f = MAXUINT, uint p = MAXUINT, bool all = true);
    virtual ~DRS_VectorDef() {}

    bool HasAddress() const { return HasAddr; }
    const DRS_Vector * SetVector(DRS_Application * appl, uint vectId);
    const DRS_Vector * SetVector(DRS_Vector * v);    
    uint GetVectorId() const  { return VectorId; }
    bool SetAddress(const DRS_Vector * vect, uint * a);
    bool SetPeriod(const DRS_Vector * vect, uint p);
    bool SetFormula(const DRS_Vector * vect, uint f);
    void SetAll(bool a) { AllowAll = a; }
        
    uint GetDescr(byte * buf, uint sz, const byte * delim = (const byte*)";",
        bool IsLong = true) const;
};

#endif

