// 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 DDP_VECTORDEF_H
#define DDP_VECTORDEF_H

#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>

#include  "ddp_expdef.h"
#include  "ddp_vector.h"

////////////////////////////////////////////////////////
// DDP_VectorDef class
////////////////////////////////////////////////////////
class DDP_VectorDef : public DDP_ExportDef
{
public:
    enum { DEFAULT_DECIMALS = -1 };

private:
    DDP_DescrCollection AddressDescr;
    DDP_Descr FormulaDescr;
    uint bIsSumable;
    DDP_Descr PeriodDescr;
    const DDP_VectorTree::RootNode * Root;
    bool HasAddr;

    uint DataSize;
    uint DataTextSize;
    AT_Num MaxValue;
    
    uint Decimals;
    bool bLongName;

protected:
    virtual const byte * GetDefLabel() const { return (const byte *)"Vector"; }

protected:
    virtual const byte * get_descr(byte * buf, uint sz) const {
        if(GetDescr(buf, sz, (const byte *)";", false) ) return buf;
        return NULL; }
    virtual const byte * get_formula(byte * buf, uint sz) const {
        PORT_snprintf_1((char *)buf, sz, "%s", IsSumable() ? (const byte *)"Sumable" : (const byte *)"Not Sumable");
        return buf; }

protected:
    bool RecursiveSetAddress(const DDP_VectorTree::Node * node,
        const VectorAddress * a);
        
public:
    DDP_VectorDef() : HasAddr(false), bIsSumable(false),
        Root(NULL), Decimals(DEFAULT_DECIMALS), bLongName(true),
        DataSize(0), DataTextSize(0), MaxValue(0)
        {}
    DDP_VectorDef(const DDP_VectorDef & rhs);
    DDP_VectorDef(const DDP_VectorTree::RootNode * vroot, const VectorAddress * a = NULL,
        uint f = MAXUINT, uint p = MAXUINT);
    virtual ~DDP_VectorDef() {}

    bool HasAddress() const { return HasAddr; }
    bool SetVector(const DDP_VectorTree::RootNode * vroot);
    uint GetVectorId() const  { return Root ? Root->GetNodeID() : MAXUINT; }
    bool SetAddress(const VectorAddress * a);
    bool SetPeriod(uint p);
    bool SetFormula(uint f);
    bool SetIndexState(uint state);

    uint GetDescr(byte * buf, uint sz, const byte * delim = (const byte *)";",
        bool IsLong = true) const;
    uint RetrieveUserName(byte * buf, uint sz, const byte * delim = (const byte *)";",
        bool IsLong = true) const;

    uint GetDecimals() const { return Decimals; }
    bool IsSumable() const { return bIsSumable; }
    void SetDecimals(uint dec) { Decimals = dec; }

    void SetLongName(bool blong) { bLongName = blong; }
    bool IsLongName() const { return bLongName; }
    
    virtual bool Dump(DDP_PrintFile * file, const byte * prefix = NULL) const;

    virtual DDP_ExportDef * NewCopy(const DDP_ExportDef * rhs) const
        { return new DDP_VectorDef(*((const DDP_VectorDef *)rhs)); }

    virtual bool IsVector() const { return true; }
    virtual bool IsNull() const { return !Root; }

    virtual const bool HasFormula() const { return FormulaDescr.MaxLen(); }
    virtual uint GetSize() const { return DataSize; }
    virtual uint GetTextSize() const { return DataTextSize; }
};

#endif

