Unit Class Reference

Encapsulates units within Camelot. All units (i.e. default and user-defined ones) are an instance of this class. Each document has its own list of units controlled by an instance of DocUnitList within the Document class. Therefore you should get hold of the DocUnitList within the current doc when you want to add/delete/edit/find a unit. More...

#include <units.h>

Inheritance diagram for Unit:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 Unit ()
 Default constructor for a unit. Adds the unit to the end of Unit::pUnitList.
 ~Unit ()
 Default destructor for a unit - does nothing.
BOOL IsDefault ()
 Find out if this is a default unit.
BOOL SetDefaultState (BOOL State)
 Allows you to set/clear the default unit flag. Updated 4/9/95 to return the old state.
BOOL IsPrefix ()
 Find out whether unit specifier should be a prefix or suffix.
BOOL SetPrefixState (BOOL State)
 Allows you to set/clear the Prefix flag Updated 4/9/95 to return the old state.
UnitType GetUnitType ()
 Returns the UnitType of this unit.
BOOL SetUnitType (UnitType NewUnitType)
 Sets the UnitType for the unit.
double GetMillipoints ()
 Want the number of millipoints in a single instance of this unit? This is the call for you!
BOOL SetMillipoints (double NewMillipoints)
 Lets you define exactly how big this unit is in the real world, not that we sad computer programmers have any idea what the "real world" is, even if it came up and generated pulses in a recognisable protocol on our ethernet cable. Updated 4/9/95 to return the True if can set the new state ok.
UnitType GetBaseUnitType ()
 Find out which unit this unit is based on.
BOOL SetBaseUnitType (UnitType NewBaseUnitType)
 Lets you set that base unit type. Oh boy! Updated 4/9/95 to return the True if can set the new state ok.
double GetBaseNumerator ()
 Get the numerator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints();.
BOOL SetBaseNumerator (double NewBaseNumerator)
 Sets the numerator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints(); Updated 4/9/95 to return the True if can set the new state ok.
double GetBaseDenominator ()
 Get the Denominator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints();.
BOOL SetBaseDenominator (double NewBaseDenominator)
 Sets the Denominator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints(); Updated 4/9/95 to return the True if can set the new state ok.
String_32 GetToken ()
 Returns the token string which might be used in say a drop-down list of units. This is the full name of the unit in question E.g. "centimetres" specifies the default centimetres unit with the abbreviation or specifier of "cm".
BOOL SetToken (const String_32 &NewToken)
 Sets the token string for the unit. This is the full name of the unit in question E.g. "centimetres" specifies the default centimetres unit with the abbreviation or specifier of "cm". This must not be blank and must not contain numbers as otherwise number parsing may be difficult. Hence, new units should be labelled with A, B .... Hence also, updated to return BOOL 4/9/95 so can return to the setter the fact that the new specifier cannot be allowed.
String_32 GetSpecifier ()
 Returns the Specifier string used in in ed fields when specifying units E.g. "cm" specifies centimetres.
BOOL SetSpecifier (const String_32 &NewSpecifier)
 Sets the Specifier string for the unit. This is the abbreviation for the unit. E.g. "cm" specifies centimetres. Might be bad to allow blanks or duplicates of previosly defined specifiers. Hence, updated to return BOOL 4/9/95 so can return to the setter the fact that the new specifier cannot be allowed.

Static Public Member Functions

static BOOL Init ()
 Initialises the unit class MUST BE CALLED BEFORE ANY OTHER FUNCTION IN THIS CLASS Inits the list of units, defines all the default units and places them on the list.
static BOOL Deinit ()
 Deinitialises the unit class It scans Unit::pUnitList, removing and deleting all its members, then it destroys the list.

Private Attributes

UnitType ThisUnitType
double Millipoints
UnitFlagsType Flags
UnitType BaseUnitType
double BaseNumerator
double BaseDenominator
String_32 Token
String_32 Specifier

Detailed Description

Encapsulates units within Camelot. All units (i.e. default and user-defined ones) are an instance of this class. Each document has its own list of units controlled by an instance of DocUnitList within the Document class. Therefore you should get hold of the DocUnitList within the current doc when you want to add/delete/edit/find a unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
See also:
DocUnitList,Document

Definition at line 167 of file units.h.


Constructor & Destructor Documentation

Unit::Unit  ) 
 

Default constructor for a unit. Adds the unit to the end of Unit::pUnitList.

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

Definition at line 132 of file units.cpp.

00133 {
00134 }

Unit::~Unit  ) 
 

Default destructor for a unit - does nothing.

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

Definition at line 149 of file units.cpp.

00150 {
00151 }


Member Function Documentation

BOOL Unit::Deinit void   )  [static]
 

Deinitialises the unit class It scans Unit::pUnitList, removing and deleting all its members, then it destroys the list.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if deinitialised OK

Definition at line 189 of file units.cpp.

00190 {
00191     return TRUE;
00192 }

double Unit::GetBaseDenominator  ) 
 

Get the Denominator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints();.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Get the base Denominator

Definition at line 430 of file units.cpp.

00431 {
00432     return BaseDenominator;
00433 }

double Unit::GetBaseNumerator  ) 
 

Get the numerator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints();.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Get the base numerator

Definition at line 381 of file units.cpp.

00382 {
00383     return BaseNumerator;
00384 }

UnitType Unit::GetBaseUnitType  ) 
 

Find out which unit this unit is based on.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Unit type this unit is based on

Definition at line 340 of file units.cpp.

00341 {
00342     return BaseUnitType;
00343 }

double Unit::GetMillipoints  ) 
 

Want the number of millipoints in a single instance of this unit? This is the call for you!

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The num millipoints in one of these units

Definition at line 293 of file units.cpp.

00294 {
00295     return Millipoints;
00296 }

String_32 Unit::GetSpecifier  ) 
 

Returns the Specifier string used in in ed fields when specifying units E.g. "cm" specifies centimetres.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The Specifier string
See also:
DocUnitList::GetSpecifier;

Definition at line 535 of file units.cpp.

00536 {
00537     return Specifier;
00538 }

String_32 Unit::GetToken  ) 
 

Returns the token string which might be used in say a drop-down list of units. This is the full name of the unit in question E.g. "centimetres" specifies the default centimetres unit with the abbreviation or specifier of "cm".

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The token string.
See also:
Unit::SetToken; DocUnitList::GetSpecifier;

Definition at line 481 of file units.cpp.

00482 {
00483     return Token;
00484 }

UnitType Unit::GetUnitType  ) 
 

Returns the UnitType of this unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The UnitType. This is a enumerated number for all the units defined.

Definition at line 614 of file units.cpp.

00615 {
00616     return ThisUnitType;
00617 }

BOOL Unit::Init void   )  [static]
 

Initialises the unit class MUST BE CALLED BEFORE ANY OTHER FUNCTION IN THIS CLASS Inits the list of units, defines all the default units and places them on the list.

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

Reimplemented from SimpleCCObject.

Definition at line 169 of file units.cpp.

00170 {
00171     return TRUE;
00172 }

BOOL Unit::IsDefault  ) 
 

Find out if this is a default unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if this unit is one of Camelot's default units

Definition at line 207 of file units.cpp.

00208 {
00209     // Cannot return the state of the flag directly as this is not BOOLEAN due to the
00210     // way bit arrays work. Only reliable test on this is FALSE == 0.
00211     return (Flags.DefaultUnit != 0);
00212 }

BOOL Unit::IsPrefix  ) 
 

Find out whether unit specifier should be a prefix or suffix.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if this unit's specifier should be placed as a prefix in ed fields FALSE means suffix

Definition at line 250 of file units.cpp.

00251 {
00252     // Cannot return the state of the flag directly as this is not BOOLEAN due to the
00253     // way bit arrays work. Only reliable test on this is FALSE == 0.
00254     return (Flags.Prefix != 0);
00255 }

