TVSKIN源代碼閱讀日記(三)--- __declspec(property())……

Well, in msxml.tlh中可以看到如此類似的很多定義。爲了搞清楚XML文件到底是怎麼解析的。需要搞明白這些聲明的含義。

__declspec(property(get=GetnodeName))
_bstr_t nodeName;

 

well, i look reference to the _declspec property in MSDN (web version). The digit i took from the web page is specific to microsoft visual studio 2005/.net framework 2.0.

Visual C++ language reference

Microsoft specific

This attribute be applied to non-static virtual data members in a class or structure definition. The compiler treats these virtual data members as data members by changing their reference into function calls.

__declspec( property ( get = get_func_name )) declarator
__declspec( property ( put = put_func_name )) declarator
__declspec( property ( get = get_func_name, put = put_func_name)) declarator

 

Remarks

when the compiler sees a data member declared with this attribute on the right of a member-selection operator (“.” or  “->”), it converts the operation to a get or put function, depending on whether such an expression is an l-value or r-value. In more complicated context, such as “+=”, a rewrite is performed by doing both get and put.

This attribute can also be used in the declaration of an empty array in a class or structure definition.

For example:

__declspec (property(get=GetX, put=PutX)) int x[];

The above statement indicates that x[] can be used with one ro more array indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a,b) and p->x[a][b]=i will be turned into p->PutX(a,b,i).

 

Example

// declspec_property.cpp
struct S {
   int i;
   void putprop(int j) { 
      i = j;
   }

   int getprop() {
      return i;
   }

   __declspec(property(get = getprop, put = putprop)) int the_prop;
};

int main() {
   S s;
   s.the_prop = 5;
   return s.the_prop;
}

 

 

_COM_SMARTPTR_TYPEDEF(IXMLDOMNode, __uuidof(IXMLDOMNode));

//_COM_SMARTPTR_TYPEDEF(Ix1, __uuidof(Ix1));展開的代碼就應該是
//typedef _com_ptr_t< _com_IIID > Ix1Ptr;

 

中文解釋就是定義了一個COM智能指針,指向接口的智能指針。

details about smart types technology article:

http://edndoc.esri.com/arcobjects/9.0/ArcGISDevHelp/DevelopmentEnvs/COM/VCpp/SmartTypes.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章