#include <range.h>
Inheritance diagram for CommonAttrSet:
Public Types | |
enum | ObjectAttrUsage { REQUIRED, FOUND, NOT_REQUIRED } |
Public Member Functions | |
CommonAttrSet () | |
virtual | ~CommonAttrSet () |
BOOL | AddTypeToSet (CCRuntimeClass *AttrType) |
Call this function to build up a subset of attribute types to find common attribute values for. It creates an CommonAttributeItem and adds it to the set. | |
BOOL | AddAllTypesToSet () |
This function adds all attribute types to the CommonAttrSet. You will probably never need to call this function because Range::FindCommonAttributes will call it for you if you pass in an empty CommonAttrSet. | |
CommonAttributeItem * | FindAttrItem (CCRuntimeClass *AttrType) |
To find an item in the CommonAttrSet. | |
BOOL | FindAttrDetails (CCRuntimeClass *AttrType, NodeAttribute **pAttr, Range::CommonAttribResult *Status) |
To find an item in the CommonAttrSet. | |
BOOL | IsAnyItemCommon () |
Returns TRUE if any item in the CommonAttrSet is a common attribute. | |
void | ClearResults () |
This function initialises the CommonAttrSet ready for finding common attributes Each CommonAttributeItem in the set has its Status set to ATTR_NONE and its pAttr set to NULL. You will probably never need to call this function as Range::FindCommonAttributes makes a call to it prior to looking for common attributes. | |
INT32 | UpdateKnownValues (CommonAttrSet *pCache) |
This function is provided so that a CommonAttrSet can be updated from a cache of known values. Each AttrType in this set which has values in the pCache is updated. | |
BOOL | BuildAttrDetailsMap (NodeRenderableInk *CompoundObject, INT32 FirstN, CCAttrMap *pAppliedAttrMap, CMapPtrToWord *pCompoundAttrMap) |
This method is used by FindCommonAttributes to determine if a default attribute is common to a CompoundObject. |
Definition at line 723 of file range.h.
|
Definition at line 744 of file range.h. 00744 { REQUIRED, // The attribute is required by at least one child object 00745 // but does not appear as a child. => Default attr is 00746 // common 00747 FOUND, // The attribute is required by at least one child object 00748 // and has been found as a child. => Default attr is not common 00749 NOT_REQUIRED }; // Attribute is not required by any child.
|
|
Definition at line 726 of file range.h.
|
|
Definition at line 727 of file range.h. 00727 { DeleteAll(); }; // Delete all items in the set before we leave
|
|
This function adds all attribute types to the CommonAttrSet. You will probably never need to call this function because Range::FindCommonAttributes will call it for you if you pass in an empty CommonAttrSet.
Definition at line 6068 of file range.cpp. 06069 { 06070 // If the CommonAttributeSet is not empty on entry then something is probably not right ! 06071 ERROR3IF(!IsEmpty(), 06072 "CommonAttributeSet not empty on entry to AddAllTypesToSet"); 06073 06074 // Obtain a list of all required attributes 06075 List* ReqdAttribList = ObjectRegistry::GetRequiredAttribs(NULL); 06076 06077 // Now create a CommonAttributeItem for each item in the list 06078 NodeAttributeClassItem* ReqdAttrib = (NodeAttributeClassItem*)ReqdAttribList->GetHead(); 06079 06080 while(ReqdAttrib != NULL) 06081 { 06082 if (!(ReqdAttrib->AttributeClass == CC_RUNTIME_CLASS(AttrQuality))) 06083 { 06084 if (!AddTypeToSet(ReqdAttrib->AttributeClass)) 06085 { 06086 DeleteAll(); 06087 return FALSE; 06088 } 06089 } 06090 ReqdAttrib = (NodeAttributeClassItem*)ReqdAttribList->GetNext(ReqdAttrib); 06091 } 06092 return TRUE; // Success 06093 }
|
|
Call this function to build up a subset of attribute types to find common attribute values for. It creates an CommonAttributeItem and adds it to the set.
Definition at line 6038 of file range.cpp. 06039 { 06040 ERROR3IF(FindAttrItem(AttrType), "Trying to add a duplicate item to a CommonAttrSet"); 06041 CommonAttributeItem* CommonAttrItem; 06042 CommonAttrItem = new CommonAttributeItem(AttrType); 06043 if (CommonAttrItem == NULL) 06044 { 06045 // Oh no we've run out of memory 06046 return FALSE; 06047 } 06048 AddTail(CommonAttrItem); 06049 return TRUE; 06050 }
|
|
This method is used by FindCommonAttributes to determine if a default attribute is common to a CompoundObject. BOOL CommonAttrSet::BuildAttrDetailsMap(NodeRenderableInk* CompoundObject, INT32 FirstN, CCAttrMap* pAppliedAttrMap, CMapPtrToWord* pCompoundAttrMap)
pAppliedAttrMap: A map from an attribute type to the attribute value which is 'applied' to the CompoundObject. Only AttrTypes which have default attribute values are added to the AttrDetailsMap
For Child read Child, or Child of Child etc. If an AttrType maps to a REQUIRED value, this means that at least one Child of the compound requires the attribute, but an attribute of this type does not appear as a Child of the compound. If it maps to a FOUND value then this means that the attribute is required by at least one child object and has been found as a Child if it maps to a NOT_REQUIRED value then this means that the attribute is not required by any child of the compound.
Definition at line 6326 of file range.cpp. 06330 { 06331 06332 // This will probably indicate a bug 06333 ERROR3IF(FirstN == 0, "Called CommonAttrSet::BuildAttrDetailsMap with nothing to do"); 06334 06335 // I can't imagine why anyone would want to call this fn on a non-compound object 06336 ERROR3IF(!(Object->IsCompound()), "BuildAttrDetailsMap called on a non-compound"); 06337 06338 if (FirstN == 0) 06339 return TRUE; // Nothing to do 06340 06341 // We want to scan this list fast, and we don't want to change the order of items 06342 // within it. So create a ListIndex 06343 List IdxIntoAttrSet; 06344 if (!CreateIndex(&IdxIntoAttrSet)) 06345 { 06346 return FALSE; 06347 } 06348 06349 // Place required attribute types into the map, and remove index items we are not interested 06350 // in. 06351 ListItemIdx* ppAttrItem = (ListItemIdx*)(IdxIntoAttrSet.GetHead()); 06352 CommonAttributeItem* pAttrItem = (CommonAttributeItem*)GetHead(); 06353 ListItemIdx* ppNxtAttrItem; // Hand over hand 06354 INT32 Count = 0; 06355 while(pAttrItem && ppAttrItem) 06356 { 06357 ppNxtAttrItem = (ListItemIdx*)(IdxIntoAttrSet.GetNext(ppAttrItem)); 06358 06359 if (Count != FirstN) // We are interested in this item, add it to the map 06360 { 06361 // Is the applied AttrType attribute a default ? 06362 void* pvAttrValue = NULL; 06363 NodeAttribute* pAttrValue; 06364 pAppliedAttrMap->Lookup(pAttrItem->AttrType, pvAttrValue); 06365 pAttrValue = (NodeAttribute*)pvAttrValue; 06366 if (pAttrValue->IsADefaultAttr()) 06367 { 06368 (*pCompoundAttrMap)[pAttrItem->AttrType] = (WORD)CommonAttrSet::NOT_REQUIRED; 06369 } 06370 else 06371 { 06372 // Remove item from index - we are not interested in non-defaults 06373 delete(IdxIntoAttrSet.RemoveItem(ppAttrItem)); 06374 } 06375 pAttrItem = (CommonAttributeItem*)GetNext(pAttrItem); 06376 Count++; 06377 } 06378 else // We are not interested in this item remove it from our index 06379 { 06380 delete(IdxIntoAttrSet.RemoveItem(ppAttrItem)); 06381 } 06382 ppAttrItem = ppNxtAttrItem; 06383 } 06384 06385 // Scan the compound depth first 06386 Node* Current = Object->FindFirstDepthFirst(); 06387 06388 INT32 UnknownValues = IdxIntoAttrSet.GetCount(); // When this equals 0 we can stop 06389 06390 while((Current != Object) && UnknownValues) // stop when we hit the compound 06391 { 06392 if (Current->IsAnObject()) 06393 { 06394 ppAttrItem = (ListItemIdx*)(IdxIntoAttrSet.GetHead()); 06395 while (ppAttrItem) 06396 { 06397 ppNxtAttrItem = (ListItemIdx*)(IdxIntoAttrSet.GetNext(ppAttrItem)); 06398 06399 CCRuntimeClass* AttrType = ((CommonAttributeItem*)(ppAttrItem->pItem))->AttrType; 06400 if (((NodeRenderableInk*)Current)-> 06401 RequiresAttrib(AttrType)) 06402 { 06403 CommonAttrSet::ObjectAttrUsage AttrUsage; 06404 CMapPtrToWord::iterator iter = pCompoundAttrMap->find( AttrType ); 06405 if( pCompoundAttrMap->end() != iter ) 06406 { 06407 AttrUsage = (CommonAttrSet::ObjectAttrUsage)iter->second; 06408 if( AttrUsage != CommonAttrSet::FOUND ) 06409 { 06410 (*pCompoundAttrMap)[AttrType] = (WORD)CommonAttrSet::REQUIRED; 06411 } 06412 } 06413 06414 // We don't need to consider this item again, so remove it from the 06415 // index. 06416 delete(IdxIntoAttrSet.RemoveItem(ppAttrItem)); 06417 } 06418 ppAttrItem = ppNxtAttrItem; 06419 } 06420 06421 } 06422 else if (Current->IsAnAttribute()) 06423 { 06424 CCRuntimeClass* AttrType = ((NodeAttribute*)Current)->GetAttributeType(); 06425 06426 CommonAttrSet::ObjectAttrUsage AttrUsage; 06427 CMapPtrToWord::iterator iter = pCompoundAttrMap->find( AttrType ); 06428 if( pCompoundAttrMap->end() != iter ) 06429 { 06430 AttrUsage = (CommonAttrSet::ObjectAttrUsage)iter->second; 06431 06432 if (AttrUsage != CommonAttrSet::FOUND) // Has not been found before ! 06433 { 06434 (*pCompoundAttrMap)[AttrType] = (WORD)CommonAttrSet::FOUND; 06435 UnknownValues--; // This AttrUsage value is not going to change 06436 } 06437 } // else it's an attribute we're not interested in ! 06438 } 06439 Current = Current->FindNextDepthFirst(Object); 06440 } 06441 06442 IdxIntoAttrSet.DeleteAll(); // Tidyup 06443 06444 return TRUE; 06445 }
|
|
This function initialises the CommonAttrSet ready for finding common attributes Each CommonAttributeItem in the set has its Status set to ATTR_NONE and its pAttr set to NULL. You will probably never need to call this function as Range::FindCommonAttributes makes a call to it prior to looking for common attributes.
Definition at line 6208 of file range.cpp. 06209 { 06210 ERROR3IF(IsEmpty(), "CommonAttrSet::ClearResults called on an empty CommonAttrSet"); 06211 CommonAttributeItem* pAttrItem; 06212 pAttrItem = (CommonAttributeItem*)(GetHead()); 06213 while (pAttrItem) 06214 { 06215 ERROR3IF(!pAttrItem->AttrType, "CommonAttrSet contains invalid attr type"); 06216 pAttrItem->ClearResults(); 06217 pAttrItem = (CommonAttributeItem*)(GetNext(pAttrItem)); 06218 } 06219 }
|
|
To find an item in the CommonAttrSet.
Definition at line 6143 of file range.cpp. 06146 { 06147 CommonAttributeItem* pAttrItem; 06148 pAttrItem = (CommonAttributeItem*)(GetHead()); 06149 while (pAttrItem) 06150 { 06151 if (pAttrItem->AttrType == AttrType) 06152 { 06153 *pAttr = pAttrItem->pAttr; 06154 *Status = pAttrItem->Status; 06155 return TRUE; 06156 } 06157 pAttrItem = (CommonAttributeItem*)(GetNext(pAttrItem)); 06158 } 06159 return FALSE; 06160 }
|
|
To find an item in the CommonAttrSet.
Definition at line 6108 of file range.cpp. 06109 { 06110 CommonAttributeItem* pAttrItem; 06111 pAttrItem = (CommonAttributeItem*)(GetHead()); 06112 while (pAttrItem) 06113 { 06114 if (pAttrItem->AttrType == AttrType) 06115 break; 06116 06117 pAttrItem = (CommonAttributeItem*)(GetNext(pAttrItem)); 06118 } 06119 return pAttrItem; 06120 }
|
|
Returns TRUE if any item in the CommonAttrSet is a common attribute.
Definition at line 6175 of file range.cpp. 06176 { 06177 // Scan the set 06178 CommonAttributeItem* pAttrItem; 06179 pAttrItem = (CommonAttributeItem*)(GetHead()); 06180 while (pAttrItem) 06181 { 06182 if (pAttrItem->Status == Range::ATTR_COMMON) 06183 return TRUE; 06184 pAttrItem = (CommonAttributeItem*)(GetNext(pAttrItem)); 06185 } 06186 return FALSE; 06187 }
|
|
This function is provided so that a CommonAttrSet can be updated from a cache of known values. Each AttrType in this set which has values in the pCache is updated.
Definition at line 6247 of file range.cpp. 06248 { 06249 CommonAttributeItem* pMyItem; 06250 CommonAttributeItem* pCachedItem; 06251 CommonAttributeItem* pFirstKnownItem = NULL; 06252 INT32 UncachedItems = GetCount(); 06253 06254 // Scan thru the cache 06255 pCachedItem = (CommonAttributeItem*)(pCache->GetHead()); 06256 06257 while (pCachedItem && UncachedItems) 06258 { 06259 pMyItem = (CommonAttributeItem*)GetHead(); 06260 while (pMyItem != pFirstKnownItem) 06261 { 06262 if (pMyItem->AttrType == pCachedItem->AttrType) 06263 { 06264 // Item is cached 06265 pMyItem->pAttr = pCachedItem->pAttr; 06266 pMyItem->Status = pCachedItem->Status; 06267 UncachedItems--; 06268 // Move the item to the tail of the list, so that we can stop when we 06269 // hit the first known item. 06270 RemoveItem(pMyItem); 06271 AddTail(pMyItem); 06272 if (!pFirstKnownItem) 06273 pFirstKnownItem = pMyItem; 06274 break; 06275 } 06276 pMyItem = (CommonAttributeItem*)(GetNext(pMyItem)); 06277 } 06278 pCachedItem = (CommonAttributeItem*)(pCache->GetNext(pCachedItem)); 06279 } 06280 return UncachedItems; 06281 }
|