Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QTime>
- #include <QDebug>
- #include <QString>
- #include <QVector>
- #include <QMap>
- class Profile {
- QString mId;
- QVector <quint32 *> mIData;
- QVector <float *> mFData;
- public:
- friend class Profiler;
- explicit Profile (const QString &id) : mId (id) {
- mIData.clear();
- mFData.clear();
- }
- Profile & operator << (quint32 *v) {
- mIData.push_back (v);
- return *this;
- }
- Profile & operator << (float *v) {
- mFData.push_back (v);
- return *this;
- }
- void step () {
- foreach (quint32 *q, mIData) {
- qDebug () << "QUINT:" << *q;
- }
- foreach (float *f, mFData) {
- qDebug () << "FLOAT:" << *f;
- }
- }
- };
- class Profiler {
- bool mIsProfiling;
- QMap <QString, Profile *> mProfiles;
- public:
- Profiler () : mIsProfiling (false) {
- mProfiles.clear();
- }
- ~Profiler () {
- //qDeleteAll (mProfiles);
- }
- bool isProfiling () const {
- return mIsProfiling;
- }
- void step () {
- foreach (Profile *p, mProfiles) {
- p->step();
- }
- }
- Profiler & operator << (Profile *p) {
- mProfiles[p->mId] = p;
- return *this;
- }
- };
- int main (int argc, char *argv[]) {
- // Create a new profile
- Profile p ("Test");
- // Create two variables to track
- quint32 a = 34234;
- quint32 b = 53535;
- p << &a;
- p << &b;
- // Create the profiler
- Profiler go;
- go << &p;
- QTime midnight (0, 0, 0);
- qsrand (midnight.secsTo (QTime::currentTime()));
- a = qrand() % a;
- b = qrand() % b;
- qDebug () << "real a: " << a;
- qDebug () << "real b: " << b;
- go.step ();
- return 0;
- }
Add Comment
Please, Sign In to add comment