Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
/* -------------------------------------------------------------------- */
/* */
/* FILE : sdata.h */
/* */
/* DESC : Sampler data definition. */
/* */
/* PROJ : CSA\sampler */
/* */
/* CREATED 16.02.98 19:28 by L&M. */
/* MODIFIED 03.02.99 13:27 by A.V. */
/* */
/* */
/* 1995-98 (c) by Leonid Moiseichuk */
/* -------------------------------------------------------------------- */
#ifndef __sdata_h
#define __sdata_h
/* ==========================[ includes ]============================== */
#ifndef __MEM_H
#include <Mem.h>
#endif
#ifndef __STRING_H
#include <String.h>
#endif
#ifndef __DIR_H
#include <Dir.h>
#endif
#ifndef __STDIO_H
#include <StdIO.h>
#endif
#ifndef __timer_h
#include "Timer.h"
#endif
/* ===========================[ defines ]============================== */
typedef const char far* PChar;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef char FileName[ MAXPATH ];
typedef uchar FileHandle;
#define MAX_FILES 8u
// Maximum 8 files
#define MAX_LINES 52u
// Maximum of sampling lines in a file
#define MAX_CONDS 8u
// Maximum of conditions for each line
#define MAX_ENTRIES (MAX_FILES * MAX_LINES)
/*
-----------------------------------------------------------------------
Size of SamplerList is MAX_CONDS * 9 + 4 ( current 76 bytes ).
We create MAX_ENTRIES SamplerLists :
== > this array will be little 64K
==> Sizeof(SamplerList) * MAX_ENTRIES < 64K
==> MAX_ENTRIES < 862.
Thus, if have 10 sampling files, we can have 86 lines at a each file.
-----------------------------------------------------------------------
*/
/* ===========================[ classes ]============================== */
class FileMgr
{
public :
FileMgr() : Counter(0)
{ memset( Files,0,sizeof(Files) ); }
~FileMgr() {}
FileHandle HandleOf( PChar );
void Print( FILE* Stream ) const;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
PChar NameOf( FileHandle index ) const;
uint Count () { return Counter; }
private :
FileName Files[ MAX_FILES ];
FileHandle Counter ;
}; // Class FileMgr
inline PChar FileMgr :: NameOf( FileHandle index ) const
{
return (index && index<=Counter ? PChar(Files[index-1]) : NULL);
}
class Locate
{
public :
Locate() : File(0), Line(0)
{}
Locate( FileHandle file, uint line ) : File(file), Line(line)
{}
int operator==( const Locate& aTest ) const
{ return (File==aTest.File && Line==aTest.Line); }
int operator <( const Locate& aTest ) const
{ return ( File<aTest.File ? 1 : (File==aTest.File && Line<aTest.Line) ); }
void operator =( const Locate& aSet )
{
File = aSet.File ;
Line = aSet.Line ;
}
void Print( FILE* Stream ) const
{ fprintf( Stream, "%2u :%4u",uint(File),Line ); }
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
operator int() const
{ return File && Line; }
FileHandle FileID () { return File; }
uint LineNo () { return Line; }
protected :
FileHandle File;
uint Line;
}; // Class Locate
/* Inlines */
inline void Locate :: Put( FILE* Stream ) const
{
fwrite (&File,sizeof(File),1,Stream);
fwrite (&Line,sizeof(Line),1,Stream);
}
inline void Locate :: Get( FILE* Stream )
{
fread (&File,sizeof(File),1,Stream);
fread (&Line,sizeof(Line),1,Stream);
}
class SamplerRecord : public Locate
{
public :
SamplerRecord() { Prob = 0; }
void operator += ( const SamplerRecord& forAdd );
void Print( FILE* Stream, TIME ttime, Tscl Scale) const ;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
public :
TIME TotalTime ; /* Totals timing */
uint CrossTimes; /* How march times call */
float Prob;
}; // Class SamplerRecord
/* Inlines */
inline void SamplerRecord :: operator += ( const SamplerRecord& forAdd )
{
if ( Line>0 )
{
CrossTimes ++ ;
TotalTime += forAdd.TotalTime ;
}
else
memcpy(this,&forAdd,sizeof(SamplerRecord) );
} // operator +=
inline void SamplerRecord :: Print(FILE* Stream, TIME _ctime, Tscl Scale) const
{
double precTime = 0.0;
TIME corrTime(UINT32(_ctime)*CrossTimes);
if (TotalTime > corrTime)
precTime = TimeAsMicroSeconds(TotalTime - corrTime, Scale);
Locate::Print(Stream);
fprintf( Stream," %19.2lf %12u %6.2lf %17.2lf", precTime, CrossTimes, Prob, precTime/CrossTimes);
} // Print
inline void SamplerRecord :: Put( FILE* Stream ) const
{
Locate :: Put (Stream);
fwrite (&TotalTime,sizeof(TotalTime),1,Stream);
fwrite (&CrossTimes,sizeof(CrossTimes),1,Stream);
}
inline void SamplerRecord :: Get( FILE* Stream )
{
Locate :: Get (Stream);
fread (&TotalTime,sizeof(TotalTime),1,Stream);
fread (&CrossTimes,sizeof(CrossTimes),1,Stream);
}
struct SumOfInProbsInfo{
float Prob;
long CrossTimes;
};
/* --- Class SamplerList --- */
class SamplerList : public Locate
{
public :
SamplerList() : Counter(0), Prob(0), InArcs(0), SubCounter(0), SubEntriesPtr(0)
{ memset( Conditions,0,sizeof(Conditions) ); }
~SamplerList() {}
void Append( const SamplerRecord& rec );
void Print( FILE* Stream, TIME ttime, Tscl Scale) const ;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
SamplerRecord* CondOf( uchar idx )
{ return ( idx < Counter ? &(Conditions[idx]) : 0 ); }
uchar Count () { return Counter; }
typedef SamplerList* SmpLstArr[ MAX_ENTRIES]; //IV
SmpLstArr* SubEntriesPtr; //Pointer at Entries member of Access class
uint SubCounter ; //The number of elements in Entries
float Prob;
uint InArcs;
//both are to be initialized in run-time
// void LoadArc(uchar idx, float ProbVal); //IV
SumOfInProbsInfo SumOfInProbs();
private :
SamplerRecord Conditions[ MAX_CONDS ]; /* Refs for some conds to this line */
uchar Counter ; /* Counter for using records */
}; // Class SamplerList
class Storage
{
public :
Storage() : Counter(0)
{}
~Storage() {}
SamplerList* Allocate()
{ return ( Counter<MAX_ENTRIES ? &Space[Counter++] : NULL ); }
private :
SamplerList Space[ MAX_ENTRIES ]; /* The space for allocation */
uint Counter ;
}; // Class Storage
class Access
{
public :
Access() : Counter(0), timeTrue(0), corrNum(0)
{ memset( Entries,0,sizeof(Entries) );}
~Access() {}
SamplerList* Search( const Locate& ) const;
SamplerList* Search( const FileHandle, const uint, uint& ) const;
void Append( SamplerList* );
void Print( FILE* Stream ) const ;
void TrueTime (TIME ttrue);
TIME TrueTime ();
void CorrScale (Tscl Scale);
Tscl CorrScale ();
SamplerList* At (uint idx);
uint Count () { return Counter; }
void MapProbs();
private :
TIME timeTrue; /* Є®а४жЁп Ё§¬ҐаҐЁп ў вЁЄ е */
Tscl corrNum; /* Є®а४жЁп ¬ бив ЎЁа®ў Ёп */
SamplerList* Entries[ MAX_ENTRIES ];
uint Counter ;
friend class CallsHandler;
}; // Class Access
inline void Access :: TrueTime (TIME ttrue)
{
timeTrue = ttrue;
}
inline TIME Access :: TrueTime ()
{
return timeTrue ;
}
inline void Access :: CorrScale (Tscl Scale)
{
corrNum = Scale;
}
inline Tscl Access :: CorrScale ()
{
return corrNum ;
}
inline SamplerList* Access :: At (uint idx)
{
return ( idx < Counter ? Entries[idx] : NULL );
}
class CallsHandler
{
public :
CallsHandler();
~CallsHandler();
TIME TrueTime();
void TrueTime (TIME ttrue);
void CorrScale (Tscl Scale);
Tscl CorrScale ();
void Handle( TIME time, PChar File, uint Line );
void Print( FILE* , PChar Prog ) const ;
void Put( FILE* Stream ) const ;
int Get( FILE* Stream ) ;
void PrintCSA( FILE*, PChar Prog ) const ; //IV
operator int() const
{ return (SamplerAccess && SamplerStorage && SamplerFiles); }
public :
Access* SamplerAccess ;
Storage* SamplerStorage;
FileMgr* SamplerFiles ;
SamplerList* LastUsedRec;
}; // Class CallsHandler
inline void CallsHandler :: TrueTime (TIME ttrue)
{
if (SamplerAccess) SamplerAccess->TrueTime(ttrue);
}
inline TIME CallsHandler :: TrueTime ()
{
return ( (SamplerAccess)? SamplerAccess->TrueTime() : 0ul) ;
}
inline void CallsHandler :: CorrScale (Tscl Scale)
{
if (SamplerAccess) SamplerAccess->CorrScale (Scale);
}
inline Tscl CallsHandler :: CorrScale ()
{
return ( (SamplerAccess)? SamplerAccess->CorrScale() : 0) ;
}
#endif // Sentry of __sdata_h
/* */
/* FILE : sdata.h */
/* */
/* DESC : Sampler data definition. */
/* */
/* PROJ : CSA\sampler */
/* */
/* CREATED 16.02.98 19:28 by L&M. */
/* MODIFIED 03.02.99 13:27 by A.V. */
/* */
/* */
/* 1995-98 (c) by Leonid Moiseichuk */
/* -------------------------------------------------------------------- */
#ifndef __sdata_h
#define __sdata_h
/* ==========================[ includes ]============================== */
#ifndef __MEM_H
#include <Mem.h>
#endif
#ifndef __STRING_H
#include <String.h>
#endif
#ifndef __DIR_H
#include <Dir.h>
#endif
#ifndef __STDIO_H
#include <StdIO.h>
#endif
#ifndef __timer_h
#include "Timer.h"
#endif
/* ===========================[ defines ]============================== */
typedef const char far* PChar;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef char FileName[ MAXPATH ];
typedef uchar FileHandle;
#define MAX_FILES 8u
// Maximum 8 files
#define MAX_LINES 52u
// Maximum of sampling lines in a file
#define MAX_CONDS 8u
// Maximum of conditions for each line
#define MAX_ENTRIES (MAX_FILES * MAX_LINES)
/*
-----------------------------------------------------------------------
Size of SamplerList is MAX_CONDS * 9 + 4 ( current 76 bytes ).
We create MAX_ENTRIES SamplerLists :
== > this array will be little 64K
==> Sizeof(SamplerList) * MAX_ENTRIES < 64K
==> MAX_ENTRIES < 862.
Thus, if have 10 sampling files, we can have 86 lines at a each file.
-----------------------------------------------------------------------
*/
/* ===========================[ classes ]============================== */
class FileMgr
{
public :
FileMgr() : Counter(0)
{ memset( Files,0,sizeof(Files) ); }
~FileMgr() {}
FileHandle HandleOf( PChar );
void Print( FILE* Stream ) const;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
PChar NameOf( FileHandle index ) const;
uint Count () { return Counter; }
private :
FileName Files[ MAX_FILES ];
FileHandle Counter ;
}; // Class FileMgr
inline PChar FileMgr :: NameOf( FileHandle index ) const
{
return (index && index<=Counter ? PChar(Files[index-1]) : NULL);
}
class Locate
{
public :
Locate() : File(0), Line(0)
{}
Locate( FileHandle file, uint line ) : File(file), Line(line)
{}
int operator==( const Locate& aTest ) const
{ return (File==aTest.File && Line==aTest.Line); }
int operator <( const Locate& aTest ) const
{ return ( File<aTest.File ? 1 : (File==aTest.File && Line<aTest.Line) ); }
void operator =( const Locate& aSet )
{
File = aSet.File ;
Line = aSet.Line ;
}
void Print( FILE* Stream ) const
{ fprintf( Stream, "%2u :%4u",uint(File),Line ); }
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
operator int() const
{ return File && Line; }
FileHandle FileID () { return File; }
uint LineNo () { return Line; }
protected :
FileHandle File;
uint Line;
}; // Class Locate
/* Inlines */
inline void Locate :: Put( FILE* Stream ) const
{
fwrite (&File,sizeof(File),1,Stream);
fwrite (&Line,sizeof(Line),1,Stream);
}
inline void Locate :: Get( FILE* Stream )
{
fread (&File,sizeof(File),1,Stream);
fread (&Line,sizeof(Line),1,Stream);
}
class SamplerRecord : public Locate
{
public :
SamplerRecord() { Prob = 0; }
void operator += ( const SamplerRecord& forAdd );
void Print( FILE* Stream, TIME ttime, Tscl Scale) const ;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
public :
TIME TotalTime ; /* Totals timing */
uint CrossTimes; /* How march times call */
float Prob;
}; // Class SamplerRecord
/* Inlines */
inline void SamplerRecord :: operator += ( const SamplerRecord& forAdd )
{
if ( Line>0 )
{
CrossTimes ++ ;
TotalTime += forAdd.TotalTime ;
}
else
memcpy(this,&forAdd,sizeof(SamplerRecord) );
} // operator +=
inline void SamplerRecord :: Print(FILE* Stream, TIME _ctime, Tscl Scale) const
{
double precTime = 0.0;
TIME corrTime(UINT32(_ctime)*CrossTimes);
if (TotalTime > corrTime)
precTime = TimeAsMicroSeconds(TotalTime - corrTime, Scale);
Locate::Print(Stream);
fprintf( Stream," %19.2lf %12u %6.2lf %17.2lf", precTime, CrossTimes, Prob, precTime/CrossTimes);
inline void SamplerRecord :: Put( FILE* Stream ) const
{
Locate :: Put (Stream);
fwrite (&TotalTime,sizeof(TotalTime),1,Stream);
fwrite (&CrossTimes,sizeof(CrossTimes),1,Stream);
}
inline void SamplerRecord :: Get( FILE* Stream )
{
Locate :: Get (Stream);
fread (&TotalTime,sizeof(TotalTime),1,Stream);
fread (&CrossTimes,sizeof(CrossTimes),1,Stream);
}
struct SumOfInProbsInfo{
float Prob;
long CrossTimes;
};
/* --- Class SamplerList --- */
class SamplerList : public Locate
{
public :
SamplerList() : Counter(0), Prob(0), InArcs(0), SubCounter(0), SubEntriesPtr(0)
{ memset( Conditions,0,sizeof(Conditions) ); }
~SamplerList() {}
void Append( const SamplerRecord& rec );
void Print( FILE* Stream, TIME ttime, Tscl Scale) const ;
void Put( FILE* Stream ) const ;
void Get( FILE* Stream ) ;
SamplerRecord* CondOf( uchar idx )
{ return ( idx < Counter ? &(Conditions[idx]) : 0 ); }
uchar Count () { return Counter; }
typedef SamplerList* SmpLstArr[ MAX_ENTRIES]; //IV
SmpLstArr* SubEntriesPtr; //Pointer at Entries member of Access class
uint SubCounter ; //The number of elements in Entries
float Prob;
uint InArcs;
//both are to be initialized in run-time
// void LoadArc(uchar idx, float ProbVal); //IV
SumOfInProbsInfo SumOfInProbs();
private :
SamplerRecord Conditions[ MAX_CONDS ]; /* Refs for some conds to this line */
uchar Counter ; /* Counter for using records */
}; // Class SamplerList
class Storage
{
public :
Storage() : Counter(0)
{}
~Storage() {}
SamplerList* Allocate()
{ return ( Counter<MAX_ENTRIES ? &Space[Counter++] : NULL ); }
private :
SamplerList Space[ MAX_ENTRIES ]; /* The space for allocation */
uint Counter ;
}; // Class Storage
class Access
{
public :
Access() : Counter(0), timeTrue(0), corrNum(0)
{ memset( Entries,0,sizeof(Entries) );}
~Access() {}
SamplerList* Search( const Locate& ) const;
SamplerList* Search( const FileHandle, const uint, uint& ) const;
void Append( SamplerList* );
void Print( FILE* Stream ) const ;
void TrueTime (TIME ttrue);
TIME TrueTime ();
void CorrScale (Tscl Scale);
Tscl CorrScale ();
SamplerList* At (uint idx);
uint Count () { return Counter; }
void MapProbs();
private :
TIME timeTrue; /* Є®а४жЁп Ё§¬ҐаҐЁп ў вЁЄ е */
Tscl corrNum; /* Є®а४жЁп ¬ бив ЎЁа®ў Ёп */
SamplerList* Entries[ MAX_ENTRIES ];
uint Counter ;
friend class CallsHandler;
}; // Class Access
inline void Access :: TrueTime (TIME ttrue)
{
timeTrue = ttrue;
}
inline TIME Access :: TrueTime ()
{
return timeTrue ;
}
inline void Access :: CorrScale (Tscl Scale)
{
corrNum = Scale;
}
inline Tscl Access :: CorrScale ()
{
return corrNum ;
}
inline SamplerList* Access :: At (uint idx)
{
return ( idx < Counter ? Entries[idx] : NULL );
}
class CallsHandler
{
public :
CallsHandler();
~CallsHandler();
TIME TrueTime();
void TrueTime (TIME ttrue);
void CorrScale (Tscl Scale);
Tscl CorrScale ();
void Handle( TIME time, PChar File, uint Line );
void Print( FILE* , PChar Prog ) const ;
void Put( FILE* Stream ) const ;
int Get( FILE* Stream ) ;
void PrintCSA( FILE*, PChar Prog ) const ; //IV
operator int() const
{ return (SamplerAccess && SamplerStorage && SamplerFiles); }
public :
Access* SamplerAccess ;
Storage* SamplerStorage;
FileMgr* SamplerFiles ;
SamplerList* LastUsedRec;
}; // Class CallsHandler
inline void CallsHandler :: TrueTime (TIME ttrue)
{
if (SamplerAccess) SamplerAccess->TrueTime(ttrue);
}
inline TIME CallsHandler :: TrueTime ()
{
return ( (SamplerAccess)? SamplerAccess->TrueTime() : 0ul) ;
}
inline void CallsHandler :: CorrScale (Tscl Scale)
{
if (SamplerAccess) SamplerAccess->CorrScale (Scale);
}
inline Tscl CallsHandler :: CorrScale ()
{
return ( (SamplerAccess)? SamplerAccess->CorrScale() : 0) ;
}
#endif // Sentry of __sdata_h
Соседние файлы в папке Samp16