sharedbreakiterator.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. * Copyright (C) 2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ******************************************************************************
  8. * sharedbreakiterator.h
  9. */
  10. #ifndef __SHARED_BREAKITERATOR_H__
  11. #define __SHARED_BREAKITERATOR_H__
  12. #include "unicode/utypes.h"
  13. #include "sharedobject.h"
  14. #if !UCONFIG_NO_BREAK_ITERATION
  15. U_NAMESPACE_BEGIN
  16. class BreakIterator;
  17. // SharedBreakIterator encapsulates a shared BreakIterator. Because
  18. // BreakIterator has mutable semantics, clients must ensure that all uses
  19. // of a particular shared BreakIterator is protected by the same mutex
  20. // ensuring that only one thread at a time gets access to that shared
  21. // BreakIterator. Clients can accomplish this by creating a mutex for all
  22. // uses of break iterator within a particular class. Then objects of that
  23. // class may then freely share break iterators among themselves. However,
  24. // these shared break iterators must never be exposed outside of that class.
  25. class U_I18N_API SharedBreakIterator : public SharedObject {
  26. public:
  27. SharedBreakIterator(BreakIterator *biToAdopt);
  28. virtual ~SharedBreakIterator();
  29. BreakIterator *get() const { return ptr; }
  30. BreakIterator *operator->() const { return ptr; }
  31. BreakIterator &operator*() const { return *ptr; }
  32. private:
  33. BreakIterator *ptr;
  34. SharedBreakIterator(const SharedBreakIterator &) = delete;
  35. SharedBreakIterator &operator=(const SharedBreakIterator &) = delete;
  36. };
  37. U_NAMESPACE_END
  38. #endif
  39. #endif