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