QSapecNG
 All Classes Functions Enumerations Properties
metacircuit_thread.hpp
00001 /*
00002     QSapecNG - Qt based SapecNG GUI front-end
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef METACIRCUIT_THREAD_H
00021 #define METACIRCUIT_THREAD_H
00022 
00023 
00024 #include "model/metacircuit.h"
00025 #include "parser/parser.h"
00026 
00027 #include <QtCore/QMutexLocker>
00028 #include <QtCore/QThread>
00029 #include <QtCore/QMutex>
00030 
00031 
00032 namespace qsapecng
00033 {
00034 
00035 
00036 class MetaCircuit_Thread: public QThread
00037 {
00038 
00039   Q_OBJECT
00040 
00041 public:
00042   MetaCircuit_Thread(QObject* parent = 0): QThread(parent)
00043     { circuit_ = new sapecng::circuit; }
00044   ~MetaCircuit_Thread() { delete circuit_; }
00045 
00046   inline void apply(sapecng::abstract_parser& parser)
00047     {
00048       QMutexLocker locker(&mutex_);
00049       sapecng::abstract_builder* builder =
00050         new sapecng::circuit_builder(*circuit_);
00051       parser.parse(*builder);
00052       delete builder;
00053     }
00054 
00055   inline sapecng::metacircuit::expression raw_numerator()
00056     { QMutexLocker locker(&mutex_); return meta_.raw().first; }
00057   inline sapecng::metacircuit::expression raw_denominator()
00058     { QMutexLocker locker(&mutex_); return meta_.raw().second; }
00059   inline sapecng::metacircuit::expression digit_numerator()
00060     { QMutexLocker locker(&mutex_); return meta_.digit().first; }
00061   inline sapecng::metacircuit::expression digit_denominator()
00062     { QMutexLocker locker(&mutex_); return meta_.digit().second; }
00063   inline sapecng::metacircuit::expression mixed_numerator()
00064     { QMutexLocker locker(&mutex_); return meta_.mixed().first; }
00065   inline sapecng::metacircuit::expression mixed_denominator()
00066     { QMutexLocker locker(&mutex_); return meta_.mixed().second; }
00067 
00068 protected:
00069   void run()
00070   {
00071     QMutexLocker locker(&mutex_);
00072     meta_(*circuit_);
00073   }
00074 
00075 private:
00076   sapecng::metacircuit meta_;
00077   sapecng::circuit* circuit_;
00078   QMutex mutex_;
00079 
00080 };
00081 
00082 
00083 }
00084 
00085 
00086 #endif // METACIRCUIT_THREAD_H
 All Classes Functions Enumerations Properties