× Go Back Go Back to Programming Section Menu Go Back to Home Page
Class_DateTime.h
/************************************************************************************************/
/*               File Name: Class_DateTime.h               Written by: Koral Eren               */
/************************************************************************************************/

// This class follows C++11 Standard. Please include [-std=c+11] for g++

#ifndef DATETIME_H_INCLUDED
#define DATETIME_H_INCLUDED

#include <iostream>
#include <chrono>
#include <ctime>
#include <sstream>
#include <string>
#include <iomanip>


using namespace std;
using namespace std::chrono;

class DateTime
{
    private:
        unsigned long long millisecondsSince_1January1970;
        unsigned long secondsSince_1January1970;
        unsigned int minutesSince_1January1970;
        unsigned int hoursSince_1January1970;
        unsigned int daysSince_1January1970;
        unsigned int monthsSince_1January1970;
        unsigned int yearsSince_1January1970;

        unsigned int thursdayWeeksSince_1January1970;
        unsigned int dayOfWeek;

        unsigned int millisecond;
        unsigned int second;
        unsigned int minute;
        unsigned int hour;
        unsigned int day;
        unsigned int month;
        unsigned int year;


        bool isLeapYear(unsigned int Year)
        {
            if (Year % 4 == 0)
            {
                if ((Year % 100 == 0) && (Year % 400 == 0))
                    return false;
                else
                    return true;
            }

            return false;
        }

        bool isLeapYear()
        {
            if (year % 4 == 0)
            {
                if ((year % 100 == 0) && (year % 400 == 0))
                    return false;
                else
                    return true;
            }

            return false;
        }

        unsigned int monthDays(unsigned int Month, unsigned int Year)
        {
            if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
                return 30;
            else if (Month == 2)
                return 28;
            else if (Month == 2 && isLeapYear(Year))
                return 29;
            else
                return 31;
        }

        unsigned int monthDays()
        {
            if (month == 4 || month == 6 || month == 9 || month == 11)
                return 30;
            else if (month == 2)
                return 28;
            else if (month == 2 && isLeapYear())
                return 29;
            else
                return 31;
        }

        void calculateYearMonth()
        {
            monthsSince_1January1970 = 0;
            yearsSince_1January1970 = 0;

            unsigned int i = 1;

            while(i< daysSince_1January1970)
            {
                if(isLeapYear(yearsSince_1January1970))
                {
                    i+= 366;
                    yearsSince_1January1970 ++;
                }
                else if (daysSince_1January1970 - i < 365)
                {
                    break;
                }
                else
                {
                    i+= 365;
                    yearsSince_1January1970 ++;
                }


            }

            unsigned int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

            if(isLeapYear(yearsSince_1January1970 + 1970))
                days[2]++;

            i = daysSince_1January1970 - i;

            unsigned int j = 1;
            unsigned int counter = 1;

            while ((i / days[j]) != 0)
            {
                i-=days[j];
                j++;
                counter ++;
            }

            monthsSince_1January1970 = yearsSince_1January1970 * 12 + counter;
        }

        void calculateDay ()
        {
            unsigned int sum = 0;

            for (unsigned int i = 1970; i 12 || day > 31 || month < 1 || day < 1 || year < 1970 || year > 2038 || hour > 23 || hour < 0 ||
                 minute > 59 || minute < 0 || second > 59 || second < 0 || millisecond > 999 || millisecond < 0)
            {
                cout << "\nCannot constuct specified object, constructing default object" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -1;
            }
            else if (monthDays(month, year) == 30 && (day > 30))
            {
                cout << "\nCannot constuct specified object, constructing default object" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -2;
            }
            else if (monthDays(month, year) == 29 && (day > 29))
            {
                cout << "\nCannot constuct specified object, constructing default object" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -3;
            }
            else if (monthDays(month, year) == 28 && (day > 28))
            {
                cout << "\nCannot constuct specified object, constructing default object" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -4;
            }

            return 1;
        }

