力为的博客
技术那些事。
posts - 89,comments - 434,trackbacks - 0

Using Variant to Store Point

 

      Variant is a very powerful data type to store 'any' data. With the help of COM class _variant_t, VARIANT bacomes very easy to use. But _variant_t dosen't support all kinds of data type, for example, point data with two or three elements. Variant can hold pointer, but the memory management becomes a stubborn problem when copying variant. I'm trying to find a better way to solve the problem, but I don't want to rewrite a variant. So,  dose the way exist?

      Many UI-libs use variant to hold data of properties, such as BCGPControlBar, and they do support point displaying. Actually the point elements are formated to a string so that they be stored into one property. But it's very boring to parse values between points and variant, so it's a good idea to write a adapter for them. This adapter takes charge to format point data to string, extract point data from string, and ex-convert with _variant_t.

if we have a point class like this:

 

class  Point3D
{
public :
Point3D()
{}
Point3D(
double  x,  double  y,  double  z);
double  x();
double  y();
double  z();
private :
double  x, y, z;
}
;

 

we can write our point adapter as following:

 

class  PointAdapter
{
private :
CString m_strData;
public :
PointAdapter();
PointAdapter(
const  Point3D &  point);
PointAdapter(
const  _variant_t &  point);

operator  Point3D() const ;
operator  _variant_t() const ;
}
;

 

now, we can use the classes:

 

Point3D point( 1 , 2 , 3 );
_variant_t var 
=  PointAdapter(point);
Point3D point2 
=  PointAdapter(var);



 

posted on 2006-08-30 15:30 力为 阅读(1231) 评论(1)  编辑 收藏 引用 所属分类: C++ FAQVC&MFCVenus Plan

FeedBack:
# re: 用variant存point数据
2006-08-31 00:02 | 万连文
struct直接导出,VB可以使用,不过好像有warning  回复  更多评论
  


标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
.NET频道  博客园社区  闪存
网站导航: