• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 *   Copyright (C) 2003-2011, International Business Machines
6 *   Corporation and others.  All Rights Reserved.
7 **********************************************************************
8 */
9 
10 #include "uvector.h"
11 
12 U_NAMESPACE_BEGIN
13 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)14 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
15 
16 UStack::UStack(UErrorCode &status) :
17     UVector(status)
18 {
19 }
20 
UStack(int32_t initialCapacity,UErrorCode & status)21 UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
22     UVector(initialCapacity, status)
23 {
24 }
25 
UStack(UObjectDeleter * d,UElementsAreEqual * c,UErrorCode & status)26 UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) :
27     UVector(d, c, status)
28 {
29 }
30 
UStack(UObjectDeleter * d,UElementsAreEqual * c,int32_t initialCapacity,UErrorCode & status)31 UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) :
32     UVector(d, c, initialCapacity, status)
33 {
34 }
35 
~UStack()36 UStack::~UStack() {}
37 
pop()38 void* UStack::pop() {
39     int32_t n = size() - 1;
40     void* result = nullptr;
41     if (n >= 0) {
42         result = orphanElementAt(n);
43     }
44     return result;
45 }
46 
popi()47 int32_t UStack::popi() {
48     int32_t n = size() - 1;
49     int32_t result = 0;
50     if (n >= 0) {
51         result = elementAti(n);
52         removeElementAt(n);
53     }
54     return result;
55 }
56 
search(void * obj) const57 int32_t UStack::search(void* obj) const {
58     int32_t i = indexOf(obj);
59     return (i >= 0) ? size() - i : i;
60 }
61 
62 U_NAMESPACE_END
63