ustack.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "uvector.h"
  10. U_NAMESPACE_BEGIN
  11. UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UStack)
  12. UStack::UStack(UErrorCode &status) :
  13. UVector(status)
  14. {
  15. }
  16. UStack::UStack(int32_t initialCapacity, UErrorCode &status) :
  17. UVector(initialCapacity, status)
  18. {
  19. }
  20. UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) :
  21. UVector(d, c, status)
  22. {
  23. }
  24. UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) :
  25. UVector(d, c, initialCapacity, status)
  26. {
  27. }
  28. UStack::~UStack() {}
  29. void* UStack::pop() {
  30. int32_t n = size() - 1;
  31. void* result = nullptr;
  32. if (n >= 0) {
  33. result = orphanElementAt(n);
  34. }
  35. return result;
  36. }
  37. int32_t UStack::popi() {
  38. int32_t n = size() - 1;
  39. int32_t result = 0;
  40. if (n >= 0) {
  41. result = elementAti(n);
  42. removeElementAt(n);
  43. }
  44. return result;
  45. }
  46. int32_t UStack::search(void* obj) const {
  47. int32_t i = indexOf(obj);
  48. return (i >= 0) ? size() - i : i;
  49. }
  50. U_NAMESPACE_END