        int parseSetDate (unsigned int year = 1970, unsigned int month = 1, unsigned int day = 0, unsigned int hour = 0, unsigned int minute = 0, unsigned int second = 0, unsigned int millisecond = 0)
        {
            if ( month > 12 || day > 31 || month < 1 || day < 1 || year < 1970 || year > 2038 || hour > 23 || hour < 0 ||
                 minute > 59 || minute < 0 || second > 59 || second < 0 || millisecond > 999 || millisecond < 0)
            {
                cout << "\nCannot set specified parameters, setting default parameters" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -1;
            }
            else if (monthDays(month, year) == 30 && (day > 30))
            {
                cout << "\nCannot set specified parameters, setting default parameters" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -2;
            }
            else if (monthDays(month, year) == 29 && (day > 29))
            {
                cout << "\nCannot set specified parameters, setting default parameters" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -3;
            }
            else if (monthDays(month, year) == 28 && (day > 28))
            {
                cout << "\nCannot set specified parameters, setting default parameters" << endl;
                millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
                setTimeVariables();
                return -4;
            }

            return 1;
        }


    public:
        DateTime()
        {
            millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
            setTimeVariables();
        }

        DateTime(float timeZone)
        {
            millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
            millisecondsSince_1January1970 += (int)(timeZone * 3600000);
            setTimeVariables();
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute)
        {
            if(parseDate(year,month,day,hour,minute)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000;
                setTimeVariables();
            }
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, float timeZone)
        {
            if(parseDate(year,month,day,hour,minute)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second)
        {
           if(parseDate(year,month,day,hour,minute,second)>0)
           {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000;
                setTimeVariables();
           }
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, float timeZone)
        {
           if(parseDate(year,month,day,hour,minute,second)>0)
           {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
           }
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, unsigned int millisecond)
        {
            if(parseDate(year,month,day,hour,minute,second,millisecond)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000 + millisecond;
                setTimeVariables();
            }
        }

        DateTime(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, unsigned int millisecond, float timeZone)
        {
            if(parseDate(year,month,day,hour,minute,second,millisecond)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000 + millisecond;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        ~DateTime()
        {

        }

        DateTime(const DateTime& dateTimeObject)
        {
            this->millisecondsSince_1January1970 = dateTimeObject.millisecondsSince_1January1970;
            setTimeVariables();
        }

        friend ostream& operator << (ostream& os, const DateTime& dateTimeObject)
        {

            stringstream convertStream;

            if (dateTimeObject.dayOfWeek == 0)
                convertStream << "Thu ";
            else if (dateTimeObject.dayOfWeek == 1)
                convertStream << "Fri ";
            else if (dateTimeObject.dayOfWeek == 2)
                convertStream << "Sat ";
            else if (dateTimeObject.dayOfWeek == 3)
                convertStream << "Sun ";
            else if (dateTimeObject.dayOfWeek == 4)
                convertStream << "Mon ";
            else if (dateTimeObject.dayOfWeek == 5)
                convertStream << "Tue ";
            else
                convertStream << "Wed ";

            if (dateTimeObject.month == 1)
                convertStream << "Jan ";
            else if (dateTimeObject.month == 2)
                convertStream << "Feb ";
            else if (dateTimeObject.month == 3)
                convertStream << "Mar ";
            else if (dateTimeObject.month == 4)
                convertStream << "Apr ";
            else if (dateTimeObject.month == 5)
                convertStream << "May ";
            else if (dateTimeObject.month == 6)
                convertStream << "Jun ";
            else if (dateTimeObject.month == 7)
                convertStream << "Jul ";
            else if (dateTimeObject.month == 8)
                convertStream << "Aug ";
            else if (dateTimeObject.month == 9)
                convertStream << "Sep ";
            else if (dateTimeObject.month == 10)
                convertStream << "Oct ";
            else if (dateTimeObject.month == 11)
                convertStream << "Nov ";
            else
                convertStream << "Dec ";

                convertStream << dateTimeObject.day << " ";

                convertStream << setfill('0') << setw(2) << dateTimeObject.hour << ":" << setfill('0') << setw(2) << dateTimeObject.minute << ":" << setfill('0') << setw(2) << dateTimeObject.second;

                convertStream << ":" << setfill('0') << setw(3) << dateTimeObject.millisecond << " ";

                convertStream << dateTimeObject.year << endl;

                os << convertStream.str();

            return os;
        }

        bool operator == (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 == dateTimeObject.millisecondsSince_1January1970)
                return true;
            else
                return false;
        }

        bool operator != (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 == dateTimeObject.millisecondsSince_1January1970)
                return false;
            else
                return true;
        }

         bool operator > (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 > dateTimeObject.millisecondsSince_1January1970)
                return true;
            else
                return false;
        }

