描述:
最近遇到使用SAFEARRAY比较多,因为是三维图形方面,用到的SAFEARRAY一般都是一维的数组,元素个数为1(表示参数曲线),2(表示参数曲面),3(表示三维点).于是写了一个针对这方面的类.
我想值得讨论是地方有两个, 一是SAFEARRAY的使用,一就是关于通用类编写的一些准则(比如说实现正规函数,转型,以及错误处理等等),希望大家能够批评指教.
#pragma once
#include <assert.h>
#include <oleauto.h>
#include <math.h>
const double E_PRECISION = 0.0001;
template<int dimension>
class CDbSafeArray
{
public:
//constructor
explicit CDbSafeArray(double t);
CDbSafeArray(double u,double v);
CDbSafeArray(double x,double y,double z);
CDbSafeArray(const SAFEARRAY* psa);
//copy constructor
CDbSafeArray(const CDbSafeArray& rhs);
~CDbSafeArray();
public:
//operator override
SAFEARRAY** operator&();
CDbSafeArray& operator = (const CDbSafeArray& rhs);
bool Equal(double dbleft,double dbright);
bool operator == ( const CDbSafeArray& rhs);
bool operator != ( const CDbSafeArray& rhs);
public:
//data access
//for parameterized curve dimension = 1
HRESULT get_T(double& T);
HRESULT set_T(double T);
//for parameterized surface dimension = 2
HRESULT get_U(double& U);
HRESULT set_U(double U);
HRESULT get_V(double& V);
HRESULT set_V(double V);
//for 3d point dimension = 3
HRESULT get_X(double& X);
HRESULT set_X(double X);
HRESULT get_Y(double& Y);
HRESULT set_Y(double Y);
HRESULT get_Z(double& Z);
HRESULT set_Z(double Z);
//
HRESULT setdata(double T);
HRESULT getdata(double& T);
HRESULT setdata(double U,double V);
HRESULT getdata(double& U,double& V);
HRESULT setdata(double X,double Y, double Z);
HRESULT getdata(double& X,double& Y, double& Z);
public:
//safearray
SAFEARRAY* m_psa;
private:
//the length of the array(only 1,2,3 allowed)
int m_idimension;
};
解决方案1:
呵呵,看来有共同的爱好,喜欢写些基础的类.
我想这是在更深层次上学习模板的好办法.
我也做了个CSafeArray,比起CComSafeArray,它提供了对自定义类型数组的支持,交流一下.
http://IUnknown.6to23.com/
不错,鼎
不过呢,MS都有线程的封装类,何必这么辛苦呢
不错,支持+收藏
解决方案4: COleSafeArray
The COleSafeArray class is used for working with arrays of arbitrary types and dimensions. COleSafeArray provides implementations of the COM SAFEARRAY member functions, as well as a set of member functions specifically designed for one-dimensional arrays of bytes. COleSafeArray derives from the COM VARIANT structure.