-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhotoUtilsSuites.h
85 lines (75 loc) · 2 KB
/
PhotoUtilsSuites.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ****************************************************************************
// By Antonino Perricone
// http://amicoperry.altervista.org/luce/
//
// This work is licensed under the Creative Commons
// Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// To view a copy of this license, visit
// http://creativecommons.org/licenses/by-nc-sa/3.0/.
// ****************************************************************************
#pragma once
// A better template for acquiring and release suites.
// Depends on a globally defined CPhotoshopLuce::GetBasicSuite() pointer.
// Illustrator example
// AutoSuite<AITextPathSuite> sAITextPath(kAITextPathSuite, kAITextPathSuiteVersion);
// AutoSuite will throw on bad access
// if you were using MySuite switch to AutoSuite
template<class T> class AutoSuite
{
private:
T * suite;
const long suiteVersion;
const char * suiteName;
SPErr error;
// make sure the compiler doesn't create this
AutoSuite();
void AcquireSuite(void)
{
if (CPhotoshopLuce::GetBasicSuite() != NULL)
{
error = CPhotoshopLuce::GetBasicSuite()->AcquireSuite(suiteName,
suiteVersion,
(const void**)&suite);
}
else
{
error = kSPBadParameterError;
}
}
public:
AutoSuite(const char * name, const long version) :
suite(NULL), suiteName(name), suiteVersion(version), error(0)
{ }
~AutoSuite()
{
Unload();
}
const T * operator->()
{
if (suite == NULL)
AcquireSuite();
return suite;
}
const T * operator *()
{
if (suite == NULL)
AcquireSuite();
return suite;
}
void Unload(void)
{
if (suite != NULL && suiteName != NULL &&
CPhotoshopLuce::GetBasicSuite() != NULL)
{
CPhotoshopLuce::GetBasicSuite()->ReleaseSuite(suiteName, suiteVersion);
suite = NULL;
}
}
bool IsSupported()
{
if( suite != NULL ) return true;
AcquireSuite();
return ( suite != NULL );
}
SPErr GetError() { return error; }
};