        bool operator < (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 < dateTimeObject.millisecondsSince_1January1970)
                return true;
            else
                return false;
        }

        bool operator <= (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 <= dateTimeObject.millisecondsSince_1January1970)
                return true;
            else
                return false;
        }

        bool operator >= (const DateTime& dateTimeObject)
        {
            if (this->millisecondsSince_1January1970 <= dateTimeObject.millisecondsSince_1January1970)
                return true;
            else
                return false;
        }

        DateTime& operator + (const DateTime& dateTimeObject)
        {
            millisecondsSince_1January1970 = millisecondsSince_1January1970 + dateTimeObject.millisecondsSince_1January1970;
            if(millisecondsSince_1January1970 < 0)
            {
                cout << "Error using operator [+]: Resulting date must be smaller than 1 January 2038" << endl;
                millisecondsSince_1January1970 = 0;
            }
            else
                setTimeVariables();

            return *this;
        }

        DateTime& operator - (const DateTime& dateTimeObject)
        {
            millisecondsSince_1January1970 = millisecondsSince_1January1970 - dateTimeObject.millisecondsSince_1January1970;
            if(millisecondsSince_1January1970 < 0)
            {
                cout << "Error using operator [-]: Resulting date must be greater than 1 January 1970" << endl;
                millisecondsSince_1January1970 = 0;
            }
            else
                setTimeVariables();

            return *this;
        }

        void set_Date()
        {
            millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
            setTimeVariables();
        }

        void set_Date(unsigned int year)
        {
            unsigned int month = 1;
            unsigned int day = 0;

            if(parseSetDate(year)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                setTimeVariables();
            }

        }

        void set_Date(unsigned int year, unsigned int month)
        {
            unsigned int day = 0;

            if(parseSetDate(year,month)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day)
        {
            if(parseSetDate(year,month,day)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour)
        {
            if(parseSetDate(year,month,day,hour)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000;
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute)
        {
            if(parseSetDate(year,month,day,hour,minute)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000;
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second)
        {
            if(parseSetDate(year,month,day,hour,minute,second)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000;
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, unsigned int millisecond)
        {
            if(parseSetDate(year,month,day,hour,minute,second,millisecond)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000 + millisecond;
                setTimeVariables();
            }
        }

        void set_Date(float timeZone)
        {
            millisecondsSince_1January1970 = duration_cast(system_clock::now().time_since_epoch()).count();
            millisecondsSince_1January1970 += (int)(timeZone * 3600000);
            setTimeVariables();
        }

        void set_Date(unsigned int year, float timeZone)
        {
            unsigned int month = 1;
            unsigned int day = 0;

            if(parseSetDate(year)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, float timeZone)
        {
            unsigned int day = 0;

            if(parseSetDate(year,month)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, float timeZone)
        {
            if(parseSetDate(year,month,day)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, float timeZone)
        {
            if(parseSetDate(year,month,day,hour)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, float timeZone)
        {
            if(parseSetDate(year,month,day,hour,minute)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, float timeZone)
        {
            if(parseSetDate(year,month,day,hour,minute,second)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Date(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int second, unsigned int millisecond, float timeZone)
        {
            if(parseSetDate(year,month,day,hour,minute,second,millisecond)>0)
            {
                millisecondsSince_1January1970 = (unsigned long long)calculateDay(year, month, day) * 86400000  + hour * 3600000 + minute * 60000 + second * 1000 + millisecond;
                millisecondsSince_1January1970 += (int)(timeZone * 3600000);
                setTimeVariables();
            }
        }

        void set_Time(unsigned int hour)
        {
            if(parseSetDate(hour)>0)
            {
                millisecondsSince_1January1970 += (hour * 3600000 - this->hour * 3600000);
                setTimeVariables();
            }
        }

        void set_Time(unsigned int hour, unsigned int minute)
        {
            if(parseSetDate(hour,minute)>0)
            {
                millisecondsSince_1January1970 += ((hour * 3600000 + minute * 60000) - (this->hour * 3600000 + this->minute * 60000));
                setTimeVariables();
            }
        }

        void set_Time(unsigned int hour, unsigned int minute, unsigned int second)
        {
            if(parseSetDate(hour,minute,second)>0)
            {
                millisecondsSince_1January1970 += ((hour * 3600000 + minute * 60000 + second * 1000) - (this->hour * 3600000 + this->minute * 60000 + this->second *1000));
                setTimeVariables();
            }
        }

        void set_Time(unsigned int hour, unsigned int minute, unsigned int second, unsigned int millisecond)
        {
            if(parseSetDate(hour,minute,second,millisecond)>0)
            {
                millisecondsSince_1January1970 += ((hour * 3600000 + minute * 60000 + second * 1000 + millisecond) - (this->hour * 3600000 + this->minute * 60000 + this->second *1000 + this->millisecond));
                setTimeVariables();
            }
        }

        string get_date()
        {
            stringstream convertStream;

            if (dayOfWeek == 0)
                convertStream << "Thu ";
            else if (dayOfWeek == 1)
                convertStream << "Fri ";
            else if (dayOfWeek == 2)
                convertStream << "Sat ";
            else if (dayOfWeek == 3)
                convertStream << "Sun ";
            else if (dayOfWeek == 4)
                convertStream << "Mon ";
            else if (dayOfWeek == 5)
                convertStream << "Tue ";
            else
                convertStream << "Wed ";

            if (month == 1)
                convertStream << "Jan ";
            else if (month == 2)
                convertStream << "Feb ";
            else if (month == 3)
                convertStream << "Mar ";
            else if (month == 4)
                convertStream << "Apr ";
            else if (month == 5)
                convertStream << "May ";
            else if (month == 6)
                convertStream << "Jun ";
            else if (month == 7)
                convertStream << "Jul ";
            else if (month == 8)
                convertStream << "Aug ";
            else if (month == 9)
                convertStream << "Sep ";
            else if (month == 10)
                convertStream << "Oct ";
            else if (month == 11)
                convertStream << "Nov ";
            else
                convertStream << "Dec ";

                convertStream << day << " ";

                convertStream << setfill('0') << setw(2) << hour << ":" << setfill('0') << setw(2) << minute << ":" << setfill('0') << setw(2) << second;

                convertStream << ":" << setfill('0') << setw(3) << millisecond << " ";

                convertStream << year << endl;

                return convertStream.str();
        }

        string get_time()
        {
            stringstream convertStream;

            convertStream << setfill('0') << setw(2) << hour << ":" << setfill('0') << setw(2) << minute << ":" << setfill('0') << setw(2) << second;
            convertStream << ":" << setfill('0') << setw(3) << millisecond;

            return convertStream.str();
        }

        string get_dayString()
        {
            if (dayOfWeek == 0)
                return "Thursday";
            else if (dayOfWeek == 1)
                return "Friday";
            else if (dayOfWeek == 2)
                return "Saturday";
            else if (dayOfWeek == 3)
                return "Sunday";
            else if (dayOfWeek == 4)
                return "Monday";
            else if (dayOfWeek == 5)
                return "Tuesday";
            else
                return "Wednesday";
        }

        unsigned int get_millisecond()
        {
            return millisecond;
        }

        unsigned int get_second()
        {
            return second;
        }
        unsigned int get_minute()
        {
            return minute;
        }
        unsigned int get_hour()
        {
            return hour;
        }
        unsigned int get_day()
        {
            return day;
        }
        unsigned int get_year()
        {
            return year;
        }
};

#endif // DATETIME_H_INCLUDED
Node.h
/**************************************************************************************/
/*               File Name: Node.h               Written by: Koral Eren               */
/**************************************************************************************/

// This class follows C++11 Standard. Please include [-std=c+11] for g++

#ifndef NODE_H_INCLUDED
#define NODE_H_INCLUDED

#include "DateTime.h"
#include "Node.h"
#include "Subscription.h"

#include <iostream>
#include <thread>

using namespace std;

class Node: public Notification
{

    //Node has access to GPS Data from its notification. Every time a Node object is created,
    //a notification object is also created. So no variables implemented here.
    //Node can also interact with Subscription class using inheritace.

    public:
        Node()
        {

        }

        ~Node()
        {

        }

        thread createRandomNotification()
        {
            return thread( [&] { protectedCreateRandomNotification(); } );
        }

        const Notification& getNotification()
        {
            return *this;
        }
};






#endif // NODE_H_INCLUDED

Notification.h
/**********************************************************************************************/
/*               File Name: Notification.h               Written by: Koral Eren               */
/**********************************************************************************************/

// This class follows C++11 Standard. Please include [-std=c+11] for g++

#ifndef NOTIFICATION_H_INCLUDED
#define NOTIFICATION_H_INCLUDED

#include <iostream>
#include <string>
#include <ctime>
#include <random>
#include <thread>
#include <chrono>

#include "DateTime.h"
#include "Subscription.h"

#define SAMPLE_RATE 100
#define NUM_OF_NODES 3 // 1 publisher [N1], 1 broker [N2], 1 subscriber [N3]

using namespace std;

class Node;
void notify_specific(const Notification& notificationObject);

class Notification: public Subscription
{
    private:
        double** accelerationData = new double*[SAMPLE_RATE];
        //N by 3 Matrix containing the data of sensor readings
        //Sensor reads 100 times a second, updates once a second
        //for x, y and z for acceleration [m/s^2]

        double** magnetometerData = new double*[SAMPLE_RATE];
        //N by 3 Matrix containing the data of sensor readings
        //Sensor reads 100 times a second, updates once a second
        //for x, y and z for magnetic field intensity [µT]

        double* temperatureData = new double[SAMPLE_RATE];
        //Array containing the data for temperature
        //Sensor reads 100 times a second, updates once a second
        //Temperature unit [C]

        double* pressureData = new double[SAMPLE_RATE];
        //Array containing the data for pressure
        //Sensor reads 100 times a second, updates once a second
        //Pressure unit [Pa]

        double* humidityData = new double[SAMPLE_RATE];
        //Array containing the data for relative humidity
        //Sensor reads 100 times a second, updates once a second
        //Humidity unit [Φ%]

        double** gyroscopeData = new double*[SAMPLE_RATE];
        //Array containing the data for gyroscope
        //Sensor reads 100 times a second, updates once a second
        //angular velocity unit [rad/s]



        string* stringNodeNames = new string[NUM_OF_NODES];
        //Holds the name of the nodes

    protected:

        void protectedCreateRandomNotification()
        {
            const unsigned int seed = time(0);
            mt19937 rng(seed);

            for(unsigned int i = 0; i < SAMPLE_RATE; ++i)
                accelerationData[i] = new double[3];

            for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                magnetometerData[i] = new double[3];

            for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                gyroscopeData[i] = new double[3];

            while(true)
            {
                currentTime = new DateTime(3);

                //Data updates once a second because updating 100 times a second
                //requires a network latency of 1/100 seconds = 10 milliseconds betweeen
                //nodes. Over a wireless network achieveable, but prone to packet loss.

                    uniform_real_distribution  unif(-9.81, 9.81);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        for(unsigned int j = 0; j < 3; j++)
                            accelerationData[i][j] = unif(rng);

                    uniform_real_distribution  unif1(25.0, 65.0);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        for(unsigned int j = 0; j < 3; j++)
                            magnetometerData[i][j] = unif1(rng);

                    uniform_real_distribution  unif2(-89.2, 56.7);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        temperatureData[i] = unif2(rng);

                    uniform_real_distribution  unif3(25000.0, 108480.0);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        pressureData[i] = unif3(rng);

                    uniform_real_distribution  unif4(0.0, 100.0);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        humidityData[i] = unif4(rng);

                   uniform_real_distribution  unif5(-3.14, 3.14);

                    for(unsigned int i = 0; i < SAMPLE_RATE; i++)
                        for(unsigned int j = 0; j < 3; j++)
                            gyroscopeData[i][j] = unif5(rng);

                    uniform_real_distribution  unif6(0.0, 90.0);

                    for(unsigned int i = 0; i < 2; i++)
                        lattitude[i] = unif6(rng);

                    uniform_real_distribution  unif7(0.0, 180.0);

                    for(unsigned int i = 0; i < 2; i++)
                        longitude[i] = unif7(rng);


                    uniform_int_distribution  unif8(0, 1);

                    for(unsigned int i = 0; i < 2; i++)
                        if(unif8(rng) == 0)
                            northSouth[i] = 'N';
                        else
                            northSouth[i] = 'S';

                    uniform_int_distribution  unif9(0, 1);

                    for(unsigned int i = 0; i < 2; i++)
                        if(unif9(rng) == 0)
                            eastWest[i] = 'E';
                        else
                            eastWest[i] = 'W';

                    uniform_int_distribution  unif10(1, 4);

                    for(unsigned int i = 0; i < 2; i++)
                        quality_indicator[i] = unif10(rng);

                    uniform_int_distribution  unif11(0, 20);

                    for(unsigned int i = 0; i < 2; i++)
                        no_of_satellites[i] = unif11(rng);

                    uniform_real_distribution  unif12(0.0, 1.0);

                    for(unsigned int i = 0; i < 2; i++)
                        horizontal_precision[i] = unif12(rng);

                    uniform_real_distribution  unif13(-1419.0, 45000.0);

                    for(unsigned int i = 0; i < 2; i++)
                        altitude[i] = unif13(rng);

                    uniform_int_distribution  unif14(0, 1);

                    for(unsigned int i = 0; i < 2; i++)
                        if(unif14(rng) == 0)
                            altitudeUnit[i] = 'M';
                        else
                            altitudeUnit[i] = 'F';

                    uniform_real_distribution  unif15(0.0, 1000.0);

                    for(unsigned int i = 0; i < 2; i++)
                        geoidal_seperation[i] = unif15(rng);

                    uniform_int_distribution  unif16(0, 1);

                    for(unsigned int i = 0; i < 2; i++)
                        if(unif16(rng) == 0)
                            geoidal_seperation_units[i] = 'M';
                        else
                            geoidal_seperation_units[i] = 'F';

                    uniform_real_distribution  unif17(0, 5);

                    for(unsigned int i = 0; i < 2; i++)
                        correctionAge[i] = unif17(rng);

                    uniform_int_distribution  unif18(0, 5);

                    for(unsigned int i = 0; i < 2; i++)
                        correctionStation[i] = unif18(rng);

                    uniform_int_distribution  unif19(0, 100);

                    for(unsigned int i = 0; i < 2; i++)
                        checksum[i] = unif19(rng);

                    stringstream ss;

                    for(unsigned int i = 0; i < NUM_OF_NODES; i++)
                    {
                        ss << (i+1);
                        stringNodeNames[i] = "N" + ss.str();
                        ss.str(string());
                    }

            this_thread::sleep_for(seconds(1));

            delete currentTime;

        }
    }
        string GPS_position_indicator = "GP";
        DateTime* currentTime;
        double* lattitude = new double[2];
        double* longitude = new double[2];
        char* northSouth = new char[2];
        char* eastWest  = new char[2];
        unsigned int* quality_indicator = new unsigned int[2];
        unsigned int* no_of_satellites = new unsigned int[2];
        double* horizontal_precision = new double[2];
        double* altitude = new double[2];
        char* altitudeUnit  = new char[2];
        double* geoidal_seperation = new double[2];
        char* geoidal_seperation_units = new char[2];
        double* correctionAge = new double[2];
        unsigned int* correctionStation = new unsigned int[2];
        unsigned int* checksum = new unsigned int[2];
        //Data for GPS sensor. GPS sensor updates only twice a second due to distance to satellite.

    public:

    Notification()
    {

    }

    ~Notification()
    {

    }

    void publish(const Notification& notificationObject)
    {
             cout << "\n\n";
             for(unsigned int i = 0; i<80; i++)
                putchar('*');
                cout << "\n";
             cout << "Notification coming from: " << *notificationObject.stringNodeNames << " at: " << *notificationObject.currentTime;
             for(unsigned int i = 0; i<80; i++)
                putchar('*');
                cout << endl;


             for(unsigned int i = 0; i < SAMPLE_RATE; i++)
             {
                 for(unsigned int j = 0; j < 3; j++)
                 {
                     if(j == 0)
                        cout << "Acceleration x        Acceleration y        Acceleration z" << endl;

                     cout << notificationObject.accelerationData[i][j] << "                ";
                 }

                cout << "\n";
             }

             cout << "\n\n\n";
             cout.flush();

             for(unsigned int i = 0; i < SAMPLE_RATE; i++)
             {
                 for(unsigned int j = 0; j < 3; j++)
                 {
                     if(j == 0)
                        cout << "Mag.Field x        Mag.Field y        Mag.Field z" << endl;

                     cout << notificationObject.magnetometerData[i][j] << "             ";
                 }

                cout << "\n";
             }

             cout << "\n\n\n";
             cout.flush();

            for(unsigned int i = 0; i < SAMPLE_RATE; i++)
            {
                cout << "Temperature:" << endl;
                cout <get_time() << " ";
             cout << notificationObject.lattitude[0] << " ";
             cout << notificationObject.northSouth[0] << " ";
             cout << notificationObject.longitude[0] << " ";
             cout << notificationObject.eastWest[0] << " ";
             cout << notificationObject.quality_indicator[0] << " ";
             cout << notificationObject.no_of_satellites[0] << " ";
             cout << notificationObject.horizontal_precision[0] << " ";
             cout << notificationObject.altitude[0] << " ";
             cout << notificationObject.altitudeUnit[0] << " ";
             cout << notificationObject.geoidal_seperation[0] << " ";
             cout << notificationObject.geoidal_seperation_units[0] << " ";
             cout << notificationObject.correctionAge[0] << " ";
             cout << notificationObject.correctionStation[0] << " ";
             cout << "*" << notificationObject.checksum[0] << " " << endl;

             cout << notificationObject.currentTime->get_time() << " ";
             cout << notificationObject.lattitude[1] << " ";
             cout << notificationObject.northSouth[1] << " ";
             cout << notificationObject.longitude[1] << " ";
             cout << notificationObject.eastWest[1] << " ";
             cout << notificationObject.quality_indicator[1] << " ";
             cout << notificationObject.no_of_satellites[1] << " ";
             cout << notificationObject.horizontal_precision[1] << " ";
             cout << notificationObject.altitude[1] << " ";
             cout << notificationObject.altitudeUnit[1] << " ";
             cout << notificationObject.geoidal_seperation[1] << " ";
             cout << notificationObject.geoidal_seperation_units[1] << " ";
             cout << notificationObject.correctionAge[1] << " ";
             cout << notificationObject.correctionStation[1] << " ";
             cout << "*" << notificationObject.checksum[1] << "\n" << endl;

            bool flag = true;
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find('>') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('>')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] > temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }




             if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find('<') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('<')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] < temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }



            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find(">=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find(">=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] >= temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }



            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find("<=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("<=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] <= temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }



            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find("!=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("!=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] != temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }



            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("cceleration") != string::npos &&
                    subsciption_message[i].find('=') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('=')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                        {
                            for(unsigned int j = 0; j < 3; j++)
                                if (notificationObject.accelerationData[k][j] == temp)
                                {
                                    ndID = (Node*)¬ificationObject;
                                    cout << "Notification published to " << subsciberID << " with criteria ";
                                    cout << subsciption_message[i] << "\nAcceleration in sample " << k+1 << " :"
                                    << notificationObject.accelerationData[k][j] << endl;
                                    flag = false;
                                    break;
                                }

                            if(flag == false)
                                break;
                        }
                    }

                if(flag == false)
                    break;
            }


            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find('<') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('<')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] < temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find('>') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('>')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] > temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find(">=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find(">=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] >= temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find("<=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("<=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] <= temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find("!=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("!=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] != temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("emperature") != string::npos &&
                    subsciption_message[i].find('=') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('=')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] == temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nTemperature in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find('>') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('>')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.pressureData[k] > temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.pressureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find('<') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('<')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.pressureData[k] < temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.pressureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find(">=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find(">=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.pressureData[k] >= temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.pressureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find("<=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("<=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.pressureData[k] <= temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.pressureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find("!=") != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find("!=")+3));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.pressureData[k] != temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.pressureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            if (flag == true)
            for(unsigned int i = 0; i < 3; i++)
            {
                if (subsciption_message[i].find("ressure") != string::npos &&
                    subsciption_message[i].find('=') != string::npos)
                    {
                        double temp;
                        temp = stod(subsciption_message[i].substr(subsciption_message[i].find('=')+2));

                        for(unsigned int k = 0; k < SAMPLE_RATE; k++)
                            if (notificationObject.temperatureData[k] == temp)
                            {
                                ndID = (Node*)¬ificationObject;
                                cout << "Notification published to " << subsciberID << " with criteria ";
                                cout << subsciption_message[i] << "\nPressure in sample " << k+1 << " :"
                                << notificationObject.temperatureData[k] << endl;
                                flag = false;
                                break;
                            }
                    }

                if(flag == false)
                    break;
            }

            //More creteria can be coded here if required.

    }

};

