Home | History | Annotate | Download | only in common
      1 /*
      2 **********************************************************************
      3 *   Copyright (C) 2003-2004, International Business Machines
      4 *   Corporation and others.  All Rights Reserved.
      5 **********************************************************************
      6 */
      7 
      8 #include "uvector.h"
      9 
     10 U_NAMESPACE_BEGIN
     11 
     12 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
     13 
     14 UStack::UStack(UErrorCode &status) :
     15     UVector(status)
     16 {
     17 }
     18 
     19 UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
     20     UVector(initialCapacity, status)
     21 {
     22 }
     23 
     24 UStack::UStack(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status) :
     25     UVector(d, c, status)
     26 {
     27 }
     28 
     29 UStack::UStack(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status) :
     30     UVector(d, c, initialCapacity, status)
     31 {
     32 }
     33 
     34 UStack::~UStack() {}
     35 
     36 void* UStack::pop(void) {
     37     int32_t n = size() - 1;
     38     void* result = 0;
     39     if (n >= 0) {
     40         result = elementAt(n);
     41         removeElementAt(n);
     42     }
     43     return result;
     44 }
     45 
     46 int32_t UStack::popi(void) {
     47     int32_t n = size() - 1;
     48     int32_t result = 0;
     49     if (n >= 0) {
     50         result = elementAti(n);
     51         removeElementAt(n);
     52     }
     53     return result;
     54 }
     55 
     56 int32_t UStack::search(void* obj) const {
     57     int32_t i = indexOf(obj);
     58     return (i >= 0) ? size() - i : i;
     59 }
     60 
     61 U_NAMESPACE_END
     62