Line data Source code
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 :
14 0 : UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
15 :
16 0 : UStack::UStack(UErrorCode &status) :
17 0 : UVector(status)
18 : {
19 0 : }
20 :
21 0 : UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
22 0 : UVector(initialCapacity, status)
23 : {
24 0 : }
25 :
26 0 : UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) :
27 0 : UVector(d, c, status)
28 : {
29 0 : }
30 :
31 0 : UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) :
32 0 : UVector(d, c, initialCapacity, status)
33 : {
34 0 : }
35 :
36 0 : UStack::~UStack() {}
37 :
38 0 : void* UStack::pop(void) {
39 0 : int32_t n = size() - 1;
40 0 : void* result = 0;
41 0 : if (n >= 0) {
42 0 : result = elementAt(n);
43 0 : removeElementAt(n);
44 : }
45 0 : return result;
46 : }
47 :
48 0 : int32_t UStack::popi(void) {
49 0 : int32_t n = size() - 1;
50 0 : int32_t result = 0;
51 0 : if (n >= 0) {
52 0 : result = elementAti(n);
53 0 : removeElementAt(n);
54 : }
55 0 : return result;
56 : }
57 :
58 0 : int32_t UStack::search(void* obj) const {
59 0 : int32_t i = indexOf(obj);
60 0 : return (i >= 0) ? size() - i : i;
61 : }
62 :
63 : U_NAMESPACE_END
|