ValueFunctionRandom Class Reference

#include <valfunc.h>

Inheritance diagram for ValueFunctionRandom:

ValueFunction ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 ValueFunctionRandom (UINT32 Seed=0, double Min=0.8, double Max=1.0)
 Constructor The Random ValueFunction returns a pseudo-random value between Min & Max.
virtual double GetValue (double Position)
 To read the value of this function at a given position.
virtual ValueFunctionClone (void)
 Clone operator. Creates an exact copy of this object.
virtual BOOL IsDifferent (ValueFunction *pOther)
 Comparator. Determines if 2 different ValueFunction objects are considered different.
virtual CamelotFileRecordWriteFileRecord (INT32 RecordTag, INT32 ExtraBytes, BaseCamelotFilter *pFilter)
 Saves a ValueFunction object to a Xara file. This function will create a new variable-sized record with the given record tag, and will write out whatever data is needed to save this ValueFunction's state to the file.
virtual ValueFunctionID GetUniqueID (void)

Protected Member Functions

virtual ValueFunctionCreateAndReadFileRecord (CXaraFileRecord *pInputRecord)
 Loads a ValueFunction object from a record which was saved into a file using the WriteFileRecord call. This is called by the base class loader routine ReadFileRecord, which finds an appropriate instance of a derived class to call to load the data in question.

Protected Attributes

short Array [NumRandomValues]
UINT32 SeedValue
double MinValue
double MaxValue

Private Member Functions

 CC_DECLARE_DYNAMIC (ValueFunctionRandom)

Detailed Description

Definition at line 318 of file valfunc.h.


Constructor & Destructor Documentation

ValueFunctionRandom::ValueFunctionRandom UINT32  Seed = 0,
double  Min = 0.8,
double  Max = 1.0
 

Constructor The Random ValueFunction returns a pseudo-random value between Min & Max.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/12/96
Parameters:
Seed - The base random-number seed. This is combined with the [INPUTS] position value to generate a "random" number that will not change for any given position/seed combination.
Min - The minimum value you want returned Max - The maximum value you want returned

Definition at line 692 of file valfunc.cpp.

00693 {
00694     ERROR3IF(Min > Max, "ValueFunctionRandom: Min should be smaller than Max");
00695 
00696     MinValue = Min;
00697     MaxValue = Max;
00698     SeedValue = Seed;
00699 
00700     // Fill in the array with random values
00701     srand(SeedValue);
00702     for (INT32 i = 0; i < NumRandomValues; i++)
00703         Array[i] = rand() & 0xffff;
00704 }


Member Function Documentation

ValueFunctionRandom::CC_DECLARE_DYNAMIC ValueFunctionRandom   )  [private]
 

ValueFunction * ValueFunctionRandom::Clone void   )  [virtual]
 

Clone operator. Creates an exact copy of this object.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/1/97
Returns:
NULL if it failed, else an exact copy of this object

Implements ValueFunction.

Definition at line 765 of file valfunc.cpp.

00766 {
00767     ValueFunction *pClone = new ValueFunctionRandom(SeedValue, MinValue, MaxValue);
00768     return(pClone);
00769 }

ValueFunction * ValueFunctionRandom::CreateAndReadFileRecord CXaraFileRecord pInputRecord  )  [protected, virtual]
 

Loads a ValueFunction object from a record which was saved into a file using the WriteFileRecord call. This is called by the base class loader routine ReadFileRecord, which finds an appropriate instance of a derived class to call to load the data in question.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/1/97
Parameters:
pInputRecord - The file record to read [INPUTS]
Returns:
NULL if it failed, else a pointer to new ValueFunction object representing whatever was saved in that record.
This method creates a new instance of this particular ValueFunction class and then loads whatever information is necessary from the file to initialise itself properly. The record read-pointer is left pointing at the end of the ValueFunction-saved data so that the caller can continue reading their extra bytes of data after loading the ValueFunction.

See also:
ValueFunctionRandom::WriteFileRecord; ValueFunctionRandom::ReadFileRecord

Implements ValueFunction.

Definition at line 903 of file valfunc.cpp.

00904 {
00905     ERROR3IF(pInputRecord == NULL, "Illegal NULL param");
00906 
00907     UINT32 SeedValue = 1;
00908     float MinValue = (float) 0.0;
00909     float MaxValue = (float) 0.0;
00910 
00911     pInputRecord->ReadUINT32(&SeedValue);
00912     pInputRecord->ReadFLOAT(&MinValue);
00913     pInputRecord->ReadFLOAT(&MaxValue);
00914 
00915     return(new ValueFunctionRandom((UINT32) SeedValue, (double) MinValue, (double) MinValue));
00916 }

virtual ValueFunctionID ValueFunctionRandom::GetUniqueID void   )  [inline, virtual]
 

Implements ValueFunction.

Definition at line 331 of file valfunc.h.

00331 { return(ValueFunctionID_Random); };

double ValueFunctionRandom::GetValue double  Position  )  [virtual]
 

