ScaleUnit Class Reference

A ScaleUnit is defined by: A range for which the scaled value is between 0 & 1 A scaler which converts any value in its range to between 0 & 1 A qualifier which may be prefixed or suffixed onto the value NB: There are no base units as such. More...

#include <scunit.h>

Inheritance diagram for ScaleUnit:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 ScaleUnit ()
 Default constructor for a ScaleUnit giving a scale of 0 to 1 Scope: public.
 ScaleUnit (const double dScale, const double dMin, const double dMax)
 Constructor for a ScaleUnit Scope: Public.
 ScaleUnit (const double dScale, const UINT32 nDPtoShow)
 Constructor for a ScaleUnit, with a range 0..dScale. Scope: Public.
 ScaleUnit (const ScaleUnit &UnitToCopy)
 Copy constructor.
virtual ScaleUnitoperator= (const ScaleUnit &UnitToCopy)
 Assignment operator.
virtual ~ScaleUnit ()
 Default destructor for a ScaleUnit - does nothing Scope: public.
virtual BOOL operator== (const ScaleUnit &RhsUnit) const
 Compares two ScaleUnits for equality Scope: public.
virtual BOOL operator!= (const ScaleUnit &RhsUnit) const
 Compares two ScaleUnits for inequality Scope: public.
BOOL SetQualifier (Qualifier &NewQualifier)
 Allows the Qualifier for the given ScaleUnit to be specified Scope: public.
BOOL SetQualifier (const StringBase &QualifierParseString, const Qualifier::QUALIFIER_SHOWN WhetherShown)
 Allows the Qualifier for the given ScaleUnit to be specified Scope: public.
const QualifierGetQualifier () const
 Allows access to the Qualifier for the ScaleUnit. The Qualifier to which the returned value is pointing is read-only and should be copied if necessary. Scope: public.
BOOL SetDPtoShow (const UINT32 uNumber)
 When a value of this unit is displayed we may need to provide some default for the number of decimal places to display. This member sets that default. Scope: public.
UINT32 GetDPtoShow () const
 When displaying a number for a ScaleUnit we frequently wish to have it restricted to a given number of decimal places when displayed. This number is returned here to be used by display routines. Scope: public.
BOOL SetMin (const double dMin)
 The minimum value provides an offset from which numbers for this ScaleUnit will start when provided with 0 as the scaled value. Scope: public.
double GetMin () const
 Retrieves the starting offset value to be used by the conversion routines (or displaying the limits) Scope: public.
BOOL SetMax (const double dMax)
 The maximum value is the value for which, when scaled, 1 will be returned by ConvertTo0To1(). This member function allows that maximum to be set. Scope: public.
double GetMax () const
 Returns the maximum value, which when scaled will return 1. Scope: public.
BOOL SetScale (const double dScale)
 Sets the value by which all numbers in the given max & min will be scaled to produce a value between 0 & 1. Scope: public.
double GetScale () const
 Returns the value by which all numbers in the given max & min will be scaled to produce a value between 0 & 1. Scope: public.
BOOL SetRange (const double dMin, const double dMax)
BOOL ConvertTo0to1 (double &dValue) const
 Converts the given double to a value between 0 & 1 depending on the ScaleUnit's scale.
BOOL ConvertFrom0to1 (double &dValue) const
 Converts the given double to a value between 0 & 1 depending on the ScaleUnit's scale.
BOOL StringFromScale (double &dNumber, StringBase *pResult, const UINT32 uSigFigs) const
 Will produce a string of the form <number>[<qualifier>] | <qualifier><number> depending on the units specification.

Protected Attributes

double m_dScale
Qualifierm_pQualifier
UINT32 m_nDPtoShow
double m_dMin
double m_dMax

Private Attributes

BOOL m_bInternalQualifier

Detailed Description

A ScaleUnit is defined by: A range for which the scaled value is between 0 & 1 A scaler which converts any value in its range to between 0 & 1 A qualifier which may be prefixed or suffixed onto the value NB: There are no base units as such.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96

Definition at line 236 of file scunit.h.


Constructor & Destructor Documentation

ScaleUnit::ScaleUnit  ) 
 

Default constructor for a ScaleUnit giving a scale of 0 to 1 Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96

Definition at line 337 of file scunit.cpp.

00338 {
00339     m_dScale = 1.0;
00340     m_dMin = 0.0;
00341     m_dMax = 1.0;
00342     m_nDPtoShow = 0;
00343     m_bInternalQualifier = FALSE;
00344 }

ScaleUnit::ScaleUnit const double  dScale,
const double  dMin,
const double  dMax
 