#endif // NOTIFICATION_H_INCLUDED
publish_subscribe.cpp
/***************************************************************************************************/
/*               File Name: publish_subscribe.cpp              Written by: Koral Eren              */
/***************************************************************************************************/

// This project follows C++11 Standard. Please include [-std=c+11] for g++

#include <iostream>
#include <string>
#include <thread>
#include <chrono>

#include "DateTime.h"
#include "Notification.h"
#include "Subscription.h"
#include "Node.h"

#define SAMPLE_RATE 100
#define NUM_OF_NODES 3 // 1 publisher [N1], 1 broker [N2], 1 subscriber [N3]

using namespace std;

class Node;
class Notification;
void notify_specific(const Notification& notificationObject);

int main()
{
    Node n1;
    Node n2;
    Node n3;
    thread t1 = n1.createRandomNotification();
    Subscription s("N3", n3, "Acceleration > 3", "temperature > 24", "Pressure > 33");
    n2.subscribe(s);


    while(1)
    {
            n2.publish(n1.getNotification());
            this_thread::sleep_for(seconds(1));
    }

t1.detach();

    return 0;
}
Subscription.h
/**********************************************************************************************/
/*               File Name: Subscription.h               Written by: Koral Eren               */
/**********************************************************************************************/

// This class follows C++11 Standard. Please include [-std=c+11] for g++

