Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

NewVal.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Fri Apr 22 17:37:24 EDT 2005 by ken@xorian.net         
00020 //      modified on Sun Jul 28 12:14:19 EDT 2002 by lken@remote.xorian.net 
00021 //      modified on Fri Jul 27 19:05:23 PDT 2001 by mann  
00022 //      modified on Mon Aug 31 14:13:01 PDT 1998 by heydon
00023 
00024 // basics
00025 #include <Basics.H>
00026 
00027 // fp
00028 #include <FP.H>
00029 
00030 // local includes
00031 #include "BitVector.H"
00032 #include "FV.H"
00033 #include "Model.H"
00034 #include "CacheIndex.H"
00035 #include "Derived.H"
00036 #include "VestaVal.H"
00037 #include "Debug.H"
00038 #include "NewVal.H"
00039 
00040 void NewVal::NewNames(/*OUT*/ FV::List& names, unsigned int num) throw ()
00041 {
00042     if (num < 1) num = Debug::MyRand(1, 5);
00043     names.len = num;
00044     names.name = NEW_ARRAY(FV::T, num);
00045     for (int i = 0; i < num; i++) {
00046         names.name[i] = FV::T("name-");
00047         char buff[20];
00048         int printLen = sprintf(buff, "%d", i);
00049         assert(printLen < 20);
00050         names.name[i] += FV::T(buff);
00051     }
00052 }
00053 
00054 void NewVal::NewFP(/*OUT*/ FP::Tag& fp, int vals) throw ()
00055 /* Initialize "fp" to a new, random fingerprint. */
00056 {
00057     int pk = Debug::MyRand(0, vals-1);
00058     fp = FP::Tag((char *)(&pk), sizeof(pk));
00059 }
00060 
00061 void NewVal::NewFPs(/*OUT*/ FP::List& fps, unsigned int num, int vals) throw ()
00062 {
00063     if (num < 1) num = Debug::MyRand(1, 5);
00064     fps.len = num;
00065     fps.fp = NEW_PTRFREE_ARRAY(FP::Tag, num);
00066     for (int i = 0; i < num; i++) {
00067         NewVal::NewFP(fps.fp[i], vals);
00068     }
00069 }
00070 
00071 void NewVal::NewModel(/*OUT*/ Model::T &model) throw ()
00072 {
00073     model = (Model::T)Debug::MyRand(0, 99999);
00074 }
00075 
00076 void NewVal::NewCI(/*OUT*/ CacheEntry::Index &index) throw ()
00077 {
00078     index = (CacheEntry::Index)Debug::MyRand(0, 9999);
00079 }
00080 
00081 void NewVal::NewCIs(/*OUT*/ CacheEntry::Indices &kids, unsigned int num)
00082   throw ()
00083 {
00084     if (num < 1) num = Debug::MyRand(1, 6);
00085     kids.len = num;
00086     kids.index = NEW_PTRFREE_ARRAY(CacheEntry::Index, num);
00087     for (int i = 0; i < num; i++) {
00088         NewVal::NewCI(kids.index[i]);
00089     }
00090 }
00091 
00092 void NewVal::NewDI(/*OUT*/ Derived::Index &index) throw ()
00093 {
00094     index = (Derived::Index)Debug::MyRand(0, 9999);
00095 }
00096 
00097 void NewVal::NewDIs(/*OUT*/ Derived::Indices &kids, unsigned int num) throw ()
00098 {
00099     if (num < 1) num = Debug::MyRand(1, 6);
00100     kids.len = num;
00101     kids.index = NEW_PTRFREE_ARRAY(Derived::Index, num);
00102     for (int i = 0; i < num; i++) {
00103         NewVal::NewDI(kids.index[i]);
00104     }
00105 }
00106 
00107 void NewVal::NewValue(/*OUT*/ VestaVal::T &value) throw ()
00108 {
00109     NewVal::NewFP(value.fp);
00110     NewVal::NewDIs(value.dis);
00111     value.len = (int)Debug::MyRand(1, 20);
00112     value.bytes = NEW_PTRFREE_ARRAY(char, value.len);
00113     for (int i = 0; i < value.len; i++) {
00114         value.bytes[i] = (char)Debug::MyRand(0, 255);
00115     }
00116 }
00117 
00118 void NewVal::NewBV(/*OUT*/ BitVector &bv) throw ()
00119 {
00120     int num = Debug::MyRand(0, 5), curr = -1;
00121     while (num-- > 0) {
00122         int skip = Debug::MyRand(1, 10);
00123         curr += skip;
00124         bv.Set(curr);
00125     }
00126 }
00127 
00128 void NewVal::NewBool(/*OUT*/ bool &b) throw ()
00129 {
00130     b = (Debug::MyRand(0, 1) == 0) ? false : true;
00131 }

Generated on Mon May 8 00:48:32 2006 for Vesta by  doxygen 1.4.2