Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccArrayFactory.cpp
Go to the documentation of this file.
1/** @file
2 File: IccArrayFactory.cpp
3
4 Contains: Implementation of the IIccArray handler creation factories
5
6 Version: V1
7
8 Copyright: (c) see ICC Software License
9*/
10
11/*
12 * The ICC Software License, Version 0.2
13 *
14 *
15 * Copyright (c) 2003-2012 The International Color Consortium. All rights
16 * reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 *
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 *
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in
27 * the documentation and/or other materials provided with the
28 * distribution.
29 *
30 * 3. In the absence of prior written permission, the names "ICC" and "The
31 * International Color Consortium" must not be used to imply that the
32 * ICC organization endorses or promotes products derived from this
33 * software.
34 *
35 *
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 * DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40 * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This software consists of voluntary contributions made by many
51 * individuals on behalf of the The International Color Consortium.
52 *
53 *
54 * Membership in the ICC is encouraged when this software is used for
55 * commercial purposes.
56 *
57 *
58 * For more information on The International Color Consortium, please
59 * see <http://www.color.org/>.
60 *
61 *
62 */
63
64//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -July 27, 2011
68// Added IIccArray Creation using factory support
69//
70//////////////////////////////////////////////////////////////////////
71
72#include "IccTagComposite.h"
73#include "IccArrayBasic.h"
74#include "IccArrayFactory.h"
75#include "IccUtil.h"
76#include "IccProfile.h"
77#include <string.h>
78
79#ifdef USEREFICCMAXNAMESPACE
80namespace refIccMAX {
81#endif
82
84{
85 switch(arrayTypeSig) {
87 return new CIccArrayNamedColor(pTagArray);
88
90 return new CIccArrayColorantInfo(pTagArray);
91
92 default:
93 return new CIccArrayUnknown(pTagArray, arrayTypeSig);
94 }
95}
96
97
98static struct {
101} g_icArrayNames[] = {
102 { icSigColorantInfoArray, "colorantInfoArray" },
103 { icSigNamedColorArray, "namedColorArray" },
104 { icSigUtf8TextTypeArray, "UTF8TextArray" },
105 { (icArraySignature)0, "" },
107
108bool CIccBasicArrayFactory::GetArraySigName(std::string &arrayName, icArraySignature arrayTypeSig, bool bFindUnknown)
109{
110 int i;
111 for (i = 0; g_icArrayNames[i].sig; i++) {
112 if (g_icArrayNames[i].sig == arrayTypeSig) {
113 arrayName = g_icArrayNames[i].szArrayName;
114 return true;
115 }
116 }
117
118 if (!bFindUnknown) {
119 char sig[20];
120 arrayName = "UnknownStruct_";
121 icGetSigStr(sig, arrayTypeSig);
122 arrayName += sig;
123 }
124 else {
125 arrayName = "";
126 }
127
128 return false;
129}
130
132{
133 int i;
134 for (i = 0; g_icArrayNames[i].sig; i++) {
135 if (!strcmp(g_icArrayNames[i].szArrayName, szArrayName)) {
136 return g_icArrayNames[i].sig;
137 }
138 }
139 return (icArraySignature)0;
140}
141
142
143std::unique_ptr<CIccArrayCreator> CIccArrayCreator::theArrayCreator;
144
146{
147 IIccArrayFactory *pFactory = DoPopFactory(true);
148
149 while (pFactory) {
150 delete pFactory;
151 pFactory = DoPopFactory(true);
152 }
153}
154
156{
157 if (!theArrayCreator.get()) {
158 theArrayCreator = CIccArrayCreatorPtr(new CIccArrayCreator);
159
160 theArrayCreator->DoPushFactory(new CIccBasicArrayFactory);
161 }
162
163 return theArrayCreator.get();
164}
165
167{
168 CIccArrayFactoryList::iterator i;
169 IIccArray *rv = NULL;
170
171 for (i=factoryStack.begin(); i!=factoryStack.end(); i++) {
172 rv = (*i)->CreateArray(arrayTypeSig, pTagArray);
173 if (rv)
174 break;
175 }
176 return rv;
177}
178
179bool CIccArrayCreator::DoGetArraySigName(std::string &arrayName, icArraySignature arrayTypeSig, bool bFillUnknown)
180{
181 CIccArrayFactoryList::iterator i;
182
183 for (i=factoryStack.begin(); i!=factoryStack.end(); i++) {
184 if ((*i)->GetArraySigName(arrayName, arrayTypeSig, bFillUnknown))
185 return true;
186 }
187
188 return false;
189}
190
192{
193 CIccArrayFactoryList::iterator i;
194
195 for (i = factoryStack.begin(); i != factoryStack.end(); i++) {
196 icArraySignature rv = (*i)->GetArraySig(structName);
197 if (rv)
198 return rv;
199 }
200
201 return (icArraySignature)0;
202}
203
204
206{
207 factoryStack.push_front(pFactory);
208}
209
211{
212 if (factoryStack.size()>0) {
213 CIccArrayFactoryList::iterator i=factoryStack.begin();
214 IIccArrayFactory* rv = (*i);
215 factoryStack.pop_front();
216 return rv;
217 }
218 return NULL;
219}
220
221#ifdef USEREFICCMAXNAMESPACE
222} //namespace refIccMAX
223#endif
File: IccArrayBasic.h.
const icChar * szArrayName
static struct @0 g_icArrayNames[]
icArraySignature sig
File: IccArrayFactory.h.
std::unique_ptr< CIccArrayCreator > CIccArrayCreatorPtr
char icChar
Definition IccDefs.h:109
File: IccProfile.h.
File: IccTagComposite.h.
const icChar * icGetSigStr(icChar *pBuf, icUInt32Number nSig)
Definition IccUtil.cpp:1056
File: IccUtil.h.
Class: CIccArrayColorantInfo.
Class: CIccArrayCreator.
bool DoGetArraySigName(std::string &arrayName, icArraySignature arrayTypeSig, bool bFillUnknown=true)
icArraySignature DoGetArraySig(const icChar *arrayName)
static CIccArrayCreatorPtr theArrayCreator
void DoPushFactory(IIccArrayFactory *pFactory)
IIccArray * DoCreateArray(icArraySignature arrayTypeSig, CIccTagArray *pArray)
IIccArrayFactory * DoPopFactory(bool bAll=false)
static CIccArrayCreator * GetInstance()
Function: GetInstance() Private static function to access singleton CiccArrayCreator Object.
Class: CIccArrayNamedColor.
Class: CIccArrayUnknown.
Class: CIccBasicArrayFactory.
virtual bool GetArraySigName(std::string &arrayName, icArraySignature arrayTypeSig, bool bFindUnknown=true)
Function: GetArraySigName(arrayName, arrayTypeSig, bFindUnknown) Get display name of arrayTypeSig.
virtual IIccArray * CreateArray(icArraySignature arrayTypeSig, CIccTagArray *pTagArray=NULL)
Function: CreateArray(arrayTypeSig) Create an array object handler of type arrayTypeSig.
virtual icArraySignature GetArraySig(const icChar *arrayName)
Function: GetArraySig(arrayName) Get signature associate with display name arrayName handler.
Class: CIccTagArray.
Class: IIccArrayFactory.
Class: IIccArray.
icArraySignature
Tag Array type signatures.
@ icSigColorantInfoArray
@ icSigNamedColorArray
@ icSigUtf8TextTypeArray