InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Utils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Matt Joss
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 // Purpose:
24 // This is a helper class for calling methods in interfaces on the kUtilsBoss. The Utils boss is an easy way
25 // to share Utils across plugins without putting them in Public.
26 // The syntax to use is...
27 // Utils<IFooUtils>()->MyFooMethod()
28 //
29 //========================================================================================
30 
31 #ifndef __Utils__
32 #define __Utils__
33 
34 
35 #include "ShuksanID.h"
36 #include "InterfacePtr.h"
37 #include "IPMUnknown.h"
38 #include "PMTypes.h"
39 #ifdef DEBUG
40  #include "ISession.h"
41 #endif
42 
47 class UtilsBoss
48 {
49 public:
53  static void Purge();
54 
59  static IPMUnknown * QueryUtils( const PMIID& utilsIID );
60 };
61 
62 
63 
81 template <class IFace>
82 class Utils
83 {
84 public:
86  inline Utils() { fFace = UtilsBoss::QueryUtils(IFace::kDefaultIID); }
88  inline ~Utils() { if(fFace) fFace->Release(); }
89 
94  inline IFace * operator ->() const { return static_cast<IFace*>(fFace); }
95 
100  inline operator IFace*() { return static_cast<IFace*>(fFace); }
101 
106  inline bool16 Exists() const { return fFace != nil; }
107 
115  inline IFace *QueryUtilInterface() { fFace->AddRef(); return static_cast<IFace*>(fFace); }
116 
117 private:
118  Utils<IFace>& operator=(const Utils<IFace>& other); // don't support this
119  Utils<IFace>(const Utils<IFace>& copy); // don't support this
120 
121  IPMUnknown* fFace;
122 };
123 
124 
125 
126 #endif //__Utils__
127 
128