⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vector.cpp

📁 Intel开发的IPP库的应用例程
💻 CPP
📖 第 1 页 / 共 2 页
字号:

void CVector::Set(CMyString str)
{
   if (m_type == ppNONE) return;
   CStringArray itemArr;
   str.Parse(itemArr,_T(";(){}\r\n"));
   Allocate((int)itemArr.GetSize());
   for (int i=0; i<itemArr.GetSize(); i++) {
      CString item = itemArr[i];
      item.TrimLeft();
      item.TrimRight();
      if (item.IsEmpty()) {
         i--;
         continue;
      }
      Set(i, item);
   }
}

void CVector::Get(CMyString& str, CString separ) const
{
   Get(str,5,separ);
}

void CVector::Get(CMyString& str, int nDigits, CString separ) const
{
   str.Empty();
   for (int i=0; i<Length(); i++) {
      CString item;
      Get(i,item,nDigits);
      if (!str.IsEmpty()) str += separ;
      str += item;
   }
}

void CVector::Set(const CMyString* strArray, int num)
{
   if (m_type == ppNONE) return;
   if (num < 0) num = Length();
   for (int i=0; i<num; i++) {
      Set(i, strArray[i]);
   }
}

void CVector::Get(CMyString* strArray, int num, int nDigits) const
{
   if (m_type == ppNONE) return;
   if (num < 0) num = Length();
   for (int i=0; i<num; i++) {
      Get(i,strArray[i],nDigits);
   }
}

void CVector::CreateCustomData(CString dataName, void* pData, int dataSize)
{
   DeleteCustomData();
   if (!pData || !dataSize) return;
   m_pCustomData = new char[dataSize];
   m_CustomName = dataName;
   m_CustomSize = dataSize;
   memcpy(m_pCustomData, pData, dataSize);
}

void CVector::DeleteCustomData()
{ 
   if (m_pCustomData)
      delete[] m_pCustomData;
   m_pCustomData = NULL;
   m_CustomSize = 0;
   m_CustomName = _T("");
}
void* CVector::GetCustomData(CString dataName)
{
   if (dataName == m_CustomName)
      return m_pCustomData;
   else
      return NULL;
}

///////////////////////////////////////////////////////////////////////////////

BOOL CVector::IsVoi() const 
{ 
   return m_Voi.m_length > 0;
}

void* CVector::GetDataVoi()
{
   CVoi voi = GetVoi();
   return (char*)m_pointer + voi.m_offset*ItemSize();
}

const void* CVector::GetDataVoi() const
{
   CVoi voi = GetVoi();
   return (const char*)m_pointer + voi.m_offset*ItemSize();
}

CVoi CVector::GetVoi() const
{
   if (IsVoi()) return m_Voi;
   CVoi voi(0,m_len);
   return voi;
}

void CVector::GetVoi(int& offset, int& length) const
{
   CVoi voi = GetVoi();
   offset = voi.m_offset;
   length = voi.m_length;
}

int CVector::GetLengthVoi() const
{
   CVoi voi = GetVoi();
   return voi.m_length;
}

void CVector::ResetVoi(int len)
{
   if (!IsVoi()) {
      if (m_Voi.m_offset > len)
         m_Voi.m_offset = len;
      return;
   }
   int offset, length;
   GetVoi(offset,length);
   if (offset + length > len)
      length = len - offset;
   if (offset >= len) {
      offset = len;
      length = 0;
   } else if (length < 0) {
      length = 0;
   }
   m_Voi.m_offset = offset;
   m_Voi.m_length = length;
}

BOOL CVector::SetVoi(CVoi voi)
{
   m_Voi = voi;
   ResetVoi(m_len);
   return IsVoi();
}

BOOL CVector::SetVoi(int offset, int length)
{
   CVoi voi(offset,length);
   return SetVoi(voi);
}

int CVector::GetPos() const
{
   return m_Voi.m_offset + m_Voi.m_length;
}

BOOL CVector::SetPos(int pos)
{
   if (pos > m_len)
      return FALSE;
   if (m_Voi.m_offset + m_Voi.m_length == pos)
      return TRUE;
   m_Voi.m_offset = pos;
   m_Voi.m_length = 0;
   return TRUE;
}

