cygnuscygwinb20includegstldequeh.docx

上传人:b****7 文档编号:9624047 上传时间:2023-02-05 格式:DOCX 页数:50 大小:28.97KB
下载 相关 举报
cygnuscygwinb20includegstldequeh.docx_第1页
第1页 / 共50页
cygnuscygwinb20includegstldequeh.docx_第2页
第2页 / 共50页
cygnuscygwinb20includegstldequeh.docx_第3页
第3页 / 共50页
cygnuscygwinb20includegstldequeh.docx_第4页
第4页 / 共50页
cygnuscygwinb20includegstldequeh.docx_第5页
第5页 / 共50页
点击查看更多>>
下载资源
资源描述

cygnuscygwinb20includegstldequeh.docx

《cygnuscygwinb20includegstldequeh.docx》由会员分享,可在线阅读,更多相关《cygnuscygwinb20includegstldequeh.docx(50页珍藏版)》请在冰豆网上搜索。

cygnuscygwinb20includegstldequeh.docx

cygnuscygwinb20includegstldequeh

G++2.91.57,cygnus\cygwin-b20\include\g++\stl_deque.h完整列表

/*

*

*Copyright(c)1994

*Hewlett-PackardCompany

*

*Permissiontouse,copy,modify,distributeandsellthissoftware

*anditsdocumentationforanypurposeisherebygrantedwithoutfee,

*providedthattheabovecopyrightnoticeappearinallcopiesand

*thatboththatcopyrightnoticeandthispermissionnoticeappear

*insupportingdocumentation.Hewlett-PackardCompanymakesno

*representationsaboutthesuitabilityofthissoftwareforany

*purpose.Itisprovided"asis"withoutexpressorimpliedwarranty.

*

*

*Copyright(c)1997

*SiliconGraphicsComputerSystems,Inc.

*

*Permissiontouse,copy,modify,distributeandsellthissoftware

*anditsdocumentationforanypurposeisherebygrantedwithoutfee,

*providedthattheabovecopyrightnoticeappearinallcopiesand

*thatboththatcopyrightnoticeandthispermissionnoticeappear

*insupportingdocumentation.SiliconGraphicsmakesno

*representationsaboutthesuitabilityofthissoftwareforany

*purpose.Itisprovided"asis"withoutexpressorimpliedwarranty.

*/

/*NOTE:

Thisisaninternalheaderfile,includedbyotherSTLheaders.

*Youshouldnotattempttouseitdirectly.

*/

#ifndef__SGI_STL_INTERNAL_DEQUE_H

#define__SGI_STL_INTERNAL_DEQUE_H

/*Class的恆長特性(invariants):

*對於任何nonsingulariteratorI:

*i.node是maparray中的某個元素的位址。

*i.node所指內容則是一個指標,指向某個節點(緩衝區)的頭。

*i.first==*(i.node)

*i.last==i.first+node_size(也就是buffer_size())

*i.cur是一個指標,指向範圍[i.first,i.last)之間。

注意:

*這意味i.cur永遠是一個dereferenceablepointer,

*縱使i是一個past-the-enditerator.

*Start和Finish總是nonsingulariterators。

注意:

這意味

*emptydeque一定會有一個node,而一個具有N個元素的deque,

*(N表示緩衝區大小),一定會有兩個nodes。

*對於start.node和finish.node以外的每一個node,其中的每一個元素

*都是一個經過初始化的物件。

如果start.node==finish.node,

*那麼[start.cur,finish.cur)都是經過初始化的物件,而該範圍以外

*元素則是未經初始化的空間。

否則,[start.cur,start.last)和

*[finish.first,finish.cur)是經過初始化的物件,而

*[start.first,start.cur)和[finish.cur,finish.last)

*則是未經初始化的空間

*[map,map+map_size)是一個有效的,non-empty的範圍。

*[start.node,finish.node]是一個有效的範圍,內含於

*[map,map+map_size)之內。

*範圍[map,map+map_size)內的任何一個指標會指向一個經過配置的

*node—若且唯若該指標在範圍[start.node,finish.node]之內。

*/