BOOL Unit::SetBaseDenominator double  NewBaseDenominator  ) 
 

Sets the Denominator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints(); Updated 4/9/95 to return the True if can set the new state ok.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewBaseDenominator = the new Denominator value [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.

Definition at line 451 of file units.cpp.

00452 {
00453     // Sanity checks
00454     // - ensure not zero otherwise just wait for those divide by zero errors!
00455     // - check for negative values as well as these will be bad
00456     if (NewBaseDenominator <= 0)
00457         return FALSE;
00458 
00459     BaseDenominator = NewBaseDenominator;
00460 
00461     return TRUE;
00462 }

BOOL Unit::SetBaseNumerator double  NewBaseNumerator  ) 
 

Sets the numerator of the fraction that defines how many BaseUnitTypes are in one of these units. Millipoints = (BaseNumerator/BaseDenominator)*BaseUnit->GetMillipoints(); Updated 4/9/95 to return the True if can set the new state ok.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewBaseNumerator = the new numerator value [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.

Definition at line 402 of file units.cpp.

00403 {
00404     // Sanity checks
00405     // - ensure not zero otherwise just wait for those divide by zero errors!
00406     // - check for negative values as well as these will be bad
00407     if (NewBaseNumerator <= 0)
00408         return FALSE;
00409 
00410     BaseNumerator = NewBaseNumerator;
00411     
00412     return TRUE;
00413 }

BOOL Unit::SetBaseUnitType UnitType  NewBaseUnitType  ) 
 

Lets you set that base unit type. Oh boy! Updated 4/9/95 to return the True if can set the new state ok.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewBaseUnitType = the unit this unit is based on [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.

Definition at line 359 of file units.cpp.

00360 {
00361     BaseUnitType = NewBaseUnitType;
00362 
00363     return TRUE;
00364 }

BOOL Unit::SetDefaultState BOOL  State  ) 
 

Allows you to set/clear the default unit flag. Updated 4/9/95 to return the old state.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
State = new default state [INPUTS]
- [OUTPUTS]
Returns:
the old state of the default unit flag

Definition at line 228 of file units.cpp.

00229 {
00230     BOOL OldState = (Flags.DefaultUnit != 0);
00231     Flags.DefaultUnit = State;
00232     
00233     return OldState;    
00234 }

BOOL Unit::SetMillipoints double  NewMillipoints  ) 
 

Lets you define exactly how big this unit is in the real world, not that we sad computer programmers have any idea what the "real world" is, even if it came up and generated pulses in a recognisable protocol on our ethernet cable. Updated 4/9/95 to return the True if can set the new state ok.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewMillipoints = num millipoints in one of these units [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.

Definition at line 314 of file units.cpp.

00315 {
00316     // Sanity checks
00317     // - ensure not zero otherwise just wait for those divide by zero errors!
00318     // - check for negative values as well as these will be bad
00319     if (NewMillipoints <= 0)
00320         return FALSE;
00321 
00322     Millipoints = NewMillipoints;
00323 
00324     return TRUE;
00325 }

BOOL Unit::SetPrefixState BOOL  State  ) 
 

Allows you to set/clear the Prefix flag Updated 4/9/95 to return the old state.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
State = new Prefix state [INPUTS]
- [OUTPUTS]
Returns:
The old state of the Prefix flag

Definition at line 271 of file units.cpp.

00272 {
00273     BOOL OldState = (Flags.Prefix != 0);
00274     Flags.Prefix = State;
00275     
00276     return OldState;
00277 }

BOOL Unit::SetSpecifier const String_32 NewSpecifier  ) 
 