Constructor for a ScaleUnit Scope: Public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dScale : The unit's scale [INPUTS] dMin : The unit's minimum for which the scale is defined dMax : The unit's minimum for which the scale is defined

Definition at line 360 of file scunit.cpp.

00361 {
00362     m_dScale = dScale;
00363     m_dMin = dMin;
00364     m_dMax = dMax;
00365     m_bInternalQualifier = FALSE;
00366 }

ScaleUnit::ScaleUnit const double  dScale,
const UINT32  nDPtoShow
 

Constructor for a ScaleUnit, with a range 0..dScale. Scope: Public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dScale : The unit's scale [INPUTS] nDPtoShow : The number of decimal places that should be shown when the number is scaled by this unit

Definition at line 383 of file scunit.cpp.

00384 {
00385     m_dScale = m_dMax = dScale;
00386     m_dMin = 0.0;
00387     m_nDPtoShow = nDPtoShow;
00388     m_bInternalQualifier = FALSE;
00389 }

ScaleUnit::ScaleUnit const ScaleUnit UnitToCopy  ) 
 

Copy constructor.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
UnitToCopy : the ScaleUnit from which to construct a replica [INPUTS]

Definition at line 402 of file scunit.cpp.

00403 {
00404     if (this == &UnitToCopy) return;
00405 
00406     m_dScale = UnitToCopy.m_dScale;
00407     m_dMin = UnitToCopy.m_dMin;
00408     m_dMax = UnitToCopy.m_dMax;
00409     m_pQualifier = UnitToCopy.m_pQualifier;
00410     m_nDPtoShow = UnitToCopy.m_nDPtoShow;
00411     m_bInternalQualifier = FALSE;
00412 }

ScaleUnit::~ScaleUnit  )  [virtual]
 

Default destructor for a ScaleUnit - does nothing Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96

Definition at line 451 of file scunit.cpp.

00452 {
00453     if (m_bInternalQualifier && m_pQualifier != NULL)
00454         delete m_pQualifier;
00455 }


Member Function Documentation

BOOL ScaleUnit::ConvertFrom0to1 double &  value  )  const
 

Converts the given double to a value between 0 & 1 depending on the ScaleUnit's scale.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
value : The value to be scaled [INPUTS]
value : The value scaled to between 0 & 1 [OUTPUTS]
Returns:
The current scale value

Errors: - Scope: public

See also:
ScaleUnit::SetScale, ScaleUnit::GetScale

Definition at line 822 of file scunit.cpp.

00823 {
00824     value *= m_dScale;
00825     return TRUE;
00826 }

BOOL ScaleUnit::ConvertTo0to1 double &  value  )  const
 

Converts the given double to a value between 0 & 1 depending on the ScaleUnit's scale.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
value : The value to be scaled [INPUTS]
value : The value scaled to between 0 & 1 [OUTPUTS]
Returns:
The current scale value

Errors: ERROR2 for zero value Scope: public

See also:
ScaleUnit::SetScale, ScaleUnit::GetScale

Definition at line 796 of file scunit.cpp.

00797 {
00798     ERROR2IF(m_dScale == 0, FALSE, "ScaleUnit scale is zero");
00799 
00800     value /= m_dScale;
00801     return TRUE;
00802 }

UINT32 ScaleUnit::GetDPtoShow  )  const
 

When displaying a number for a ScaleUnit we frequently wish to have it restricted to a given number of decimal places when displayed. This number is returned here to be used by display routines. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The number of decimal places to show
See also:
ScaleUnit::SetDPtoShow

Definition at line 653 of file scunit.cpp.

00654 {
00655     return m_nDPtoShow;
00656 }

double ScaleUnit::GetMax  )  const
 

Returns the maximum value, which when scaled will return 1. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The current maximum
See also:
ScaleUnit::SetMax

Definition at line 734 of file scunit.cpp.

00735 {
00736     return m_dMax;
00737 }

double ScaleUnit::GetMin  )  const
 

Retrieves the starting offset value to be used by the conversion routines (or displaying the limits) Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The current minimum
See also:
ScaleUnit::SetMin

Definition at line 693 of file scunit.cpp.

00694 {
00695     return m_dMin;
00696 }

const Qualifier * ScaleUnit::GetQualifier  )  const
 

Allows access to the Qualifier for the ScaleUnit. The Qualifier to which the returned value is pointing is read-only and should be copied if necessary. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the Qualifier for this ScaleUnit
See also:
UnitGroup::SetQualifier;

Definition at line 609 of file scunit.cpp.

00610 {
00611     return m_pQualifier;
00612 }

double ScaleUnit::GetScale  )  const
 

Returns the value by which all numbers in the given max & min will be scaled to produce a value between 0 & 1. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The current scale value
See also:
ScaleUnit::SetScale

