InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
InterfaceFactory.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Robin_Briggs
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 // Virtual constructors."
24 //
25 // Allows objects to be instantiated by name, rather than
26 // requiring a compiled in C++ class.
27 //
28 // The factory_construct function is placed in a dictionary, keyed
29 // by the name. When constructing by ID, the factory looks up
30 // the key name, finds the associated factory_construct function,
31 // and calls it.
32 //
33 //========================================================================================
34 
35 #ifndef __INTERFACEFACTORY__
36 #define __INTERFACEFACTORY__
37 
38 
39 #include "OMFactoryCtor.h"
40 
41 
42 #ifdef __clang__
43 
47 #endif
48 
63 public:
64  @param faceID The ID of the implementation
65  @param faceFact The factory function for constructing the implementation.
66  @param faceDestroy The function for destructing the implementation.
67  @param faceSizeOf The function for getting the sizeof the implementation.
68  @param faceReadWrite The ReadWrite function for the implementation (optional)
69  @param faceSnapshotReadWrite The Snapshot function for the implementation (optional)
70  @param faceRestVIewFun The ResetView function for the implementation (optional)
71  */
73  InterfaceConstructor faceFact,
74  InterfaceDestructor faceDestroy,
75  InterfaceSizeOf faceSizeOf,
76  InterfaceReadWrite faceReadWrite = nil,
77  InterfaceReadWrite faceSnapshotReadWrite = nil,
78  InterfaceResetViewFun resetViewFun = nil);
79 
80  //-------------------------------------------------------------------------------
82 
83 
84  static void InstallInterfaces(PluginID ownerComponent);
85 
86  const ImplementationID GetID() { return fID; }
87  const InterfaceConstructor GetFactory() { return fFactory; }
88  const InterfaceDestructor GetDestructor() { return fDestructor; }
89  const InterfaceSizeOf GetSizeOf() { return fSizeOf; }
90  const InterfaceReadWrite GetReadWrite() { return fReadWrite; }
91  const InterfaceReadWrite GetSnapshotReadWrite() { return fSnapshotReadWrite; }
92  const InterfaceResetViewFun GetInterfaceResetViewFun() { return fInterfaceResetViewFun;}
94 
96 
97 private:
98  const ImplementationID fID;
99  const InterfaceConstructor fFactory;
100  const InterfaceDestructor fDestructor;
101  const InterfaceSizeOf fSizeOf;
102  const InterfaceReadWrite fReadWrite;
103  const InterfaceReadWrite fSnapshotReadWrite;
104  const InterfaceResetViewFun fInterfaceResetViewFun;
105  InterfaceFactory *fNext;
106 #ifdef DEBUG
107  const char *fName;
108 #endif
109 
110 private:
111  static InterfaceFactory *gFirstInterface;
112 };
113 
114 
115 
116  //-------------------------------------------------------------------------------
118 
119 
120 #ifdef USE_ALLOCATE_WITH_BOSS
121 #define PRIVATE_DECLARE_PMINTERFACE(idstring) \
122  extern "C" { void* Create##idstring(void *memoryBuffer, IPMUnknown *boss); \
123  void Destroy##idstring(void *facePtr); \
124  int SizeOf##idstring(); }
125 #else
126 #define PRIVATE_DECLARE_PMINTERFACE(idstring) \
127  extern "C" { void* Create##idstring(IPMUnknown *boss); \
128  void Destroy##idstring(void *facePtr); \
129  int SizeOf##idstring(); }
130 #endif
131  // Creates a function declaration for the factory_construct and destructor
132  // functions.
133 
134 #define PRIVATE_HACK_PMINTERFACE(idstring) \
135  InterfaceFactory *Get##idstring##InterfaceFactory(); \
136  InterfaceFactory *Get##idstring##InterfaceFactory() { return &g##idstring##Factory; }
137  // Hack to make sure the static g## doesn't get stripped on link.
138 
139 #ifdef USE_ALLOCATE_WITH_BOSS
140 #define PRIVATE_DEFINE_PMINTERFACE(cn, idstring) \
141  extern "C" { void* Create##idstring(void *memoryBuffer, IPMUnknown *boss) \
142  { \
143  return new (memoryBuffer) cn(boss); \
144  } \
145  void Destroy##idstring(void *facePtr) \
146  { reinterpret_cast<cn*>(facePtr)->~cn(); } \
147  int SizeOf##idstring() \
148  { return sizeof (cn); } }
149 #else
150 #define PRIVATE_DEFINE_PMINTERFACE(cn, idstring) \
151  extern "C" { void* Create##idstring(IPMUnknown *boss) \
152  { \
153  return new cn(boss); \
154  } \
155  void Destroy##idstring(void *facePtr) \
156  { delete reinterpret_cast<cn*>(facePtr); } \
157  int SizeOf##idstring() \
158  { return sizeof (cn); } }
159 #endif
160 
161  // Creates a function definition for the factory_construct function.
162 
163 
164 #ifdef USE_ALLOCATE_WITH_BOSS
165 #define PRIVATE_DEFINE_VIEWINTERFACE(id, cn, idstring) \
166  extern "C" { void* Create##idstring(void *memoryBuffer, IPMUnknown *boss) \
167  { \
168  cn* face = new (memoryBuffer) cn(boss); \
169  /*fViewIFaceConsistencyChecker is used only to produce compiler errors \
170  if people use the wrong helper method declaraton type \
171  while using CREATE_VIEW_PMINTERFACE*/ \
172  face->fViewIFaceConsistencyChecker = nil;\
173  return face;\
174  } \
175  void Destroy##idstring(void *facePtr) \
176  { reinterpret_cast<cn*>(facePtr)->~cn(); } \
177  int SizeOf##idstring() \
178  { return sizeof (cn); } }
179 #else
180 #define PRIVATE_DEFINE_VIEWINTERFACE(id, cn, idstring) \
181  extern "C" { void* Create##idstring(IPMUnknown *boss) \
182  { \
183  cn* face = new cn(boss); \
184  /*fViewIFaceConsistencyChecker is used only to produce compiler errors \
185  if people use the wrong helper method declaraton type \
186  while using CREATE_VIEW_PMINTERFACE*/ \
187  face->fViewIFaceConsistencyChecker = nil;\
188  return face;\
189  } \
190  void Destroy##idstring(void *facePtr) \
191  { delete reinterpret_cast<cn*>(facePtr); } \
192  int SizeOf##idstring() \
193  { return sizeof (cn); } }
194 #endif
195 
196 #ifdef USE_ALLOCATE_WITH_BOSS
197 #define PRIVATE_DEFINE_PERSIST_DONTSNAPSHOT_PMINTERFACE(cn, idstring) \
198  extern "C" { void* Create##idstring(void *memoryBuffer, IPMUnknown *boss) \
199  { \
200  cn* face = new (memoryBuffer) cn(boss); \
201  /*fDontSnapshotIFaceConsistencyChecker is used only to produce compiler errors \
202  if people use the wrong helper method declaraton type \
203  while using CREATE_PERSIST_DONTSNAPSHOT_PMINTERFACE*/ \
204  face->fDontSnapshotIFaceConsistencyChecker = nil;\
205  return face;\
206  } \
207  void Destroy##idstring(void *facePtr) \
208  { reinterpret_cast<cn*>(facePtr)->~cn(); } \
209  int SizeOf##idstring() \
210  { return sizeof (cn); } }
211 #else
212 #define PRIVATE_DEFINE_PERSIST_DONTSNAPSHOT_PMINTERFACE(cn, idstring) \
213  extern "C" { void* Create##idstring(IPMUnknown *boss) \
214  { \
215  cn* face = new cn(boss); \
216  /*fDontSnapshotIFaceConsistencyChecker is used only to produce compiler errors \
217  if people use the wrong helper method declaraton type \
218  while using CREATE_PERSIST_DONTSNAPSHOT_PMINTERFACE*/ \
219  face->fDontSnapshotIFaceConsistencyChecker = nil;\
220  return face;\
221  } \
222  void Destroy##idstring(void *facePtr) \
223  { delete reinterpret_cast<cn*>(facePtr); } \
224  int SizeOf##idstring() \
225  { return sizeof (cn); } }
226 #endif
227 
228 
229  static InterfaceFactory g##idstring##Factory(id, Create##idstring, (InterfaceDestructor)Destroy##idstring, (InterfaceSizeOf)SizeOf##idstring);
230 
231 
232 #define PRIVATE_DECLARE_READWRITE(cn, idstring) \
233  void ReadWrite##idstring(cn *obj, IPMStream *s, ImplementationID prop, int32 length);
234  // Creates a function declaration for the ReadWrite function.
235 
236 #define PRIVATE_DECLARE_SNAPSHOTREADWRITE(cn, idstring) \
237  void SnapshotReadWrite##idstring(cn *obj, IPMStream *s, ImplementationID prop, int32 length);
238  // Creates a function declaration for the SnapshotReadWrite function.
239 
240 #define PRIVATE_DECLARE_RESETVIEWFUN(cn, idstring) \
241  void ResetViewFun##idstring(cn *obj, ImplementationID prop);
242  // Creates a function declaration for the ResetView function.
243 
244 #define PRIVATE_DEFINE_READWRITE(cn, idstring) \
245  void ReadWrite##idstring(cn *obj, IPMStream *s, ImplementationID prop, int32 /*length*/) \
246  { obj->ReadWrite(s, prop); }
247  // Creates a function definition for the ReadWrite function
248 
249 #define PRIVATE_DEFINE_SNAPSHOTREADWRITE(cn, idstring) \
250  void SnapshotReadWrite##idstring(cn *obj, IPMStream *s, ImplementationID prop, int32 /*length*/) \
251  { obj->SnapshotReadWrite(s, prop); }
252  // Creates a function definition for the SnapshotReadWrite function
253 
254 #define PRIVATE_DEFINE_RESETVIEWFUN(cn, idstring) \
255  void ResetViewFun##idstring(cn *obj, ImplementationID prop) \
256  { obj->ResetView(prop); }
257  // Creates a function definition for the ResetView function
258 
259 #define PRIVATE_REGISTER_PERSIST_PMINTERFACE(id, idstring) \
260  static InterfaceFactory g##idstring##Factory(id, Create##idstring, (InterfaceDestructor)Destroy##idstring, (InterfaceSizeOf)SizeOf##idstring, (InterfaceReadWrite)ReadWrite##idstring, (InterfaceReadWrite)nil, (InterfaceResetViewFun)nil);
261 
262 #define PRIVATE_REGISTER_PERSIST_SNAPSHOT_PMINTERFACE(id, idstring) \
263  static InterfaceFactory g##idstring##Factory(id, Create##idstring, (InterfaceDestructor)Destroy##idstring, (InterfaceSizeOf)SizeOf##idstring, (InterfaceReadWrite)ReadWrite##idstring, (InterfaceReadWrite)SnapshotReadWrite##idstring, (InterfaceResetViewFun)nil);
264 
265 #define PRIVATE_REGISTER_SNAPSHOT_PMINTERFACE(id, idstring) \
266  static InterfaceFactory g##idstring##Factory(id, Create##idstring, (InterfaceDestructor)Destroy##idstring, (InterfaceSizeOf)SizeOf##idstring, (InterfaceReadWrite) nil, (InterfaceReadWrite)SnapshotReadWrite##idstring, (InterfaceResetViewFun)nil);
267 
268 #define PRIVATE_REGISTER_VIEW_PMINTERFACE(id, idstring) \
269  static InterfaceFactory g##idstring##Factory(id, Create##idstring, (InterfaceDestructor)Destroy##idstring, (InterfaceSizeOf)SizeOf##idstring, (InterfaceReadWrite) nil, (InterfaceReadWrite)SnapshotReadWrite##idstring, (InterfaceResetViewFun)ResetViewFun##idstring);
270 
271 #define BUILD_PMINTERFACE(idstring) \
272  InterfaceFactory *Get##idstring##InterfaceFactory(); \
273  Get##idstring##InterfaceFactory();
274 
276 
277  XXXFactory.h file which has declarations for the implementations it contains.
278  @param cn C++ class used for the implementation
279  @param id ImplementationID of the implementation
280 */
281 #ifdef __ODFRC__
282  id
283 #else
284  BUILD_PMINTERFACE(id##_)
285 #endif
286 
287  //-------------------------------------------------------------------------------
289 
290 
291 #define REFERENCE_PMINTERFACE(id) \
292  BUILD_PMINTERFACE(id##_)
293 
295 
296  This is the default way to declare your implementation.
297  @param cn C++ class used for the implementation
298  @param id ImplementationID of the implementation
299 */
300  PRIVATE_DECLARE_PMINTERFACE(id##_) \
301  PRIVATE_DEFINE_PMINTERFACE(cn, id##_) \
302  PRIVATE_HACK_PMINTERFACE(id##_)
303 
304  object model. Use this if your implementation has a ReadWrite method.
305  @param cn C++ class used for the implementation
306  @param id ImplementationID of the implementation
307 */
308  PRIVATE_DECLARE_PMINTERFACE(id##_) \
309  PRIVATE_DECLARE_READWRITE(cn, id##_) \
310  PRIVATE_DEFINE_PMINTERFACE(cn, id##_) \
311  PRIVATE_DEFINE_READWRITE(cn, id##_) \
312  PRIVATE_REGISTER_PERSIST_PMINTERFACE(id, id##_) \
313  PRIVATE_HACK_PMINTERFACE(id##_)
314 
315 
320 #define CREATE_PERSIST_SNAPSHOT_PMINTERFACE(cn, id) \
321  PRIVATE_DECLARE_PMINTERFACE(id##_) \
322  PRIVATE_DECLARE_READWRITE(cn, id##_) \
323  PRIVATE_DECLARE_SNAPSHOTREADWRITE(cn, id##_) \
324  PRIVATE_DEFINE_PMINTERFACE(cn, id##_) \
325  PRIVATE_DEFINE_READWRITE(cn, id##_) \
326  PRIVATE_DEFINE_SNAPSHOTREADWRITE(cn, id##_) \
327  PRIVATE_REGISTER_PERSIST_SNAPSHOT_PMINTERFACE(id, id##_) \
328  PRIVATE_HACK_PMINTERFACE(id##_)
329 
335 #define CREATE_SNAPSHOT_PMINTERFACE(cn, id) \
336  PRIVATE_DECLARE_PMINTERFACE(id##_) \
337  PRIVATE_DECLARE_SNAPSHOTREADWRITE(cn, id##_) \
338  PRIVATE_DEFINE_PMINTERFACE(cn, id##_) \
339  PRIVATE_DEFINE_SNAPSHOTREADWRITE(cn, id##_) \
340  PRIVATE_REGISTER_SNAPSHOT_PMINTERFACE(id, id##_) \
341  PRIVATE_HACK_PMINTERFACE(id##_)
342 
348 #define CREATE_VIEW_PMINTERFACE(cn, id) \
349  PRIVATE_DECLARE_PMINTERFACE(id##_) \
350  PRIVATE_DECLARE_SNAPSHOTREADWRITE(cn, id##_) \
351  PRIVATE_DECLARE_RESETVIEWFUN(cn, id##_) \
352  PRIVATE_DEFINE_VIEWINTERFACE(id, cn, id##_) \
353  PRIVATE_DEFINE_SNAPSHOTREADWRITE(cn, id##_) \
354  PRIVATE_DEFINE_RESETVIEWFUN(cn, id##_) \
355  PRIVATE_REGISTER_VIEW_PMINTERFACE(id, id##_) \
356  PRIVATE_HACK_PMINTERFACE(id##_)
357 
358  //-------------------------------------------------------------------------------
360 
361 
362 #define EXPORT_PMINTERFACE(cn, id) \
363  PRIVATE_DECLARE_PMINTERFACE(id##_) \
364  PRIVATE_DEFINE_PMINTERFACE(cn, id##_)
365 
366 #define IMPORT_PMINTERFACE(cn, id) \
367  PRIVATE_DECLARE_PMINTERFACE(id##_) \
368  PRIVATE_HACK_PMINTERFACE(id##_)
369 
371 
372 
379 #define CREATE_PERSIST_DONTSNAPSHOT_PMINTERFACE(cn, id) \
380  PRIVATE_DECLARE_PMINTERFACE(id##_) \
381  PRIVATE_DECLARE_READWRITE(cn, id##_) \
382  PRIVATE_DEFINE_PERSIST_DONTSNAPSHOT_PMINTERFACE(cn, id##_) \
383  PRIVATE_DEFINE_READWRITE(cn, id##_) \
384  PRIVATE_REGISTER_PERSIST_PMINTERFACE(id, id##_) \
385  PRIVATE_HACK_PMINTERFACE(id##_)
386 #endif // __INTERFACEFACTORY__
387