static-stack.hpp /usr/include/gecode/support.hh Gecode::Support::StaticStack Gecode Gecode::Support /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2002 * *Lastmodified: *$Date:2009-09-0821:10:29+0200(Tue,08Sep2009)$by$Author:schulte$ *$Revision:9692$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{namespaceSupport{ template<classT,classA> classStaticStack{ private: A&a; intn; unsignedinttos; T*stack; public: StaticStack(A&a,intn); ~StaticStack(void); voidreset(void); boolempty(void)const; intentries(void)const; Tpop(void); T&top(void)const; T&last(void)const; voidpush(constT&x); private: staticvoid*operatornew(size_ts)throw(){(void)s;returnNULL;} staticvoidoperatordelete(void*p){(void)p;}; StaticStack(constStaticStack&s):a(s.a){} constStaticStack&operator=(constStaticStack&){return*this;} }; template<classT,classA> forceinline StaticStack<T,A>::StaticStack(A&a0,intn0) :a(a0),n(n0),tos(0),stack(a.templatealloc<T>(n)){} template<classT,classA> forceinline StaticStack<T,A>::~StaticStack(void){ a.free(stack,n); } template<classT,classA> forceinlinebool StaticStack<T,A>::empty(void)const{ returntos==0; } template<classT,classA> forceinlineint StaticStack<T,A>::entries(void)const{ returntos; } template<classT,classA> forceinlinevoid StaticStack<T,A>::reset(void){ tos=0; } template<classT,classA> forceinlineT StaticStack<T,A>::pop(void){ assert((tos>0)&&(tos<=static_cast<unsignedint>(n))); returnstack[--tos]; } template<classT,classA> forceinlineT& StaticStack<T,A>::top(void)const{ assert((tos>0)&&(tos<=static_cast<unsignedint>(n))); returnstack[tos-1]; } template<classT,classA> forceinlineT& StaticStack<T,A>::last(void)const{ assert((tos>=0)&&(tos<static_cast<unsignedint>(n))); returnstack[tos]; } template<classT,classA> forceinlinevoid StaticStack<T,A>::push(constT&x){ assert(tos<static_cast<unsignedint>(n)); stack[tos++]=x; } }} //STATISTICS:support-any