00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef WSCOUT_GUI_FIND_DIALOG_HXX_
00024 # define WSCOUT_GUI_FIND_DIALOG_HXX_
00025
00026 # include <QtGui/QApplication>
00027
00028 # include "wscout_gui_find_dialog.hh"
00029 # include "wscout_hexdump.hh"
00030
00031 namespace wscout
00032 {
00033
00034 namespace gui
00035 {
00036
00037
00038
00039
00040
00041 inline
00042 FindThread::FindThread(QObject* parent,
00043 const_iterator& current_it,
00044 const const_iterator& last_it,
00045 const std::string& bytes,
00046 size_t first,
00047 size_t last):
00048 QThread (parent),
00049 current_it_ (current_it),
00050 last_it_ (last_it),
00051 first_ (first),
00052 last_ (last),
00053 canceled_ (false)
00054 {
00055 const std::string prefix = bytes.substr(0, 2);
00056 const bool has_prefix = prefix == "0x" or prefix == "0X";
00057
00058 bytes_ = has_prefix?
00059 unhexdump(bytes.substr(2)):
00060 bytes_type (bytes.begin(), bytes.end());
00061 if (bytes_.size() > last - first)
00062 throw std::invalid_argument ("Too many bytes w.r.t. "
00063 "the given search offsets");
00064 }
00065
00066 inline
00067 FindThread::~FindThread()
00068 {
00069 cancel();
00070 }
00071
00072 inline
00073 bool
00074 FindThread::canceled() const
00075 {
00076 return canceled_;
00077 }
00078
00079 inline
00080 void
00081 FindThread::cancel()
00082 {
00083 canceled_ = true;
00084 wait();
00085 }
00086
00087
00088
00089
00090
00091 inline
00092 void
00093 FindDialog::voidIterators()
00094 {
00095 cancelThread();
00096 first_it_ = current_it_ = last_it_ = boost::none_t ();
00097 }
00098
00099 inline
00100 void
00101 FindDialog::setIterators(const const_iterator& first,
00102 const const_iterator& last,
00103 size_t last_index)
00104 {
00105 cancelThread();
00106 first_it_ = first;
00107 current_it_ = first;
00108 last_it_ = last;
00109 pbar_.setMaximum(last_index);
00110 pbar_.setValue(1);
00111 }
00112
00113 inline
00114 void
00115 FindDialog::cancelThread()
00116 {
00117 if (threadRunning())
00118 thread_->cancel();
00119 qApp->processEvents();
00120 }
00121
00122 inline
00123 bool
00124 FindDialog::threadRunning() const
00125 {
00126 return thread_.get() and not thread_->isFinished();
00127 }
00128
00129 inline
00130 bool
00131 FindDialog::validIterators() const
00132 {
00133 return first_it_ and current_it_ and last_it_;
00134 }
00135
00136 }
00137
00138 }
00139
00140 #endif // ! WSCOUT_GUI_FIND_DIALOG_HXX_