#include <atlcoll.h>
#include <boost/functional/hash.hpp>

 

struct PRODUCTSELLPOLICYINDEX
{
    union
    {
        struct KEY
        {
            INT32    nProdSellPoliID;
            INT32 nProdID;
        };
        KEY Key;
        INT64 nValue;
    };

    PRODUCTSELLPOLICYINDEX() : nValue(0) {}
    PRODUCTSELLPOLICYINDEX(INT64 _value) : nValue(_value) {}
    PRODUCTSELLPOLICYINDEX(INT32 _nProdSellPoliID, INT32 _nProdID)
    {
        Key.nProdSellPoliID = _nProdSellPoliID;
        Key.nProdID = _nProdID;
    }
};

class ProductSellPolicyKeyTraits : public CElementTraits <PRODUCTSELLPOLICYINDEX>
{
public:
    static ULONG Hash(const PRODUCTSELLPOLICYINDEX& element) throw()
    {
        boost::hash<INT64> hasher;
        return (ULONG)hasher(element.nValue);
    }
    static bool CompareElements(const PRODUCTSELLPOLICYINDEX& a, const PRODUCTSELLPOLICYINDEX& b)
    {
        return (a.Key.nProdSellPoliID == b.Key.nProdSellPoliID && a.Key.nProdID == b.Key.nProdID) ? true : false;
    };
};

struct PRODUCTSELLPOLICY
{
    INT32    nProdSellPoliID;
    INT32 nPrice;
    char nExpirationType;
    INT16 nUseNum;
    INT32 nUsagePeriod;
    char szExpiDateTime[ MAX_DATETIME_LENGTH ];
    PRODUCT Product;

    void Clone( PRODUCTSELLPOLICY& ProductSellPolicy )
    {
        ProductSellPolicy.nProdSellPoliID = nProdSellPoliID;
        ProductSellPolicy.nPrice = nPrice;
        ProductSellPolicy.nExpirationType = nExpirationType;
        ProductSellPolicy.nUseNum = nUseNum;
        ProductSellPolicy.nUsagePeriod = nUsagePeriod;
        strncpy_s( ProductSellPolicy.szExpiDateTime, MAX_DATETIME_LENGTH,  szExpiDateTime, MAX_DATETIME_LENGTH - 1 );
        Product.Clone( ProductSellPolicy.Product );
    }
};

 

typedef CAtlMap<PRODUCTSELLPOLICYINDEX, PRODUCTSELLPOLICY, ProductSellPolicyKeyTraits> MAP_SELLPOLICY;

 

bool IsValideProductSellPolicy( INT32 nProdSellPoliID, INT32 nProdID )
{
    PRODUCTSELLPOLICYINDEX PolicyKey( nProdSellPoliID, nProdID );
    bool bIsExit = m_ProductSellPolicyList.Lookup( PolicyKey );
    return bIsExit;
}

 

by 흥배 2012. 9. 10. 09:00