Guest User

Untitled

a guest
Jan 24th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1.  
  2. #include <QTime>
  3. #include <QDebug>
  4. #include <QString>
  5. #include <QVector>
  6. #include <QMap>
  7.  
  8. class Profile {
  9.  
  10.     QString mId;
  11.  
  12.     QVector <quint32 *> mIData;
  13.     QVector <float *> mFData;
  14.  
  15.     public:
  16.  
  17.         friend class Profiler;
  18.  
  19.         explicit Profile (const QString &id) : mId (id) {
  20.  
  21.             mIData.clear();
  22.             mFData.clear();
  23.         }
  24.  
  25.         Profile & operator << (quint32 *v) {
  26.  
  27.             mIData.push_back (v);
  28.  
  29.             return *this;
  30.         }
  31.  
  32.         Profile & operator << (float *v) {
  33.  
  34.             mFData.push_back (v);
  35.  
  36.             return *this;
  37.         }
  38.  
  39.         void step () {
  40.  
  41.             foreach (quint32 *q, mIData) {
  42.  
  43.                 qDebug () << "QUINT:" << *q;
  44.             }
  45.  
  46.             foreach (float *f, mFData) {
  47.  
  48.                 qDebug () << "FLOAT:" << *f;
  49.             }
  50.         }
  51.  
  52.  
  53.  
  54. };
  55.  
  56. class Profiler {
  57.  
  58.     bool mIsProfiling;
  59.    
  60.     QMap <QString, Profile *> mProfiles;
  61.  
  62.     public:
  63.  
  64.         Profiler () : mIsProfiling (false) {
  65.  
  66.             mProfiles.clear();
  67.         }
  68.  
  69.         ~Profiler () {
  70.  
  71.             //qDeleteAll (mProfiles);
  72.  
  73.         }
  74.  
  75.         bool isProfiling () const {
  76.  
  77.             return mIsProfiling;
  78.         }
  79.  
  80.         void step () {
  81.  
  82.             foreach (Profile *p, mProfiles) {
  83.            
  84.                 p->step();
  85.             }    
  86.         }
  87.  
  88.         Profiler & operator << (Profile *p) {
  89.  
  90.             mProfiles[p->mId] = p;
  91.  
  92.             return *this;
  93.         }
  94.  
  95. };
  96.  
  97. int main (int argc, char *argv[]) {
  98.  
  99.     // Create a new profile
  100.     Profile p ("Test");
  101.    
  102.     // Create two variables to track
  103.     quint32 a = 34234;
  104.     quint32 b = 53535;
  105.  
  106.     p << &a;
  107.     p << &b;
  108.  
  109.     // Create the profiler
  110.     Profiler go;
  111.     go << &p;
  112.  
  113.     QTime midnight (0, 0, 0);
  114.     qsrand (midnight.secsTo (QTime::currentTime()));
  115.  
  116.     a = qrand() % a;
  117.     b = qrand() % b;
  118.     qDebug () << "real a: " << a;
  119.     qDebug () << "real b: " << b;
  120.  
  121.     go.step ();
  122.  
  123.     return 0;
  124. }
Add Comment
Please, Sign In to add comment