Definition at line 774 of file scunit.cpp.

00775 {
00776     return m_dScale;
00777 }

BOOL ScaleUnit::operator!= const ScaleUnit rhsUnit  )  const [virtual]
 

Compares two ScaleUnits for inequality Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
rhsUnit : the unit on the right-hand side of the inequality test [INPUTS]
Returns:
TRUE this ScaleUnit is equal to rhsUnit FALSE otherwise
See also:
class ScaleUnit

Definition at line 497 of file scunit.cpp.

00498 {
00499     return !(*this == rhsUnit);
00500 }

ScaleUnit & ScaleUnit::operator= const ScaleUnit UnitToCopy  )  [virtual]
 

Assignment operator.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
UnitToCopy : ScaleUnit to which this will be assigned [INPUTS]

Definition at line 425 of file scunit.cpp.

00426 {
00427     if (this == &UnitToCopy) return *this;
00428 
00429     m_dScale = UnitToCopy.m_dScale;
00430     m_dMin = UnitToCopy.m_dMin;
00431     m_dMax = UnitToCopy.m_dMax;
00432     m_pQualifier = UnitToCopy.m_pQualifier;
00433     m_nDPtoShow = UnitToCopy.m_nDPtoShow;
00434     m_bInternalQualifier = FALSE;
00435 
00436     return *this;
00437 }

BOOL ScaleUnit::operator== const ScaleUnit rhsUnit  )  const [virtual]
 

Compares two ScaleUnits for equality Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
rhsUnit : the unit on the right-hand side of the equality test [INPUTS]
Returns:
TRUE if this ScaleUnit is equal to rhsUnit FALSE otherwise
See also:
class ScaleUnit

Definition at line 473 of file scunit.cpp.

00474 {
00475     return (m_dScale == rhsUnit.m_dScale &&
00476             m_pQualifier->GetToken() == rhsUnit.m_pQualifier->GetToken() &&
00477             m_dMin == rhsUnit.m_dMin &&
00478             m_dMax == rhsUnit.m_dMax &&
00479             m_nDPtoShow == rhsUnit.m_nDPtoShow);
00480 }

BOOL ScaleUnit::SetDPtoShow const UINT32  nNumber  ) 
 

When a value of this unit is displayed we may need to provide some default for the number of decimal places to display. This member sets that default. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
nNumber : The number of decimal places to show [INPUTS]
Returns:
TRUE if set ok FALSE otherwise.
See also:
ScaleUnit::GetDPtoShow

Definition at line 632 of file scunit.cpp.

00633 {
00634     m_nDPtoShow = nNumber;
00635     return TRUE;
00636 }

BOOL ScaleUnit::SetMax const double  dMax  ) 
 

The maximum value is the value for which, when scaled, 1 will be returned by ConvertTo0To1(). This member function allows that maximum to be set. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dMax : The new maximum value. [INPUTS]
Returns:
TRUE : if set ok FALSE : otherwise.
See also:
ScaleUnit::GetMax

Definition at line 716 of file scunit.cpp.

00717 {
00718     m_dMax = dMax;
00719     return TRUE;
00720 }

BOOL ScaleUnit::SetMin const double  dMin  ) 
 

The minimum value provides an offset from which numbers for this ScaleUnit will start when provided with 0 as the scaled value. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dMin : The new minimum value. [INPUTS]
Returns:
True is set ok, False otherwise.
See also:
ScaleUnit::GetMin

Definition at line 673 of file scunit.cpp.

00674 {
00675     m_dMin = dMin;
00676     return TRUE;
00677 }

BOOL ScaleUnit::SetQualifier const StringBase QualifierParseString,
const Qualifier::QUALIFIER_SHOWN  WhetherShown
 

Allows the Qualifier for the given ScaleUnit to be specified Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
ParseString : a string of the form "#1%sTOKEN" or "TOKEN'1%s" signifying the [INPUTS] position of the qualifier token (TOKEN) relative to the value it's qualifying (#1s). WhetherShown : either QUALIFIER_SHOWN::IS_SHOWN or QUALIFIER_SHOWN::IS_NOTSHOWN
- [OUTPUTS]
Returns:
TRUE : if set successfully FALSE : otherwise
See also:
UnitGroup::GetQualifier;

Definition at line 550 of file scunit.cpp.