#ifndef SUBSCRIPTION_H_INCLUDED
#define SUBSCRIPTION_H_INCLUDED

#include <iostream>
#include <string>

using namespace std;

class Node;
class Notification;
void notify_specific(const Notification& notificationObject);

class Subscription
{
    protected:
    string subsciption_message[3];
    string subsciberID;
    Node *ndID;

    public:
    Subscription()
    {
        for(unsigned int i=0;i<3;i++)
            subsciption_message[i]= "xxxx";
    }

    Subscription(string subsciberID, Node& nodeID, string message1, string message2, string message3)
    {
        subsciption_message[0] = message1;
        subsciption_message[1] = message2;
        subsciption_message[2] = message3;
        this->subsciberID = subsciberID;
        ndID = &nodeID;
    }

    ~Subscription()
    {

    }

    bool operator == (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] == subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] == subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] == subscriptionObject.subsciption_message[2] &&
            this->subsciberID == subscriptionObject.subsciberID &&
            this->ndID == subscriptionObject.ndID)
            return true;
        else
            return false;
    }

    bool operator != (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] == subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] == subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] == subscriptionObject.subsciption_message[2] &&
            this->subsciberID == subscriptionObject.subsciberID &&
            this->ndID == subscriptionObject.ndID)
            return false;
        else
            return true;
    }

    bool operator > (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] > subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] > subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] > subscriptionObject.subsciption_message[2] &&
            this->subsciberID > subscriptionObject.subsciberID &&
            this->ndID > subscriptionObject.ndID)
            return true;
        else
            return false;
    }

    bool operator < (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] < subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] < subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] < subscriptionObject.subsciption_message[2] &&
            this->subsciberID < subscriptionObject.subsciberID &&
            this->ndID < subscriptionObject.ndID)
            return true;
        else
            return false;
    }

    bool operator <= (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] <= subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] <= subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] <= subscriptionObject.subsciption_message[2] &&
            this->subsciberID <= subscriptionObject.subsciberID &&
            this->ndID <= subscriptionObject.ndID)
            return true;
        else
            return false;
    }

    bool operator >= (const Subscription& subscriptionObject)
    {
        if (this->subsciption_message[0] >= subscriptionObject.subsciption_message[0] &&
            this->subsciption_message[1] >= subscriptionObject.subsciption_message[1] &&
            this->subsciption_message[2] >= subscriptionObject.subsciption_message[2] &&
            this->subsciberID >= subscriptionObject.subsciberID &&
            this->ndID >= subscriptionObject.ndID)
            return true;
        else
            return false;
    }

    void subscribe(const Subscription& subscriptionObject)
    {
        for(unsigned int i=0;i<3;i++)
        {
            this->subsciption_message[0] = subscriptionObject.subsciption_message[0];
            this->subsciption_message[1] = subscriptionObject.subsciption_message[1];
            this->subsciption_message[2] = subscriptionObject.subsciption_message[2];
            this->subsciberID = subscriptionObject.subsciberID;
        }
    }
};

#endif // SUBSCRIPTION_H_INCLUDED