pelib  2.0.0
src/Link.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Pelib.
00005 
00006  Pelib is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  Pelib is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with Pelib. If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #include <string>
00021 #include <iostream>
00022 
00023 #include <pelib/Link.hpp>
00024 
00025 #ifdef debug
00026 #undef debug
00027 #endif
00028 
00029 #define debug(expr) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #expr << " = \"" << (expr) << "\"." << endl;
00030 
00031 using namespace std;
00032 
00033 namespace pelib
00034 {
00035         Link::Link(const Task &producer, const Task &consumer, const string &producerName, const string &consumerName, const std::string &type, size_t producer_rate, size_t consumer_rate)
00036         {
00037                 this->producerName = producerName;
00038                 this->consumerName = consumerName;
00039                 this->producer = (Task*)&producer;
00040                 this->consumer = (Task*)&consumer;
00041                 this->type = string(type);
00042                 this->producer_rate = producer_rate;
00043                 this->consumer_rate = consumer_rate;
00044         }
00045 
00046         Task*
00047         Link::getProducer() const
00048         {
00049                 return this->producer;
00050         }
00051 
00052         Task*
00053         Link::getConsumer() const
00054         {
00055                 return this->consumer;
00056         }
00057 
00058         size_t
00059         Link::getProducerRate() const
00060         {
00061                 return this->producer_rate;
00062         }
00063 
00064         size_t
00065         Link::getConsumerRate() const
00066         {
00067                 return this->consumer_rate;
00068         }
00069 
00070         std::string
00071         Link::getDataType() const
00072         {
00073                 return this->type;
00074         }
00075 
00076         std::string
00077         Link::getProducerName() const
00078         {
00079                 return this->producerName;
00080         }
00081 
00082         std::string
00083         Link::getConsumerName() const
00084         {
00085                 return this->consumerName;
00086         }
00087 
00088         bool
00089         Link::operator<(const Link &other) const
00090         {
00091                 Task thisProducer = *this->getProducer();
00092                 Task otherProducer = *other.getProducer();
00093                 Task thisConsumer = *this->getConsumer();
00094                 Task otherConsumer = *other.getConsumer();
00095 
00096                 if(thisProducer == otherProducer && thisConsumer == otherConsumer)
00097                 {
00098                         if(this->getProducerName().compare(other.getProducerName()) == 0)
00099                         {
00100                                 return this->getConsumerName() < other.getConsumerName();
00101                         }
00102                         else
00103                         {
00104                                 return this->getProducerName() < other.getProducerName();
00105                         }
00106                 }
00107 
00108                 if(thisProducer == otherProducer)
00109                 {
00110                         return thisConsumer < otherConsumer;
00111                 }
00112                 else
00113                 {
00114                         return thisProducer < otherProducer;
00115                 }       
00116         }
00117 
00118         bool
00119         Link::operator==(const Link &other) const
00120         {       
00121                 return (*this->getProducer() == *other.getProducer()) && (*this->getConsumer() == *other.getConsumer()) && (this->getProducerName().compare(other.getProducerName()) == 0) && (this->getConsumerName().compare(other.getConsumerName()) == 0);
00122         }
00123 }