File indexing completed on 2026-08-06 09:20:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef EVT_PRED_GEN_HH
0022 #define EVT_PRED_GEN_HH
0023
0024 #include <stdio.h>
0025
0026
0027
0028
0029
0030
0031
0032 template <class Generator, class Predicate>
0033 class EvtPredGen {
0034 public:
0035 typedef typename Generator::result_type result_type;
0036
0037 EvtPredGen() : itsTried( 0 ), itsPassed( 0 ) {}
0038
0039 EvtPredGen( Generator gen, Predicate pred ) :
0040 itsGen( gen ), itsPred( pred ), itsTried( 0 ), itsPassed( 0 )
0041 {
0042 }
0043
0044 EvtPredGen( const EvtPredGen& other ) :
0045 itsGen( other.itsGen ),
0046 itsPred( other.itsPred ),
0047 itsTried( other.itsTried ),
0048 itsPassed( other.itsPassed )
0049 {
0050 }
0051
0052 ~EvtPredGen() {}
0053
0054 result_type operator()()
0055 {
0056 int i = 0;
0057 int MAX = 10000;
0058 while ( i++ < MAX ) {
0059 itsTried++;
0060 result_type point = itsGen();
0061 if ( itsPred( point ) ) {
0062 itsPassed++;
0063 return point;
0064 }
0065 }
0066
0067 printf( "No random point generated after %d attempts\n", MAX );
0068 printf( "Sharp peak? Consider using pole compensation.\n" );
0069 printf( "I will now pick a point at random to return.\n" );
0070 return itsGen();
0071 }
0072
0073 inline int getTried() const { return itsTried; }
0074 inline int getPassed() const { return itsPassed; }
0075
0076 protected:
0077 Generator itsGen;
0078 Predicate itsPred;
0079 int itsTried;
0080 int itsPassed;
0081 };
0082
0083 #endif