BOOL CVector::CopyVoi(const CVector* srcVector)
{
   if (srcVector->IsVoi())
      return SetVoi(srcVector->GetVoi());
   else
      return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
int  CVector::GetDropHeaderSize() const
{
   return sizeof(ppType) + sizeof(int);
}

void CVector::WriteDropHeader(char* pData) const
{
   memcpy(pData, &m_type, sizeof(ppType)); pData += sizeof(ppType);
   memcpy(pData, &m_len, sizeof(int)); pData += sizeof(int);
}

void CVector::ReadDropHeader(const char* pData)
{
   memcpy(&m_type, pData, sizeof(ppType)); pData += sizeof(ppType);
   memcpy(&m_len , pData, sizeof(int)); pData += sizeof(int);
}

int  CVector::GetDropInfoSize() const
{
   return sizeof(CVoi);
}

void CVector::WriteDropInfo(char* pData) const
{
   memcpy(pData, &m_Voi, sizeof(CVoi)); pData += sizeof(CVoi);
}

void CVector::ReadDropInfo(const char* pData)
{
   memcpy(&m_Voi, pData, sizeof(CVoi)); pData += sizeof(CVoi);
}

int  CVector::GetDropDataSize() const
{
   return ItemSize()*Length();
}

void CVector::WriteDropData(char* pData) const
{
   if (GetDropDataSize())
      memcpy(pData, m_pointer, GetDropDataSize()); 
   pData += GetDropDataSize();
}

void CVector::ReadDropData(const char* pData)
{
   if (GetDropDataSize())
      memcpy(m_pointer, pData, GetDropDataSize()); 
   pData += GetDropDataSize();
}


///////////////////////////////////////////////////////////////////////////////

CVectorUnit::CVectorUnit(ppType type) :   
   m_Type(pp32s),
   m_NONE(ppNONE),
   m_8u  (pp8u  ),
   m_8s  (pp8s  ),
   m_16u (pp16u ),
   m_16s (pp16s ),
   m_32u (pp32u ),
   m_32s (pp32s ),
   m_32f (pp32f ),
   m_64s (pp64s ),
   m_64f (pp64f ),
   m_8sc (pp8sc ),
   m_16sc(pp16sc), 
   m_32sc(pp32sc),
   m_32fc(pp32fc), 
   m_64sc(pp64sc),
   m_64fc(pp64fc) {
}

CVectorUnit::~CVectorUnit()
{

}

CVectorUnit& CVectorUnit::operator =(const CVectorUnit& val)
{
   m_Type = val.m_Type;
   m_NONE = val.m_NONE;
   m_8u   = val.m_8u  ;
   m_8s   = val.m_8s  ;
   m_16u  = val.m_16u ;
   m_16s  = val.m_16s ;
   m_32u  = val.m_32u ;
   m_32s  = val.m_32s ;
   m_32f  = val.m_32f ;
   m_64s  = val.m_64s ;
   m_64f  = val.m_64f ;
   m_8sc  = val.m_8sc ; 
   m_16sc = val.m_16sc; 
   m_32sc = val.m_32sc; 
   m_32fc = val.m_32fc; 
   m_64sc = val.m_64sc; 
   m_64fc = val.m_64fc; 
   return *this;
}

void CVectorUnit::Init(ppType type, int len)
{
   m_Type = type;
   if (len > 0)
      Vector(type).Allocate(len);
}

void CVectorUnit::Init(ppType type, CMyString str)
{
   m_Type = type;
   Set(str);
}

CVector& CVectorUnit::Vector(ppType type)
{
   switch (type) {
   case pp8u  : return m_8u  ;
   case pp8s  : return m_8s  ;
   case pp16u : return m_16u ;
   case pp16s : return m_16s ;
   case pp32u : return m_32u ;
   case pp32s : return m_32s ;
   case pp32f : return m_32f ;
   case pp64s : return m_64s ;
   case pp64f : return m_64f ;
   case pp8sc : return m_8sc ; 
   case pp16sc: return m_16sc; 
   case pp32sc: return m_32sc; 
   case pp32fc: return m_32fc; 
   case pp64sc: return m_64sc; 
   case pp64fc: return m_64fc; 
   default: return m_NONE;
   }
}

const CVector& CVectorUnit::Vector(ppType type) const
{
   switch (type) {
   case pp8u  : return m_8u  ;
   case pp8s  : return m_8s  ;
   case pp16u : return m_16u ;
   case pp16s : return m_16s ;
   case pp32u : return m_32u ;
   case pp32s : return m_32s ;
   case pp32f : return m_32f ;
   case pp64s : return m_64s ;
   case pp64f : return m_64f ;
   case pp8sc : return m_8sc ; 
   case pp16sc: return m_16sc; 
   case pp32sc: return m_32sc; 
   case pp32fc: return m_32fc; 
   case pp64sc: return m_64sc; 
   case pp64fc: return m_64fc; 
   default: return m_NONE;
   }
}

void CVectorUnit::Set(CMyString str)
{
   Vector().Set(str);
}

void CVectorUnit::Get(CMyString& str, CString separ) const
{
   Vector().Get(str,separ);
}

void CVectorUnit::Set(const CMyString* strArray, int num)
{
   Vector().Set(strArray, num);
}

void CVectorUnit::Get(CMyString* strArray, int num) const
{
   Vector().Get(strArray,num);
}

CVectorUnit& CVectorUnit::operator =(CVector& vec)
{
   Vector(vec.Type()) = vec;
   return *this;
}

CVector& CVector::operator =(CVectorUnit& unit)
{
   *this = unit.Vector();
   return *this;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -