]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/ustack.cpp
ICU-400.42.tar.gz
[apple/icu.git] / icuSources / common / ustack.cpp
CommitLineData
374ca955
A
1/*
2**********************************************************************
73c04bcf 3* Copyright (C) 2003-2004, International Business Machines
374ca955
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6*/
7
8#include "uvector.h"
9
10U_NAMESPACE_BEGIN
11
12UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
13
73c04bcf
A
14UStack::UStack(UErrorCode &status) :
15 UVector(status)
16{
17}
18
19UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
20 UVector(initialCapacity, status)
21{
22}
23
24UStack::UStack(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status) :
25 UVector(d, c, status)
26{
27}
28
29UStack::UStack(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status) :
30 UVector(d, c, initialCapacity, status)
31{
32}
33
34UStack::~UStack() {}
35
36void* 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
46int32_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
56int32_t UStack::search(void* obj) const {
57 int32_t i = indexOf(obj);
58 return (i >= 0) ? size() - i : i;
59}
60
374ca955 61U_NAMESPACE_END