InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CPMUnknown.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Mat Marcus
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __CPMUnknown__
25 #define __CPMUnknown__
26 
27 
60 #include "HelperInterface.h"
61 
62 
63 // Helper class for manaaging multiple PreDirty calls
64 class DirtyOptimizer : boost::noncopyable
65 {
66 public:
67 
68  DirtyOptimizer (IPMUnknown *face) :
69  fFace (face),
70  fDirtied (false)
71  {
72  }
73 
74  inline void PreDirty (ImplementationID prop = kInvalidImpl, bool16 allowModification = kTrue)
75  {
76  if (!fDirtied)
77  {
78  ::PreDirty (fFace, prop, allowModification);
79  fDirtied = true;
80  }
81  }
82 
83  inline void PreDirtyNoMessage (ImplementationID prop = kInvalidImpl, bool16 allowModification = kTrue)
84  {
85  if (!fDirtied)
86  {
87  ::PreDirtyNoMessage (fFace, prop, allowModification);
88  fDirtied = true;
89  }
90  }
91 
92 private:
93 
94  IPMUnknown *fFace;
95  bool fDirtied;
96 };
97 
98 
99 //========================================================================================
100 // CPMUnknown
101 //========================================================================================
102 
103 template <class Interface>
104 class CPMUnknown : public Interface
105 {
106 public:
108  IPMUnknown *QueryInterface(PMIID interfaceID) const;
110  void AddRef() const;
112  void Release() const;
113  void PreDirty(ImplementationID prop = kInvalidImpl, bool16 allowModification = kTrue);
114  void PreDirtyNoMessage(ImplementationID prop = kInvalidImpl, bool16 allowModification = kTrue);
115 
116  // Don't allow default construction, copy construction or assignment...
117  CPMUnknown() = delete;
118  CPMUnknown(const CPMUnknown &) = delete;
119  CPMUnknown &operator =(const CPMUnknown &) = delete;
120 
121 protected:
122  explicit CPMUnknown(IPMUnknown *boss);
123  HelperInterface fHelperInterface;
124 };
125 
126 //========================================================================================
127 // CPMUnknown implementation
128 //========================================================================================
129 
130 template <class Interface>
132  fHelperInterface(boss)
133 {
134 }
135 
136 template <class Interface>
138 {
139  fHelperInterface.AddRef();
140 }
141 
142 template <class Interface>
144 {
145  fHelperInterface.Release();
146 }
147 
148 template <class Interface>
149 void CPMUnknown<Interface>::PreDirty(ImplementationID prop, bool16 allowModification)
150 {
151  ::PreDirty(this, prop, allowModification);
152 }
153 
154 template <class Interface>
155 void CPMUnknown<Interface>::PreDirtyNoMessage(ImplementationID prop, bool16 allowModification)
156 {
157  ::PreDirtyNoMessage(this, prop, allowModification);
158 }
159 
160 template <class Interface>
162 {
163 #ifdef DEBUG
164  if (interfaceID == IID_IGETINTERFACEIMPL)
165  return const_cast<CPMUnknown<Interface> *>(this);
166 #endif
167 
168  return fHelperInterface.QueryInterface(interfaceID);
169 }
170 
171 #endif //__CPMUnknown__