📄 twinvector.h
字号:
#if !defined(AFX_TWINVECTOR_H__7A303F20_568C_41B5_8AAB_11D792346E35__INCLUDED_)
#define AFX_TWINVECTOR_H__7A303F20_568C_41B5_8AAB_11D792346E35__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Twin.h"
//*******************************************
//andi
//date: 14 feb 2002
//added: 18 feb 2002
//
//*******************************************
typedef vector<Twin> TWINVECTOR;
class TwinVector: public TWINVECTOR
{
public:
TwinVector(){};
//___________________________________________________________
TwinVector(VARIANT varSafe)
{
TwinVector vec;
int dim = 0;
HRESULT hr = S_OK;
long lStartBound = 0;
long lEndBound = 0;
long lDimension[2];
try
{
if (!( (varSafe.vt) == (VT_VARIANT | VT_ARRAY) ))
return;
SAFEARRAY* psa = varSafe.parray;
// Get the Upper and lower bound of the returned array
dim = SafeArrayGetDim(psa);
hr = SafeArrayGetLBound(psa, 2, &lStartBound);
hr = SafeArrayGetUBound(psa, 2, &lEndBound);
for(int index = lStartBound; index <= lEndBound; index ++)
{
VARIANT varName;
lDimension[1] = index; //index in vector
lDimension[0] = 0; //indexDim; //0, 1,
hr = SafeArrayGetElement(psa, lDimension, &varName);
if(hr != S_OK) return ;
VARIANT varValue;
lDimension[1] = index; //index in vector
lDimension[0] = 1; //indexDim; //0, 1,
hr = SafeArrayGetElement(psa, lDimension, &varValue);
if(hr != S_OK) return ;
vec.push_back(Twin(varName.bstrVal, varValue.bstrVal));
if(varName.bstrVal) ::SysFreeString(varName.bstrVal);
if(varValue.bstrVal) ::SysFreeString(varValue.bstrVal);
}
SafeArrayUnaccessData(psa);
// vec.push_back(Twin(L"1", L"1"));
*this = vec;
}
catch(...)
{
}
};
//___________________________________________________________
//___________________________________________________________
#ifndef _UNICODE
#define DimVariables 15
TwinVector(CHttpServerContext* pCtxt, LPTSTR szData)
{
TwinVector vec;
char *chVariables[] = { "HTTP_COOKIE", "REQUEST_METHOD", "QUERY_STRING",
"SCRIPT_NAME", "AUTH_TYPE", "SERVER_NAME",
"HTTP_CONTENT_TYPE", "HTTP_REFERER", "HTTP_ACCEPT",
"HTTP_ACCEPT_LANGUAGE", "PATH_INFO", "REMOTE_ADDR",
"REMOTE_HOST", "REMOTE_USER", "CONTENT_LENGTH" };
char szRequest[4096];
DWORD dwBuffSize;
try
{
for(int i=0; i< DimVariables; i++)
{
dwBuffSize = 4096;
pCtxt->GetServerVariable(chVariables[i], szRequest, &dwBuffSize);
szRequest[dwBuffSize] = '\0';
vec.push_back(Twin(chVariables[i], szRequest));
}
//now the data from post or get
//must be parsed
if (szData )
vec.push_back(Twin("DATA", szData));
*this = vec;
}
catch(...)
{
}
};
#endif
//___________________________________________________________
//___________________________________________________________
VARIANT GetVariant()
{
TwinVector vec = *this;
VARIANT pVariant;
long index = 0;
//Used for indicating indexes in the Multidimensional array
long lDimension[2];
//Initialize the vector iterators
TwinVector::iterator it;
//Initialize the bounds for the array
//Ours is a 2 dimensional array
SAFEARRAYBOUND safeBound[2];
//Set up the bounds for the first index
safeBound[0].cElements = 2;
safeBound[0].lLbound = 0;
//Set up the bounds for the second index
safeBound[1].cElements = vec.size();
safeBound[1].lLbound = 0 ;
///Initialize the VARIANT
VariantInit(&pVariant);
//The array type is VARIANT
//Storage will accomodate a BSTR and a float
pVariant.vt = VT_VARIANT | VT_ARRAY;
pVariant.parray = SafeArrayCreate(VT_VARIANT, 2, safeBound);
//Iterate thru the list of flavors and prices
for(it = vec.begin(), index=0; it != vec.end(); it++, index++)
{
//Put the Element at (0,0), (0,1) , (0,2) ,.............(0,n)
lDimension[1] = index;
lDimension[0] = 0;
//CComVariant variantName(::SysAllocString(it->GetName()));
CComVariant variantName((LPCTSTR)it->GetName());
SafeArrayPutElement(pVariant.parray, lDimension, &variantName);
//Put the Element at (1,0), (1,1) , (1,2) ,.............(1,n)
lDimension[1] = index;
lDimension[0] = 1;
CComVariant variantValue((LPCTSTR)it->GetValue());
SafeArrayPutElement(pVariant.parray, lDimension, &variantValue);
}
return pVariant;
};
//___________________________________________________________
//___________________________________________________________
//Twin Find(_bstr_t bstrToken)
long Find(_bstr_t bstrToken)
{
TwinVector vec = *this;
TwinVector::iterator it;
long index = 0;
if (! vec.empty() )
for (it = vec.begin(); it != vec.end(); it++, index++)
{
if ( (it->GetName()) == bstrToken)
{
//AfxMessageBox( it->GetName() );
//return *it;
it = vec.begin();
return index;
}
}
//return *vec.end();
return -1;
}
//___________________________________________________________
};
#endif // !defined(AFX_TWINVECTOR_H__7A303F20_568C_41B5_8AAB_11D792346E35__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -