ColourContextList Class Reference

Defines a list of colour contexts, as must be kept on a global basis. This is a perfectly normal list, except it has a special function to add a ColourContext item to the list, which ensures that no duplicate colour contexts are ever used, and that the usage count for any shared context is properly updated. More...

#include <colcontx.h>

Inheritance diagram for ColourContextList:

List CCObject SimpleCCObject List of all members.

Public Member Functions

void AddContext (ColourContext **NewContext)
 "Adds" the given colour context to the global list of available contexts. Note that if an identical context is already present in the list, the passed context will be DELETEd and the existing context will be returned in the given pointer. Thus, you must only ever access the context through the returned pointer, rather than the pointer that you originally allocated with 'new'.
void RemoveContext (ColourContext **OldContext)
 "Removes" the given colour context to the global list of available contexts. If the context is now no longer in use by anyone, it will be 'delete'd. The context pointer passed in will be set to NULL.

Static Public Member Functions

static BOOL InitColourContexts (void)
 Initialises the Colour Context system, setting up the global list of default colour contexts which are shared by all documents. Called from app.cpp (must not be called more than once).
static void DeinitColourContexts (void)
 De-initialises the Colour Context system, deleting the global list of default colour contexts which are shared by all documents. It is assumed that by this time the contexts should not be in use! Called from app.cpp (must not be caled more than once).
static ColourContextListGetList (void)
 Find the 'global' list of current colour contexts.

Static Private Attributes

static ColourContextListColContextList = NULL

Detailed Description

Defines a list of colour contexts, as must be kept on a global basis. This is a perfectly normal list, except it has a special function to add a ColourContext item to the list, which ensures that no duplicate colour contexts are ever used, and that the usage count for any shared context is properly updated.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/04/94
See also:
ColourContextList::AddContext; ColourContextList::RemoveContext; List; Colour; ColourModel; ColourContext Documentation: HowToUse.doc

Definition at line 831 of file colcontx.h.


Member Function Documentation

void ColourContextList::AddContext ColourContext **  NewContext  ) 
 

"Adds" the given colour context to the global list of available contexts. Note that if an identical context is already present in the list, the passed context will be DELETEd and the existing context will be returned in the given pointer. Thus, you must only ever access the context through the returned pointer, rather than the pointer that you originally allocated with 'new'.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/04/94
Parameters:
- [INPUTS]
An equivalent colour context that may now be used [OUTPUTS]
Returns:
-
i.e. to create and use a new context, you must: { ColourContext *MyContext;

MyContext = new ColourContextABCD(1.0); // Create new context if (MyContext == NULL) return(FAILED_MISERABLY);

ColContextList->AddContext(&MyContext); // MyContext may change!

MyContext->DoSomething... // Use the context

ColContextList->RemoveContext(&MyContext); // Have finished with it

MyContext is now a NULL pointer, so don't use it! }

Notes: You must NOT delete the context when you finish with it. Instead, you must call ColourContextList::RemoveContext() when you have finished with the context. The context will be automatically deleted when it is no longer in use by anyone.

(Sharing of contexts is currently disabled - see the comment in the function for details)

Returns:
Errors: -
See also:
ColourContext::ConvertColour; ColourContext::ConvertColourInternal

Definition at line 323 of file colclist.cpp.

00324 {
00325     ENSURE(NewContext != NULL && *NewContext != NULL,
00326                 "ColourContextList::AddContext called with NULL parameter!");
00327 
00328 #if FALSE
00329 /*
00330     Jason 22/5/96
00331     We no longer merge contexts because this makes for danger with the new ColourPlate
00332     system - it's now too easy to change a colourcontext by altering its ColourPlate,
00333     in which case shared contexts will cause extreme grief.
00334 
00335     ColourContext *Item;
00336 
00337     Item = (ColourContext *) GetHead();
00338 
00339     while (Item)
00340     {
00341         if (!Item->IsDifferent(*NewContext))    // Have found identical context
00342         {
00343             delete *NewContext;         // Delete the new context
00344             Item->IncrementUsage();     // Increment the new context's usage count
00345             *NewContext = Item;         // And return the existing one for use
00346             return;
00347         }
00348 
00349         Item = (ColourContext *) GetNext(Item);
00350     }
00351 
00352     // We have searched the entore list now but still have no equivalent context
00353     // so it is necessary to add this context to the list, and return it.
00354 */
00355 #endif
00356 
00357     // However, we do check that the given context is not already in the list,
00358     // and ignore the caller if it's already there.
00359     ColourContext *Item;
00360 
00361     Item = (ColourContext *) GetHead();
00362 
00363     while (Item)
00364     {
00365         if (Item == *NewContext)
00366         {
00367             Item->IncrementUsage();     // Increment the context's usage count
00368             return;
00369         }
00370 
00371         Item = (ColourContext *) GetNext(Item);
00372     }
00373 
00374     AddTail(*NewContext);
00375     (*NewContext)->Init();
00376 
00377     // And by leaving the contents of the passed pointer alone, we return it.
00378 }

void ColourContextList::DeinitColourContexts void   )  [static]
 

De-initialises the Colour Context system, deleting the global list of default colour contexts which are shared by all documents. It is assumed that by this time the contexts should not be in use! Called from app.cpp (must not be caled more than once).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/04/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: If any colour contexts are still in use when this function is called, you may get ENSURE failures.

Definition at line 228 of file colclist.cpp.

00229 {
00230     ENSURE(ColContextList != NULL, "ColourContextList::DeinitColourContexts: but I haven't been initialised yet!");
00231 
00232     ColourContextArray  DefaultCCA;
00233     ColourContext       *DefaultCC;
00234 
00235     ColourContext::GetGlobalDefaults(&DefaultCCA);
00236 
00237     // Delete any of the default colour contexts that actually exist...
00238     for (INT32 cm = 0; cm < MAX_COLOURMODELS; cm++)
00239     {
00240         // Get the default colour context object for this colour model number
00241         // I do this via a copy of the real array to avoid the GetDefaultContext()
00242         // call giving an ENSURE failure in the case of a NULL context pointer.
00243         DefaultCC = DefaultCCA.Context[cm];
00244     
00245         if (DefaultCC != NULL)
00246         {
00247             // Set the default to NULL to ensure fewer rampant pointers are
00248             // left lying around (just to be on the safe side)
00249             ColourContext::SetGlobalDefault((ColourModel) cm, NULL);
00250 
00251             // Remove from the list. Note that we use RemoveItem to *force*
00252             // removal - RemoveContext only removes it if UsageCount == 0.
00253             ColContextList->RemoveItem(DefaultCC);
00254 
00255             // Decrement usage. This *should* take it down to zero usage, as
00256             // it is hoped that by the time we are called, all other users will
00257             // have released their claims. We do this to stop the ENSURE from
00258             // triggering when we delete the object.
00259             DefaultCC->DecrementUsage();
00260 
00261             // And delete the object
00262             delete DefaultCC;
00263         }
00264     }
00265 
00266     ENSURE(ColContextList->IsEmpty(), "ColourContextList::DeinitColourContexts: Some ColourContext(s) have not yet been released");
00267 
00268     // And delete the global list of contexts
00269     delete ColContextList;
00270     ColContextList = NULL;
00271 }

ColourContextList * ColourContextList::GetList void   )  [inline, static]
 

Find the 'global' list of current colour contexts.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/04/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the list of colour contexts

Errors: -

See also:
-

Definition at line 871 of file colcontx.h.

00872 {
00873     return(ColContextList);
00874 }

BOOL ColourContextList::InitColourContexts void   )  [static]
 

Initialises the Colour Context system, setting up the global list of default colour contexts which are shared by all documents. Called from app.cpp (must not be called more than once).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/04/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if initialisation succeeded, else FALSE FALSE if it failed (most likely because of lack of memory)

Errors: -

Definition at line 149 of file colclist.cpp.

00150 {
00151     ENSURE(ColContextList == NULL, "ColourContextList::InitColourContexts called more than once!");
00152 
00153     // First, create the global Colour context list in which all colour contexts
00154     // should be registered.
00155     ColContextList = new ColourContextList;
00156     if (ColContextList == NULL)
00157         return(FALSE);
00158 
00159 
00160     // Now, create an instance of each available colour context to provide the
00161     // global set of default colour contexts. Add each to the CCList.
00162     ColourContext *tempcc;
00163 
00164     tempcc = new ColourContextRGBT(NULL, 1.0);          // --- RGBT
00165     if (tempcc == NULL)
00166         return(FALSE);
00167 
00168     ColContextList->AddContext(&tempcc);
00169     ColourContext::SetGlobalDefault(COLOURMODEL_RGBT, tempcc);
00170     
00171 
00172     tempcc = new ColourContextCMYK(NULL);               // --- CMYK
00173     if (tempcc == NULL)
00174         return(FALSE);
00175 
00176     ColContextList->AddContext(&tempcc);
00177     ColourContext::SetGlobalDefault(COLOURMODEL_CMYK, tempcc);
00178 
00179     tempcc = new ColourContextHSVT(NULL);               // --- HSVT
00180     if (tempcc == NULL)
00181         return(FALSE);
00182 
00183     ColContextList->AddContext(&tempcc);
00184     ColourContext::SetGlobalDefault(COLOURMODEL_HSVT, tempcc);
00185 
00186 
00187     tempcc = new ColourContextGreyT(NULL);              // --- GreyT
00188     if (tempcc == NULL)
00189         return(FALSE);
00190 
00191     ColContextList->AddContext(&tempcc);
00192     ColourContext::SetGlobalDefault(COLOURMODEL_GREYT, tempcc);
00193 
00194 
00195 #ifndef DISABLE_WEBRGBT
00196     tempcc = new ColourContextWebRGBT(NULL);            // --- WebRBGT
00197     if (tempcc == NULL)
00198         return(FALSE);
00199 
00200     ColContextList->AddContext(&tempcc);
00201     ColourContext::SetGlobalDefault(COLOURMODEL_WEBRGBT, tempcc);
00202 #endif
00203                                                         // --- etc...
00204 
00205     return(TRUE);
00206 }

void ColourContextList::RemoveContext ColourContext **  OldContext  ) 
 

"Removes" the given colour context to the global list of available contexts. If the context is now no longer in use by anyone, it will be 'delete'd. The context pointer passed in will be set to NULL.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/04/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
ColourContextList::AddContext; ColourContext

Definition at line 400 of file colclist.cpp.

00401 {
00402     ENSURE(OldContext != NULL && *OldContext != NULL,
00403                 "ColourContextList::RemoveContext called with NULL parameter!");
00404 
00405     if (!((*OldContext)->DecrementUsage()))     // Not still in use, so discard it
00406     {
00407         RemoveItem(*OldContext);
00408         delete *OldContext;
00409     }
00410 
00411     *OldContext = NULL;
00412 }


Member Data Documentation

ColourContextList * ColourContextList::ColContextList = NULL [static, private]
 

Definition at line 851 of file colcontx.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:48 2007 for Camelot by  doxygen 1.4.4