To read the value of this function at a given position.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/12/96
Parameters:
Position - A value between 0.0 and 1.0 [INPUTS]
Returns:
A "Random" value (based on the Seed, Min, and Max values given to the constructor) representing the value of the function at the given Position.
Notes: Random returns a pseudo-random value based on the position and the Seed value, and clamped within the range given to the constructor. If the Seed/Min/Max values are unchanged, the same position will always return the same value.

Implements ValueFunction.

Definition at line 728 of file valfunc.cpp.

00729 {
00730     // Determine which array entry to use, and how much to linearly interpolate
00731     // between it and the next value
00732     INT32 Index = (INT32) floor(Position * (double)(0x400 * (NumRandomValues - 2)));
00733     double MixFraction = (double)(Index & 0x3ff) / (double)0x3ff;
00734 
00735     // Scale the Index value down into the proper range now, and make sure it's safe
00736     Index /= 0x400;
00737     if (Index < 0)
00738         Index = 0;
00739     if (Index > NumRandomValues - 2)
00740         Index = NumRandomValues - 2;
00741 
00742     // Get a random number between 0.0 and 1.0
00743     double Value = ((double)Array[Index] * (1.0 - MixFraction)) + ((double)Array[Index+1] * MixFraction);
00744     Value /= (double) 0xffff;
00745 
00746     // And scale the result into the range specified by the caller
00747     return( MinValue + (Value * (MaxValue - MinValue)) );
00748 }

BOOL ValueFunctionRandom::IsDifferent ValueFunction pOther  )  [virtual]
 

Comparator. Determines if 2 different ValueFunction objects are considered different.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/1/97
Parameters:
pOther - Another ValueFunction object to compare this one to [INPUTS]
Returns:
TRUE, always

Reimplemented from ValueFunction.

Definition at line 790 of file valfunc.cpp.

00791 {
00792     return(TRUE);       // Random value functions always consider themselves different
00793 }

CamelotFileRecord * ValueFunctionRandom::WriteFileRecord INT32  RecordTag,
INT32  ExtraBytes,
BaseCamelotFilter pFilter
[virtual]
 

Saves a ValueFunction object to a Xara file. This function will create a new variable-sized record with the given record tag, and will write out whatever data is needed to save this ValueFunction's state to the file.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/1/97
Parameters:
RecordTag - the tag to write this record under [INPUTS] ExtraBytes - The number of extra bytes of information the caller will write into the record after caling this function (Space for this many extra bytes will be reserved by this function when it creates the new file record) This may be 0 or more bytes. pFilter - The filter to write to
Returns:
NULL if it failed, else a pointer to a record which saves the state of this valueFunction object. Once the caller has written the record, they MUST DELETE it.
"ExtraBytes" bytes will be added to the record size to reserve space at the end of the record for the caller to add their own data. This is to allow ValueFunctions to be saved embedded in other object's record structures (e.g. inside different types of attributes).

All ValueFunction record data has 3 sections, whiich are recorded as follows: 1. ValueFunction header, identifying which type of VF is being saved INT32 ValueFunctionUniqueID (4 bytes) 2. Derived-class-data (0 or more bytes). This particular class adds: UINT32 SeedValue float MinValue float MaxValue (12 bytes) 3. Caller data. This is written by the caller to the returned record object. This data must be ExtraBytes (0 or more) bytes in length.

See also:
ValueFunctionRandom::CreateAndReadFileRecord

Implements ValueFunction.

Definition at line 841 of file valfunc.cpp.

00843 {
00844     ERROR3IF(pFilter == NULL, "Illegal NULL param");
00845     ERROR3IF(ExtraBytes < 0, "Stupid ExtraBytes request in ValueFunction::WriteFileRecord");
00846 
00847     // Calculate how many bytes of information this VF will write. We do not include
00848     // the header info written by the base class or the ExtraInfo desired by the caller -
00849     // the base class adds all that in for us.
00850     const INT32 MyRecordSize = 12;
00851 
00852     // Create an appropriate record, and write our data to it
00853     CamelotFileRecord *pRec = CreateAndWriteFileRecord(RecordTag, MyRecordSize, ExtraBytes, pFilter);
00854 
00855     if (pRec != NULL)
00856     {
00857         // Write out our ValueFunction's specific data. If it fails, then we'll return NULL
00858         BOOL ok = TRUE;
00859         if (ok)     ok = pRec->WriteUINT32((UINT32)SeedValue);
00860         if (ok)     ok = pRec->WriteFLOAT((float)MinValue);
00861         if (ok)     ok = pRec->WriteFLOAT((float)MaxValue);
00862 
00863         if (!ok)
00864         {
00865             delete pRec;
00866             pRec = NULL;
00867         }
00868     }
00869 
00870     return(pRec);
00871 }


Member Data Documentation

short ValueFunctionRandom::Array[NumRandomValues] [protected]
 

Definition at line 338 of file valfunc.h.

double ValueFunctionRandom::MaxValue [protected]
 

Definition at line 341 of file valfunc.h.

double ValueFunctionRandom::MinValue [protected]
 

Definition at line 340 of file valfunc.h.

UINT32 ValueFunctionRandom::SeedValue [protected]
 

Definition at line 339 of file valfunc.h.


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