• 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) 2009-2015, International Business Machines Corporation and    *
6 * others. All Rights Reserved.                                                *
7 *******************************************************************************
8 */
9 
10 #ifndef FPHDLIMP_H
11 #define FPHDLIMP_H
12 
13 #include "unicode/utypes.h"
14 
15 #if !UCONFIG_NO_FORMATTING
16 
17 #include "unicode/fieldpos.h"
18 #include "unicode/fpositer.h"
19 
20 U_NAMESPACE_BEGIN
21 
22 // utility FieldPositionHandler
23 // base class, null implementation
24 
25 class U_I18N_API FieldPositionHandler: public UMemory {
26  protected:
27   int32_t fShift = 0;
28 
29  public:
30   virtual ~FieldPositionHandler();
31   virtual void addAttribute(int32_t id, int32_t start, int32_t limit) = 0;
32   virtual void shiftLast(int32_t delta) = 0;
33   virtual UBool isRecording(void) const = 0;
34 
35   void setShift(int32_t delta);
36 };
37 
38 
39 // utility subclass FieldPositionOnlyHandler
40 
41 class FieldPositionOnlyHandler : public FieldPositionHandler {
42   FieldPosition& pos;
43 
44  public:
45   FieldPositionOnlyHandler(FieldPosition& pos);
46   virtual ~FieldPositionOnlyHandler();
47 
48   void addAttribute(int32_t id, int32_t start, int32_t limit) U_OVERRIDE;
49   void shiftLast(int32_t delta) U_OVERRIDE;
50   UBool isRecording(void) const U_OVERRIDE;
51 };
52 
53 
54 // utility subclass FieldPositionIteratorHandler
55 
56 class FieldPositionIteratorHandler : public FieldPositionHandler {
57   FieldPositionIterator* iter; // can be NULL
58   UVector32* vec;
59   UErrorCode status;
60 
61   // Note, we keep a reference to status, so if status is on the stack, we have
62   // to be destroyed before status goes out of scope.  Easiest thing is to
63   // allocate us on the stack in the same (or narrower) scope as status has.
64   // This attempts to encourage that by blocking heap allocation.
65   void *operator new(size_t s);
66   void *operator new[](size_t s);
67 
68  public:
69   FieldPositionIteratorHandler(FieldPositionIterator* posIter, UErrorCode& status);
70   ~FieldPositionIteratorHandler();
71 
72   void addAttribute(int32_t id, int32_t start, int32_t limit) U_OVERRIDE;
73   void shiftLast(int32_t delta) U_OVERRIDE;
74   UBool isRecording(void) const U_OVERRIDE;
75 };
76 
77 U_NAMESPACE_END
78 
79 #endif /* !UCONFIG_NO_FORMATTING */
80 
81 #endif /* FPHDLIMP_H */
82