📄 datarecord.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#ifndef _DATARECORD_H_23648672_ // To prevent multiple #includes
#define _DATARECORD_H_23648672_
#include "string.hxx"
#include "vector.hxx"
#include "includes.h"
#include "MemTracking.h"
#include "allocator.hxx"
#include "DebugMsg.h"
#include "Tracing.h"
class DataRecord
{
public:
typedef ce::wstring string;
public:
DataRecord (INT size)
{
MemTrackAdd();
m_size = size;
m_rgpstrValues = NULL;
}
~DataRecord()
{
MemTrackRemove();
cleanup();
}
public:
HRESULT Init()
{
ASSERT(m_rgpstrValues == NULL);
m_rgpstrValues = new string*[m_size];
if (!m_rgpstrValues)
{
return E_OUTOFMEMORY;
}
for (INT i = 0; i < m_size; i++)
{
string *pstr = new string();
if (!pstr)
{
cleanup();
return E_OUTOFMEMORY;
}
m_rgpstrValues[i] = pstr;
}
return S_OK;
}
DataRecord::string& operator[] (INT idx)
{
PREFAST_ASSERT(idx >= 0 && idx < m_size);
return *(m_rgpstrValues[idx]);
}
private:
VOID cleanup()
{
if (m_rgpstrValues != NULL)
{
for (INT i = 0; i < m_size; i++)
{
if (m_rgpstrValues[i] != NULL)
{
delete m_rgpstrValues[i];
}
else
{
break;
}
}
delete [] m_rgpstrValues;
}
}
private:
INT m_size;
DataRecord::string* *m_rgpstrValues;
};
/*------------------------------------------------------------------------------
RefCountedDataRecordList
Class that wraps a ce::vector of DataRecord's and implements multithreaded
lifetime management.
------------------------------------------------------------------------------*/
class RefCountedDataRecordList
{
typedef ce::vector<DataRecord*> DataRecordList;
public:
//lifetime management
//Not a COM object - so no QueryInterface
//Constructor adds a reference
RefCountedDataRecordList(INT DataRecordSize)
{
TRACE_(ZONE_OWAEC_TRACING_CTOR);
MemTrackAdd();
m_cRefs = 1;
m_DataRecordSize = DataRecordSize;
}
~RefCountedDataRecordList()
{
TRACE_(ZONE_OWAEC_TRACING_CTOR);
MemTrackRemove();
DataRecordList::iterator it = m_DataRecordList.begin();
while (it != m_DataRecordList.end())
{
delete (*it);
it++;
}
m_DataRecordList.clear();
}
public:
HRESULT CreateNewDataRecord(DataRecord **ppNewDataRecord)
{
PREFAST_ASSERT(ppNewDataRecord != NULL);
*ppNewDataRecord = new DataRecord(m_DataRecordSize);
if (*ppNewDataRecord == NULL)
{
return E_OUTOFMEMORY;
}
return (*ppNewDataRecord)->Init();
}
#ifdef DEBUG
INT DataRecordSize() { return m_DataRecordSize; }
#endif
public:
//lifetime management (multithreaded environment)
VOID AddRef()
{
InterlockedIncrement(&m_cRefs);
}
VOID Release()
{
InterlockedDecrement(&m_cRefs);
if (m_cRefs <= 0)
delete this;
}
//vector-like routines
DataRecord* operator[] (INT idx)
{
return m_DataRecordList[idx];
}
BOOL push_back(DataRecord* pE)
{
return m_DataRecordList.push_back(pE);
}
size_t size()
{
return m_DataRecordList.size();
}
private:
LONG m_cRefs;
DataRecordList m_DataRecordList;
INT m_DataRecordSize;
};
#endif // !defined _DATARECORD_H_23648672_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -