#include <scunit.h>
Public Member Functions | |
UnitGroup () | |
Default constructor for a UnitGroup. Provides safe defaults. Scope: public. | |
UnitGroup (const UnitGroup &GroupToCopy) | |
Do not use Scope: public. | |
BOOL | IsValid () |
virtual | ~UnitGroup () |
Default destructor for the group Scope: public. | |
virtual UnitGroup & | operator= (const UnitGroup &GroupToCopy) |
Do not use Scope: public. | |
virtual BOOL | operator== (const UnitGroup &RhsGroup) const |
Do not use Scope: public. | |
virtual BOOL | operator!= (const UnitGroup &RhsGroup) const |
Do not use Scope: public. | |
BOOL | AddUnit (ScaleUnit *pUnit) |
Adds a ScaleUnit to a UnitGroup. | |
BOOL | AddUnit (ScaleUnit &NewUnit) |
Adds a ScaleUnit to a UnitGroup. | |
ScaleUnit * | UpdateUnit (const UINT32 uIndex, ScaleUnit &NewUnit) |
Allows you to update a ScaleUnit in a UnitGroup. | |
BOOL | DeleteUnit (ScaleUnit &UnitToDelete) |
Lets you delete a ScaleUnit from the UnitGroup Scope: public. | |
ScaleUnit * | FindUnitFromQualifier (const String_32 &qualifier) const |
Identifies a ScaleUnit from the given qualifier token, e.g., '', 'd', etc Scope: public. | |
ScaleUnit * | FindUnitFromIndex (const UINT32 uIndex) const |
Find a unit by index Scope: public. | |
INT32 | FindIndexFromUnit (const ScaleUnit &thisUnit) const |
Gets a unique index for the given ScaleUnit in the UnitGroup by which it may be referred. Scope: public. | |
UINT32 | GetUnitCount () const |
Provides a check for parameters usually Scope: public. | |
BOOL | SetDefaultUnit (ScaleUnit *pUnit) |
To provide a default ScaleUnit to use when no unit is specified for ScaleFromString (& no ScaleUnit has a NULL qualifier) Scope: public. | |
ScaleUnit * | GetDefaultUnit () const |
Provides a pointer to the default unit in the group. (NULL is no default) Scope: public. | |
BOOL | ScaleFromString (const StringBase &string, double &dNumber) const |
Given a string of the form <number>[<qualifier>] | <qualifier><number> this method will produce a number in the range 0 to 1 depending on the qualifier. If no qualifier is given the default for the group is used. If no default is provided FALSE is returned. | |
Protected Member Functions | |
virtual void | OnUnitChanged (const ScaleUnit &UpdatedUnit) |
virtual BOOL | AllowDeletion (const ScaleUnit &UnitToDelete) |
virtual void | OnDeleteCompletion (const ScaleUnit &DeletedUnit) |
Protected Attributes | |
List | m_UnitList |
List | m_UnitRefList |
ScaleUnit * | m_pDefaultUnit |
Private Member Functions | |
CC_DECLARE_MEMDUMP (UnitGroup) | |
Private Attributes | |
BOOL | m_bConstructedOK |
Definition at line 318 of file scunit.h.
|
Default constructor for a UnitGroup. Provides safe defaults. Scope: public.
Definition at line 910 of file scunit.cpp. 00911 { 00912 m_pDefaultUnit = NULL; 00913 m_bConstructedOK = TRUE; 00914 }
|
|
Do not use Scope: public.
Definition at line 946 of file scunit.cpp. 00947 { 00948 ERROR3("UnitGroup::UnitGroup - not expected to work"); 00949 *this = GroupToCopy; 00950 }
|
|
Default destructor for the group Scope: public.
Definition at line 927 of file scunit.cpp. 00928 { 00929 ScaleUnit* pUnit; 00930 00931 while ((pUnit = (ScaleUnit*)m_UnitList.RemoveHead()) != NULL) 00932 ; 00933 }
|
|
Adds a ScaleUnit to a UnitGroup.
Definition at line 1131 of file scunit.cpp. 01132 { 01133 ERROR2IF(TRUE, FALSE, "Not tested"); 01134 // Check for duplicate units in a group 01135 ScaleUnitReference* pCurrentRef = (ScaleUnitReference*)m_UnitRefList.GetHead(); 01136 const Qualifier* pCurrentQualifier = NewUnit.GetQualifier(); 01137 ERROR3IF(!(pCurrentQualifier->IS_KIND_OF(Qualifier)), "NewUnit contains alien qualifier"); 01138 while (pCurrentRef != NULL) 01139 { 01140 ERROR3IF(!(pCurrentRef->IS_KIND_OF(ScaleUnitReference)), "UnitGroup contains alien objects"); 01141 { 01142 const ScaleUnit* pNewUnit = pCurrentRef->GetUnit(); 01143 const Qualifier* pNewQualifier = pNewUnit->GetQualifier(); 01144 ERROR3IF(!(pNewQualifier->IS_KIND_OF(Qualifier)), "RhsRef has alien qualifier"); 01145 01146 if (*(pNewQualifier->GetToken()) == *(pCurrentQualifier->GetToken())) 01147 { 01148 ERROR3("Adding unit with duplicate qualifier"); 01149 return FALSE; 01150 } 01151 } 01152 pCurrentRef = (ScaleUnitReference*)m_UnitRefList.GetNext((ListItem*)pCurrentRef); 01153 } 01154 // Unit not already in list so add on the end 01155 pCurrentRef = new ScaleUnitReference(NewUnit); 01156 m_UnitRefList.AddTail((ListItem*)pCurrentRef); 01157 return TRUE; 01158 }
|
|
Adds a ScaleUnit to a UnitGroup.
Definition at line 1086 of file scunit.cpp. 01087 { 01088 ERROR2IF(pNewUnit == NULL && !pNewUnit->IS_KIND_OF(ScaleUnit), FALSE, "Adding a bogus ScaleUnit"); 01089 01090 // Check for duplicate units in a group 01091 ScaleUnit* pCurrentUnit = (ScaleUnit*)m_UnitList.GetHead(); 01092 while (pCurrentUnit != NULL) 01093 { 01094 ERROR3IF(!(pCurrentUnit->IS_KIND_OF(ScaleUnit)), "UnitGroup contains alien objects"); 01095 01096 const Qualifier* pNewQualifier = pNewUnit->GetQualifier(); 01097 ERROR3IF(!(pNewQualifier->IS_KIND_OF(Qualifier)), "pNewUnit has alien qualifier"); 01098 const Qualifier* pCurrentQualifier = pCurrentUnit->GetQualifier(); 01099 ERROR3IF(!(pCurrentQualifier->IS_KIND_OF(Qualifier)), "UnitGroup contains alien qualifier"); 01100 01101 if (*(pNewQualifier->GetToken()) == *(pCurrentQualifier->GetToken())) 01102 { 01103 // ScaleUnit qualifier already in group 01104 ERROR3IF(*pNewUnit == *pCurrentUnit, "Adding unit with duplicate qualifier"); 01105 return TRUE; 01106 } 01107 pCurrentUnit = (ScaleUnit*)m_UnitList.GetNext((ListItem*)pCurrentUnit); 01108 } 01109 // Unit not already in list so add on the end 01110 m_UnitList.AddTail((ListItem*)pNewUnit); 01111 01112 return TRUE; 01113 }
|
|
|
|
|
|
Lets you delete a ScaleUnit from the UnitGroup Scope: public.
Definition at line 1205 of file scunit.cpp. 01206 { 01207 01208 ERROR2IF(TRUE, FALSE, "UnitGroup::DeleteUnit - Not tested"); 01209 01210 ScaleUnit* pUnit = &UnitToDelete; 01211 // Allow something to prevent the deletion 01212 if (!AllowDeletion(UnitToDelete)) 01213 return FALSE; 01214 01215 pUnit = (ScaleUnit*)m_UnitList.RemoveItem((ListItem*)pUnit); 01216 if (pUnit == NULL) 01217 { 01218 ERROR3("UnitGroup::DeleteUnit - Item not in list"); 01219 return FALSE; 01220 } 01221 01222 if (m_pDefaultUnit == pUnit) // Reset the default unit if this is being deleted 01223 m_pDefaultUnit = NULL; 01224 01225 // Allow something to be informed that the unit is about to be deleted 01226 OnDeleteCompletion(UnitToDelete); 01227 01228 return TRUE; 01229 }
|
|
Gets a unique index for the given ScaleUnit in the UnitGroup by which it may be referred. Scope: public.
Definition at line 1306 of file scunit.cpp. 01307 { 01308 ScaleUnit* pUnit = (ScaleUnit*) m_UnitList.GetHead(); 01309 INT32 nIndex = 0; 01310 01311 while (pUnit != NULL) 01312 { 01313 ERROR3IF(!(pUnit->IS_KIND_OF(ScaleUnit)), "UnitGroup contains alien objects"); 01314 if (*pUnit == thisUnit) break; 01315 pUnit = (ScaleUnit*) m_UnitList.GetNext((ListItem*)pUnit); 01316 ++nIndex; 01317 } 01318 if (pUnit == NULL) nIndex = -1; // not found 01319 01320 return nIndex; 01321 }
|
|
Find a unit by index Scope: public.
Definition at line 1281 of file scunit.cpp. 01282 { 01283 ERROR2IF(uIndex >= GetUnitCount(), NULL, "uIndex invalid"); 01284 01285 ScaleUnit* pUnit = (ScaleUnit*) m_UnitList.FindItem(LISTPOS(uIndex)); 01286 ERROR3IF(!pUnit->IS_KIND_OF(ScaleUnit), "UnitGroup contains alien objects"); 01287 01288 return pUnit; 01289 }
|
|
Identifies a ScaleUnit from the given qualifier token, e.g., '', 'd', etc Scope: public.
Definition at line 1247 of file scunit.cpp. 01248 { 01249 ScaleUnit* pUnit = (ScaleUnit*) m_UnitList.GetHead(); 01250 01251 while (pUnit != NULL) 01252 { 01253 ERROR3IF(!(pUnit->IS_KIND_OF(ScaleUnit)), "UnitGroup::FindUnitFromQualifier - UnitGroup contains alien objects"); 01254 01255 const Qualifier* pQualifier = pUnit->GetQualifier(); 01256 ERROR3IF(!(pQualifier->IS_KIND_OF(Qualifier)), "UnitGroup::FindUnitFromQualifier - Qualifier is not"); 01257 01258 if (qualifier == pQualifier->GetToken()) 01259 return pUnit; 01260 01261 pUnit = (ScaleUnit*) m_UnitList.GetNext((ListItem*)pUnit); 01262 } 01263 01264 return NULL; 01265 }
|
|
Provides a pointer to the default unit in the group. (NULL is no default) Scope: public.
Definition at line 1387 of file scunit.cpp. 01388 { 01389 return m_pDefaultUnit; 01390 }
|
|
Provides a check for parameters usually Scope: public.
Definition at line 1335 of file scunit.cpp. 01336 { 01337 return m_UnitList.GetCount(); 01338 }
|
|
Definition at line 326 of file scunit.h. 00326 {return m_bConstructedOK;}
|
|
|
|
|
|
Do not use Scope: public.
Definition at line 1065 of file scunit.cpp.
|
|
Do not use Scope: public.
Definition at line 963 of file scunit.cpp. 00964 { 00965 ERROR3("UnitGroup::operator= - not expected to work"); 00966 00967 if (this == &GroupToCopy) return *this; 00968 00969 00970 INT32 thisSize = m_UnitRefList.GetCount(); 00971 if (thisSize == 0) // no need to copy the units so exit stage left 00972 { 00973 m_pDefaultUnit = GroupToCopy.m_pDefaultUnit; 00974 m_bConstructedOK = TRUE; 00975 return *this; 00976 } 00977 // First bin the old list of units... 00978 ScaleUnitReference* pUnitRef; 00979 while ((pUnitRef = (ScaleUnitReference*)m_UnitList.RemoveHead()) != NULL) 00980 delete pUnitRef; 00981 00982 // Create space for all the units in one go... 00983 ScaleUnitReference* UnitRefArray = new ScaleUnitReference[thisSize]; 00984 if (UnitRefArray == NULL) 00985 { 00986 m_pDefaultUnit = NULL; 00987 m_bConstructedOK = FALSE; 00988 return *this; 00989 } 00990 00991 ScaleUnitReference* pRefToCopy = (ScaleUnitReference*) m_UnitRefList.GetHead(); 00992 UINT32 uIndex = 0; 00993 while (pRefToCopy != NULL) 00994 { 00995 ScaleUnitReference* NewRef = &UnitRefArray[uIndex++]; 00996 NewRef->SetUnit(pRefToCopy->GetUnit()); 00997 m_UnitRefList.AddTail(NewRef); 00998 pRefToCopy = (ScaleUnitReference*)m_UnitList.GetNext(pRefToCopy); 00999 } 01000 01001 m_pDefaultUnit = GroupToCopy.m_pDefaultUnit; 01002 m_bConstructedOK = TRUE; 01003 return *this; 01004 }
|
|
Do not use Scope: public.
Definition at line 1017 of file scunit.cpp. 01018 { 01019 INT32 rhsSize = RhsGroup.m_UnitRefList.GetCount(); 01020 INT32 thisSize = m_UnitRefList.GetCount(); 01021 if (rhsSize != thisSize) 01022 return FALSE; 01023 if (rhsSize == 0 && thisSize == 0) 01024 return TRUE; 01025 01026 ERROR3("UnitGroup::operator== - not expected to work"); 01027 // Create a list of references from which we can eliminate duplicates 01028 // in the RhsGroup 01029 01030 UnitGroup pointerList = *this; 01031 01032 // Now scan through the group we are comparing with eliminating duplicates in our 01033 // 01034 ScaleUnit* pRhsUnit = (ScaleUnit*) RhsGroup.m_UnitList.GetHead(); 01035 while (pRhsUnit != NULL) 01036 { 01037 ScaleUnitReference* pLhsUnit = (ScaleUnitReference*) pointerList.m_UnitRefList.GetHead(); 01038 while (pLhsUnit != NULL) 01039 { 01040 if (*pLhsUnit->GetUnit() == *pRhsUnit) 01041 { 01042 // Eliminate matching pointer 01043 pointerList.m_UnitRefList.RemoveItem((ListItem*)pLhsUnit); 01044 break; 01045 } 01046 pLhsUnit = (ScaleUnitReference*)pointerList.m_UnitRefList.GetNext(pLhsUnit); 01047 } 01048 pRhsUnit = (ScaleUnit*)RhsGroup.m_UnitList.GetNext((ListItem*)pRhsUnit); 01049 } 01050 01051 return pointerList.m_UnitRefList.IsEmpty(); 01052 }
|
|
Given a string of the form <number>[<qualifier>] | <qualifier><number> this method will produce a number in the range 0 to 1 depending on the qualifier. If no qualifier is given the default for the group is used. If no default is provided FALSE is returned.
Definition at line 1545 of file scunit.cpp. 01546 { 01547 String_32 qualifier, amount; 01548 Qualifier::QUALIFIER_AFFIX affixType; 01549 Parser parser(string); 01550 01551 parser.PrepareForParse(); 01552 01553 Parser::TOKEN tk = parser.GetToken(); 01554 if (tk == Parser::TK_QUALIFIER) // expecting prefix qualifier 01555 { 01556 qualifier = parser.GetSemanticValue(); 01557 affixType = Qualifier::PREFIX; 01558 tk = parser.GetToken(); 01559 if (tk == Parser::TK_NUMBER) 01560 { 01561 amount = parser.GetSemanticValue(); 01562 } 01563 else 01564 { 01565 //ERROR3("UnitGroup::ScaleFromString - no number"); 01566 return FALSE; 01567 } 01568 } 01569 else if (tk == Parser::TK_NUMBER) // expecting suffix qualifier 01570 { 01571 amount = parser.GetSemanticValue(); 01572 tk = parser.GetToken(); 01573 if (tk == Parser::TK_QUALIFIER) 01574 { 01575 affixType = Qualifier::SUFFIX; 01576 qualifier = parser.GetSemanticValue(); 01577 } 01578 else if (tk == Parser::TK_EOS) 01579 { 01580 affixType = Qualifier::NONE; 01581 } 01582 else 01583 { 01584 //ERROR3("UnitGroup::ScaleFromString - invalid characters"); 01585 return FALSE; 01586 } 01587 } 01588 else 01589 { 01590 //ERROR3("UnitGroup::ScaleFromString - invalid characters"); 01591 return FALSE; 01592 } 01593 01594 01595 ScaleUnit* pUnit; 01596 // We've found a qualifier & amount so check them both 01597 pUnit = FindUnitFromQualifier(qualifier); 01598 if (pUnit == NULL) // no match so use the default 01599 { 01600 pUnit = GetDefaultUnit(); 01601 } 01602 else 01603 { 01604 //ERROR3IF(pUnit->GetQualifier()->GetAffix() != affixType, "UnitGroup::ScaleFromString - qualifier position incorrect"); 01605 } 01606 if (pUnit == NULL) // no unit with that qualifier & no default 01607 { 01608 return FALSE; 01609 } 01610 ERROR3IF(!pUnit->IS_KIND_OF(ScaleUnit), "UnitGroup::ScaleFromString - pUnit isn't"); 01611 Convert::StringToDouble( amount, &dNumber ); 01612 return (pUnit->ConvertTo0to1(dNumber)); 01613 }
|
|
To provide a default ScaleUnit to use when no unit is specified for ScaleFromString (& no ScaleUnit has a NULL qualifier) Scope: public.
Definition at line 1356 of file scunit.cpp. 01357 { 01358 if (pUnit == NULL) // Set no default 01359 { 01360 m_pDefaultUnit = NULL; 01361 return TRUE; 01362 } 01363 01364 ERROR2IF(!(pUnit->IS_KIND_OF(ScaleUnit)), FALSE, "pUnit Invalid"); 01365 01366 LISTPOS lp = m_UnitList.FindPosition(pUnit); 01367 if (lp == NOT_IN_LIST || lp == EMPTY_LIST) 01368 return FALSE; 01369 m_pDefaultUnit = pUnit; 01370 return TRUE; 01371 }
|
|
Allows you to update a ScaleUnit in a UnitGroup.
Definition at line 1176 of file scunit.cpp. 01177 { 01178 ERROR2IF(uIndex >= GetUnitCount(), FALSE, "uIndex invalid"); 01179 ERROR2IF(TRUE, FALSE, "Not tested"); 01180 01181 ScaleUnit* pOldUnit = FindUnitFromIndex(uIndex); 01182 01183 // Can't change the qualifier?? 01184 if (NewUnit.GetQualifier()->GetToken() != pOldUnit->GetQualifier()->GetToken()) 01185 return NULL; 01186 01187 // *pOldUnit = *pUnit; 01188 return pOldUnit; 01189 }
|
|
|
|
|
|
|
|
|