// Change History:


#ifndef DDP_DESCR_H
#define DDP_DESCR_H

#include <string>
#include <vector>

#include  "drs/drs_type.h"

////////////////////////////////////////////////////////
// DDP_Descr class
////////////////////////////////////////////////////////
class DDP_Descr
{
private:
    std::string Caption;
    std::string Short;
    std::string ID;
    
public:
    DDP_Descr() {}
    DDP_Descr(const DDP_Descr & rhs);
    DDP_Descr(const byte * caption, const byte * sshort = NULL,
        const byte * id = NULL) { SetCaption(caption);
            SetShort(sshort); SetID(id); }
    virtual ~DDP_Descr() { Clear(); }
            
    virtual void Clear() { Caption.clear(); Short.clear(); ID.clear(); }
    
    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 = max(Caption.length(), Short.length());
        return max(l, ID.length()); }

    void SetCaption(const byte * caption) { if(caption) Caption = (char *)caption;
        else Caption.clear(); }
    void SetShort(const byte * sshort) { if(sshort) Short = (char *)sshort;
        else Short.clear(); }
    void SetID(const byte * id) { if(id) ID = (char *)id;
        else ID.clear(); }
    const byte * GetCaption() const { return Caption.length() ? (const byte *)Caption.c_str() : NULL; }
    const byte * GetShort() const { return Short.length() ? (const byte *)Short.c_str() : NULL; }
    const byte * GetID() const { return ID.length() ? (const byte *)ID.c_str() : NULL; }

    bool operator == (const DDP_Descr & rhs) const { if(ID.length() && ID == rhs.ID) return true;
        if(Short.length() && Short == rhs.Short) return true;
        if(Caption.length() && Caption == rhs.Caption) return true;
        return false; }
    bool operator == (const byte * rhs) const { if(!rhs) return false;
        if(ID.length() && ID == (char *)rhs) return true;
        if(Short.length() && Short == (char *)rhs) return true;
        if(Caption.length() && Caption == (char *)rhs) return true;
        return false; }
};

class DDP_DescrCollection
{
private:
    std::vector<DDP_Descr *> coll;
protected:
    virtual DDP_Descr * CreateObject() const { return new DDP_Descr; }
    virtual DDP_Descr * CreateObject(uint num) const { const DDP_Descr * descr = Get(num);
        return descr ? new DDP_Descr(*descr) : NULL; }
public:
    DDP_DescrCollection() {}
    DDP_DescrCollection(const DDP_DescrCollection &rhs);
    virtual ~DDP_DescrCollection() { Clear(); }
    
    bool Add(const byte * caption, const byte * sshort = NULL,
        const byte * id = NULL);
    bool Add(const DDP_Descr * descr);
    bool Add(const DRS_Descriptor * descr);
    
    uint GetCount() const { return coll.size(); }
    virtual const DDP_Descr * Get(uint num) const { return num < GetCount() ? coll[num] : NULL; }
    virtual const DDP_Descr * Get(const byte * str) const;
    virtual void Clear();
};

#endif


 