Sets the Specifier string for the unit. This is the abbreviation for the unit. E.g. "cm" specifies centimetres. Might be bad to allow blanks or duplicates of previosly defined specifiers. Hence, updated to return BOOL 4/9/95 so can return to the setter the fact that the new specifier cannot be allowed.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewSpecifier = new Specifier string [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.
See also:
Unit::GetSpecifier; DocUnitList::GetSpecifier;

Definition at line 558 of file units.cpp.

00559 {
00560     // Sanity checks
00561     // - ensure not zero length
00562     // - should really check for duplicates as unless we allow for overiding of preset units
00563     // - should check for dodgy characters such as numbers as these are very bad
00564     // - should check for the decimal point character and thousands separator
00565     INT32 LenNewSpecifier = NewSpecifier.Length();  
00566     if (LenNewSpecifier == 0)
00567         return FALSE;
00568 
00569     // Check for the existance of numbers in the string.
00570     // At present, check for the prescence of the fixed decimal point and thousand separator
00571     // characters as no easy way of getting at the values in convert. 
00572     String_32 CheckString( _T("0123456789.,") );
00573     INT32 LenCheckString = CheckString.Length();    
00574     BOOL Found = FALSE;
00575     TCHAR CheckChar;
00576     // Now go through every character in the check string and see if it exists in
00577     // the required new specifier string
00578     for (INT32 i = 0; ( (i < LenNewSpecifier) && (!Found) ); i++)
00579     {
00580         // Get the next character to be checked in the new specifier string
00581         CheckChar = ((const TCHAR*)NewSpecifier)[i];
00582         
00583         // Now compare this against all the characters in the validation string
00584         for (INT32 j = 0; ( (j < LenCheckString) && (!Found) ); j++)
00585         {
00586             if (((TCHAR*)CheckString)[j] == CheckChar)
00587             {
00588                 Found = TRUE;
00589             }
00590         }
00591     }
00592     // We found a problem character so return this result to the caller
00593     if (Found)
00594         return FALSE;       
00595 
00596     Specifier = NewSpecifier;
00597     
00598     return TRUE;
00599 }

BOOL Unit::SetToken const String_32 NewToken  ) 
 

Sets the token string for the unit. This is the full name of the unit in question E.g. "centimetres" specifies the default centimetres unit with the abbreviation or specifier of "cm". This must not be blank and must not contain numbers as otherwise number parsing may be difficult. Hence, new units should be labelled with A, B .... Hence also, updated to return BOOL 4/9/95 so can return to the setter the fact that the new specifier cannot be allowed.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewToken = new token string [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.
See also:
Unit::GetToken; DocUnitList::GetSpecifier;

Definition at line 507 of file units.cpp.

00508 {
00509     // Sanity checks
00510     // - ensure not zero length
00511     // - should really check for duplicates as unless we allow for overiding of preset units
00512     // - should check for dodgy characters such as numbers as these may be very bad
00513     if (NewToken.Length() == 0)
00514         return FALSE;
00515 
00516     Token = NewToken;
00517 
00518     return TRUE;
00519 }

BOOL Unit::SetUnitType UnitType  NewUnitType  ) 
 

Sets the UnitType for the unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/6/94
Parameters:
NewUnitType = new UnitType string [INPUTS]
- [OUTPUTS]
Returns:
True is set ok, False otherwise.

Definition at line 632 of file units.cpp.

00633 {
00634     ThisUnitType = NewUnitType;
00635     
00636     return TRUE;
00637 }


Member Data Documentation

double Unit::BaseDenominator [private]
 

Definition at line 225 of file units.h.

double Unit::BaseNumerator [private]
 

Definition at line 224 of file units.h.

UnitType Unit::BaseUnitType [private]
 

Definition at line 223 of file units.h.

UnitFlagsType Unit::Flags [private]
 

Definition at line 214 of file units.h.

double Unit::Millipoints [private]
 

Definition at line 211 of file units.h.

String_32 Unit::Specifier [private]
 

Definition at line 233 of file units.h.

UnitType Unit::ThisUnitType [private]
 

Definition at line 205 of file units.h.

String_32 Unit::Token [private]
 

Definition at line 232 of file units.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:02:39 2007 for Camelot by  doxygen 1.4.4