Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccStructFactory.cpp
Go to the documentation of this file.
1/** @file
2 File: IccStructFactory.cpp
3
4 Contains: Implementation of the IIccStructObject class and 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// -June 4, 2011
68// Added IIccStructObject Creation using factory support
69//
70//////////////////////////////////////////////////////////////////////
71
72#include "IccTagComposite.h"
73#include "IccStructBasic.h"
74#include "IccStructFactory.h"
75#include "IccUtil.h"
76#include "IccProfile.h"
77#include <cstring>
78
79#ifdef USEREFICCMAXNAMESPACE
80namespace refIccMAX {
81#endif
82
84{
85 switch(structTypeSig) {
86 case icSigBRDFStruct:
87 return new CIccStructBRDF(pTagStruct);
88
90 return new CIccStructColorantInfo(pTagStruct);
91
93 return new CIccStructColorEncodingParams(pTagStruct);
94
96 return new CIccStructMeasurementInfo(pTagStruct);
97
99 return new CIccStructNamedColor(pTagStruct);
100
102 return new CIccStructProfileInfo(pTagStruct);
103
105 return new CIccStructTintZero(pTagStruct);
106
107 default:
108 return new CIccStructUnknown(pTagStruct);
109 }
110}
111
112static struct {
115} g_icStructNames[] = {
116 {icSigBRDFStruct, "brdfTransfromStructure"},
117 {icSigColorantInfoStruct, "colorantInfoStruct"},
118 {icSigBRDFStruct, "brfdfTransformStructure"},
119 {icSigColorantInfoStruct, "colorantInfoStructure"},
120 {icSigColorEncodingParamsSruct, "colorEncodingParamsStructure"},
121 {icSigMeasurementInfoStruct, "measurementInfoStructure"},
122 {icSigNamedColorStruct, "namedColorStructure"},
123 {icSigProfileInfoStruct, "profileInfoStructure"},
124 {icSigTintZeroStruct, "tintZeroStructure"},
125 {(icStructSignature)0, ""},
127
128bool CIccBasicStructFactory::GetStructSigName(std::string &structName, icStructSignature structTypeSig, bool bFindUnknown)
129{
130 int i;
131 for (i = 0; g_icStructNames[i].sig; i++) {
132 if (g_icStructNames[i].sig == structTypeSig) {
133 structName = g_icStructNames[i].szStructName;
134 return true;
135 }
136 }
137
138 if (!bFindUnknown) {
139 char sig[20];
140 structName = "UnknownStruct_";
141 icGetSigStr(sig, structTypeSig);
142 structName += sig;
143 }
144 else {
145 structName = "";
146 }
147
148 return false;
149}
150
152{
153 int i;
154 for (i = 0; g_icStructNames[i].sig; i++) {
155 if (!strcmp(g_icStructNames[i].szStructName, szStructName)) {
156 return g_icStructNames[i].sig;
157 }
158 }
159 return (icStructSignature)0;
160}
161
162
163std::unique_ptr<CIccStructCreator> CIccStructCreator::theStructCreator;
164
166{
167 IIccStructFactory *pFactory = DoPopFactory(true);
168
169 while (pFactory) {
170 delete pFactory;
171 pFactory = DoPopFactory(true);
172 }
173}
174
176{
177 if (!theStructCreator.get()) {
178 theStructCreator = CIccStructCreatorPtr(new CIccStructCreator);
179
180 theStructCreator->DoPushFactory(new CIccBasicStructFactory);
181 }
182
183 return theStructCreator.get();
184}
185
187{
188 CIccStructFactoryList::iterator i;
189 IIccStruct *rv = NULL;
190
191 for (i=factoryStack.begin(); i!=factoryStack.end(); i++) {
192 rv = (*i)->CreateStruct(structTypeSig, pTagStruct);
193 if (rv)
194 break;
195 }
196 return rv;
197}
198
199bool CIccStructCreator::DoGetStructSigName(std::string &structName, icStructSignature structTypeSig, bool bFillUnknown)
200{
201 CIccStructFactoryList::iterator i;
202
203 for (i=factoryStack.begin(); i!=factoryStack.end(); i++) {
204 if ((*i)->GetStructSigName(structName, structTypeSig, bFillUnknown))
205 return true;
206 }
207
208 return false;
209}
210
212{
213 CIccStructFactoryList::iterator i;
214
215 for (i = factoryStack.begin(); i != factoryStack.end(); i++) {
216 icStructSignature rv = (*i)->GetStructSig(structName);
217 if (rv)
218 return rv;
219 }
220
221 return (icStructSignature)0;
222}
223
225{
226 factoryStack.push_front(pFactory);
227}
228
230{
231 if (factoryStack.size()>0) {
232 CIccStructFactoryList::iterator i=factoryStack.begin();
233 IIccStructFactory* rv = (*i);
234 factoryStack.pop_front();
235 return rv;
236 }
237 return NULL;
238}
239
240#ifdef USEREFICCMAXNAMESPACE
241} //namespace refIccMAX
242#endif
icArraySignature sig
char icChar
Definition IccDefs.h:109
File: IccProfile.h.
File: IccStructBasic.h.
const icChar * szStructName
static struct @3 g_icStructNames[]
File: IccStructFactory.h.
std::unique_ptr< CIccStructCreator > CIccStructCreatorPtr
File: IccTagComposite.h.
const icChar * icGetSigStr(icChar *pBuf, icUInt32Number nSig)
Definition IccUtil.cpp:1056
File: IccUtil.h.
Class: CIccBasicStructFactory.
virtual bool GetStructSigName(std::string &structName, icStructSignature structTypeSig, bool bFindUnknown=false)
Function: GetStructSigName(structTypeSig) Get display name of structTypeSig.
virtual IIccStruct * CreateStruct(icStructSignature structSig, CIccTagStruct *pTagStruct=NULL)
Function: CreateStruct(structTypeSig) Create a struct object of type structTypeSig.
virtual icStructSignature GetStructSig(const icChar *structName)
Function: GetStructSig(structName) Get signature of structure from display name.
Class: CIccStructBRDF.
Class: CIccStructColorEncodingParams.
Class: CIccStructColorantInfo.
Class: CIccStructCreator.
IIccStructFactory * DoPopFactory(bool bAll=false)
static CIccStructCreator * GetInstance()
Function: GetInstance() Private static function to access singleton CiccStructCreator Object.
static CIccStructCreatorPtr theStructCreator
icStructSignature DoGetStructSig(const char *structName)
void DoPushFactory(IIccStructFactory *pFactory)
IIccStruct * DoCreateStruct(icStructSignature structTypeSig, CIccTagStruct *pTagStruct=NULL)
bool DoGetStructSigName(std::string &structName, icStructSignature structTypeSig, bool bFillUnknown=true)
Class: CIccStructMeasurementInfo.
Class: CIccStructNamedColor.
Class: CIccStructProfileInfo.
Class: CIccStructTintZero.
Class: CIccStructUnknown.
Class: CIccTagStruct.
Class: IIccStructFactory.
Class: IIccStruct.
icStructSignature
Tag Structure type signatures.
@ icSigMeasurementInfoStruct
@ icSigColorantInfoStruct
@ icSigTintZeroStruct
@ icSigNamedColorStruct
@ icSigBRDFStruct
@ icSigProfileInfoStruct
@ icSigColorEncodingParamsSruct