]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/ustack.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / common / ustack.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
374ca955
A
3/*
4**********************************************************************
4388f060 5* Copyright (C) 2003-2011, International Business Machines
374ca955
A
6* Corporation and others. All Rights Reserved.
7**********************************************************************
8*/
9
10#include "uvector.h"
11
12U_NAMESPACE_BEGIN
13
14UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
15
73c04bcf
A
16UStack::UStack(UErrorCode &status) :
17 UVector(status)
18{
19}
20
21UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
22 UVector(initialCapacity, status)
23{
24}
25
4388f060 26UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) :
73c04bcf
A
27 UVector(d, c, status)
28{
29}
30
4388f060 31UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) :
73c04bcf
A
32 UVector(d, c, initialCapacity, status)
33{
34}
35
36UStack::~UStack() {}
37
38void* UStack::pop(void) {
39 int32_t n = size() - 1;
40 void* result = 0;
41 if (n >= 0) {
42 result = elementAt(n);
43 removeElementAt(n);
44 }
45 return result;
46}
47
48int32_t UStack::popi(void) {
49 int32_t n = size() - 1;
50 int32_t result = 0;
51 if (n >= 0) {
52 result = elementAti(n);
53 removeElementAt(n);
54 }
55 return result;
56}
57
58int32_t UStack::search(void* obj) const {
59 int32_t i = indexOf(obj);
60 return (i >= 0) ? size() - i : i;
61}
62
374ca955 63U_NAMESPACE_END