/*

*在前一版的deque中,node_size由編譯器定死。

這個版本允許使用者選擇節點

*(node)的大小。

Deque有三個template參數,其中第三個是一個型別為size_t

*的數值,代表每個節點(node)內含的元素個數。

如果第三個template參數為0

*(那是預設值),deque就使用預設的節點大小。

*

*使用不同的節點大小的唯一理由是,或許你的程式需要不同的效率並願意付出其他方

*面的代價。

例如,假設你的程式內含許多deques,每一個都只內含一些元素,那麼

*你可以使用較小的nodes來節省記憶體(或許會因此犧牲速度)。

*

*不幸的是,某些編譯器面對non-typetemplate參數會有問題。

stl_config.h之

*中為此定義了一個__STL_NON_TYPE_TMPL_PARAM_BUG。

如果你的編譯器正是如

*此,你就無法使用不同的節點大小,你必須使用預設大小。

*/

__STL_BEGIN_NAMESPACE

#ifdefined(__sgi)&&!

defined(__GNUC__)&&(_MIPS_SIM!

=_MIPS_SIM_ABI32)

#pragmasetwoff1174

#endif

//注意:

下面這個函式是七拼八湊的產品,只是為了閃避數家編譯器在處理常數算式

//(constantexpressions)時的臭蟲。

//如果n不為0,傳回n,表示buffersize由使用者自定。

//如果n為0,表示buffersize使用預設值,那麼

//如果sz(元素大小,sizeof(value_type))小於512,傳回512/sz,

//如果sz不小於512,傳回1。

inlinesize_t__deque_buf_size(size_tn,size_tsz)

{

returnn!

=0?

n:

(sz<512?

size_t(512/sz):

size_t

(1));

}

#ifndef__STL_NON_TYPE_TMPL_PARAM_BUG

template