00552 {
00553     const String_32 StringString = TEXT("#1%s");
00554     INT32 numberPosition = QualifierParseString.Sub(StringString);
00555     ERROR2IF(numberPosition == -1, FALSE, "invalid QualifierParseString");
00556 
00557     UINT32 tokenLength = QualifierParseString.Length() - StringString.Length();
00558 
00559     String_32 NewToken;
00560     Qualifier* pNewQualifier = NULL;
00561     if (tokenLength == 0)   // there is no token
00562     {
00563         pNewQualifier = new NullQualifier;
00564     }
00565     else
00566     {
00567         if (numberPosition == 0)        // numberPosition came first...we have a suffix qualifier
00568         {
00569             QualifierParseString.Right(&NewToken, tokenLength);
00570             pNewQualifier = new SuffixQualifier;
00571         }
00572         else
00573         {
00574             QualifierParseString.Left(&NewToken, tokenLength);
00575             pNewQualifier = new PrefixQualifier;
00576         }
00577     }
00578     if (pNewQualifier == NULL)
00579         return FALSE;
00580 
00581     if (pNewQualifier->SetAttributes(NewToken, WhetherShown) == FALSE)
00582     {
00583         delete pNewQualifier;
00584         return FALSE;
00585     }
00586 
00587     SetQualifier(*pNewQualifier);
00588     m_bInternalQualifier = TRUE;        // ensure the qualifier's deleted in the destructor
00589 
00590     return TRUE;    
00591 }

BOOL ScaleUnit::SetQualifier Qualifier NewQualifier  ) 
 

Allows the Qualifier for the given ScaleUnit to be specified Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
NewQualifier : the Qualifier to use for this ScaleUnit [INPUTS]
- [OUTPUTS]
Returns:
TRUE : if set successfully FALSE : otherwise
See also:
UnitGroup::GetQualifier;

Definition at line 521 of file scunit.cpp.

00522 {
00523     if (m_bInternalQualifier && m_pQualifier != NULL)
00524         delete m_pQualifier;
00525     m_bInternalQualifier = FALSE;
00526     m_pQualifier = &NewQualifier;
00527     return TRUE;
00528 }

BOOL ScaleUnit::SetRange const double  dMin,
const double  dMax
 

BOOL ScaleUnit::SetScale const double  dScale  ) 
 

Sets the value by which all numbers in the given max & min will be scaled to produce a value between 0 & 1. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dScale : the new scale value. [INPUTS]
Returns:
TRUE if set ok, FALSE otherwise.
See also:
ScaleUnit::GetScale

Definition at line 755 of file scunit.cpp.

00756 {
00757     m_dScale = dScale;
00758     return TRUE;
00759 }

BOOL ScaleUnit::StringFromScale double &  dNumber,
StringBase pResult,
const UINT32  uSigFigs
const
 

Will produce a string of the form <number>[<qualifier>] | <qualifier><number> depending on the units specification.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
dNumber : A scale from 0 - 1 [INPUTS] uSigFigs : The number of significant figures to be contained in the string
dNumber : dNumber scaled to the Unit range [OUTPUTS] pResult : A string containing the number & its qualifier
Returns:
TRUE : The conversion was achieved successfully FALSE : No can do

Errors: Parameter type checks Scope: public

Definition at line 849 of file scunit.cpp.

00850 {
00851     ERROR2IF(pResult == NULL, FALSE, "pResult is NULL");
00852     ERROR2IF(uSigFigs > 32, FALSE, "uSigFigs out of range");
00853 
00854     if (ConvertFrom0to1(dNumber) == FALSE)
00855         return FALSE;
00856 
00857     String_32 TempString;
00858     Convert::DoubleToString(dNumber, (StringBase*)&TempString, GetDPtoShow());
00859     TempString.Left(&TempString, uSigFigs);
00860 
00861     const Qualifier* pQualifier = GetQualifier();
00862     if (pQualifier == NULL)
00863     {
00864         return FALSE;
00865     }
00866     ERROR3IF(!pQualifier->IS_KIND_OF(Qualifier), "ScaleUnit::StringFromScale - pQualifier is not");
00867 
00868     // Return the number and stick the qualifier token in there somewhere if needed
00869     // ...that darned lack of subclassing. May take some thought to do it properly (for the
00870     // reverse conversion)
00871     pQualifier->MakeDisplayString(TempString, pResult);
00872     return TRUE;
00873 }


Member Data Documentation

BOOL ScaleUnit::m_bInternalQualifier [private]
 

Definition at line 300 of file scunit.h.

double ScaleUnit::m_dMax [protected]
 

Definition at line 296 of file scunit.h.

double ScaleUnit::m_dMin [protected]
 

Definition at line 295 of file scunit.h.

double ScaleUnit::m_dScale [protected]
 

Definition at line 283 of file scunit.h.

UINT32 ScaleUnit::m_nDPtoShow [protected]
 

Definition at line 291 of file scunit.h.

Qualifier* ScaleUnit::m_pQualifier [protected]
 

Definition at line 287 of file scunit.h.


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