struct__deque_iterator{//未繼承std:

:

iterator

typedef__deque_iteratoriterator;

typedef__deque_iteratorconst_iterator;

staticsize_tbuffer_size(){return__deque_buf_size(BufSiz,sizeof(T));}

#else/*__STL_NON_TYPE_TMPL_PARAM_BUG*/

template

struct__deque_iterator{//未繼承std:

:

iterator

typedef__deque_iteratoriterator;

typedef__deque_iteratorconst_iterator;

staticsize_tbuffer_size(){return__deque_buf_size(0,sizeof(T));}

#endif

//未繼承std:

:

iterator,所以必須自行撰寫五個必要的迭代器相應型別

typedefrandom_access_iterator_tagiterator_category;//

(1)

typedefTvalue_type;//

(2)

typedefPtrpointer;//(3)

typedefRefreference;//(4)

typedefsize_tsize_type;

typedefptrdiff_tdifference_type;//(5)

typedefT**map_pointer;

typedef__deque_iteratorself;

//保持與容器的聯結

T*cur;//此迭代器所指之緩衝區中的現行(current)元素

T*first;//此迭代器所指之緩衝區的頭

T*last;//此迭代器所指之緩衝區的尾(含備用空間)

map_pointernode;

__deque_iterator(T*x,map_pointery)

:

cur(x),first(*y),last(*y+buffer_size()),node(y){}

__deque_iterator():

cur(0),first(0),last(0),node(0){}

__deque_iterator(constiterator&x)

:

cur(x.cur),first(x.first),last(x.last),node(x.node){}

//以下各個多載化運算子是__deque_iterator<>成功運作的關鍵。

referenceoperator*()const{return*cur;}

#ifndef__SGI_STL_NO_ARROW_OPERATOR

pointeroperator->()const{return&(operator*());}

#endif/*__SGI_STL_NO_ARROW_OPERATOR*/

difference_typeoperator-(constself&x)const{

returndifference_type(buffer_size())*(node-x.node-1)+

(cur-first)+(x.last-x.cur);

}

//參考MoreEffectiveC++,item6:

Distinguishbetweenprefixand

//postfixformsofincrementanddecrementoperators.

self&operator++(){

++cur;//切換至下一個元素。

if(cur==last){//如果已達所在緩衝區的尾端,

set_node(node+1);//就切換至下一個節點(亦即緩衝區)

cur=first;//的第一個元素。

}

return*this;

}

selfoperator++(int){

selftmp=*this;

++*this;

returntmp;

}

self&operator--(){

if(cur==first){//如果已達所在緩衝區的頭端,

set_node(node-1);//就切換至前一個節點(亦即緩衝區)

cur=last;//的最後一個元素。

}

--cur;//切換至前一個元素。

return*this;

}

selfoperator--(int){

selftmp=*this;

--*this;

returntmp;

}

self&operator+=(difference_typen){

difference_typeoffset=n+(cur-first);

if(offset>=0&&offset

//目標位置在同一緩衝區內

cur+=n;

else{

//目標位置不在同一緩衝區內

difference_typenode_offset=

offset>0?

offset/difference_type(buffer_size())

:

-difference_type((-offset-1)/buffer_size())-1;

//切換至正確的節點(亦即緩衝區)

set_node(node+node_offset);

//切換至正確的元素

cur=first+(offset-node_offset*difference_type(buffer_size()));

}

return*this;

}

//參考MoreEffectiveC++,item22:

Considerusingop=insteadof

//stand-aloneop.

selfoperator+(difference_typen)const{

selftmp=*this;

returntmp+=n;//喚起operator+=

}

self&operator-=(difference_typen){return*this+=-n;}

//以上利用operator+=來完成operator-=

//參考MoreEffectiveC++,item22:

Considerusingop=insteadof

//stand-aloneop.

selfoperator-(difference_typen)const{

selftmp=*this;

returntmp-=n;//喚起operator-=

}

referenceoperator[](difference_typen)const{return*(*this+n);}

//以上喚起operator*,operator+

booloperator==(constself&x)const{returncur==x.cur;}

booloperator!

=(constself&x)const{return!

(*this==x);}

booloperator<(constself&x)const{

return(node==x.node)?

(cur

(node

}

voidset_node(map_pointernew_node){

node=new_node;

first=*new_node;

last=first+difference_type(buffer_size());

}

};

#ifndef__STL_CLASS_PARTIAL_SPECIALIZATION

//編譯器不支援partialspecialization時,才需以下定義

#ifndef__STL_NON_TYPE_TMPL_PARAM_BUG

template

inlinerandom_access_iterator_tag

iterator_category(const__deque_iterator&){

returnrandom_access_iterator_tag();

}

template

inlineT*value_type(const__deque_iterator&){

return0;

}

template

inlineptrdiff_t*distance_type(const__deque_iterator&){

return0;

}

#else/*__STL_NON_TYPE_TMPL_PARAM_BUG*/

template

inlinerandom_access_iterator_tag

iterator_category(const__deque_iterator&){

returnrandom_access_iterator_tag();

}

template

inlineT*value_type(const__deque_iterator&){return0;}

template

inlineptrdiff_t*distance_type(const__deque_iterator&){

return0;

}

#endif/*__STL_NON_TYPE_TMPL_PARAM_BUG*/

//編譯器不支援partialspecialization時,才需以上定義

#endif/*__STL_CLASS_PARTIAL_SPECIALIZATION*/

//見__deque_buf_size()。

BufSize預設值為0的唯一理由是為了閃避某些

//編譯器在處理常數算式(constantexpressions)時的臭蟲。

//預設使用alloc為配置器

template

classdeque{

public:

//Basictypes

typedefTvalue_type;

typedefvalue_type*pointer;

typedefconstvalue_type*const_pointer;

typedefvalue_type&reference;

typedefconstvalue_type&const_reference;

typedefsize_tsize_type;

typedefptrdiff_tdifference_type;

public:

//Iterators

#ifndef__STL_NON_TYPE_TMPL_PARAM_BUG

typedef__deque_iteratoriterator;

typedef__deque_iteratorconst_iterator;

#else/*__STL_NON_TYPE_TMPL_PARAM_BUG*/

typedef__deque_iteratoriterator;

typedef__deque_iteratorconst_iterator;

#endif/*__STL_NON_TYPE_TMPL_PARAM_BUG*/

#ifdef__STL_CLASS_PARTIAL_SPECIALIZATION

typedefreverse_iteratorconst_reverse_iterator;

typedefreverse_iteratorreverse_iterator;

#else/*__STL_CLASS_PARTIAL_SPECIALIZATION*/

typedefreverse_iterator

difference_type>

const_reverse_iterator;

typedefreverse_iterator

reverse_iterator;

#endif/*__STL_CLASS_PARTIAL_SPECIALIZATION*/

protected:

//Internaltypedefs

//元素的指標的指標(pointerofpointerofT)

typedefpointer*map_pointer;

//專屬之空間配置器,每次配置一個元素大小

typedefsimple_allocdata_allocator

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 交通运输

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1