PageRenderTime 33ms CodeModel.GetById 16ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/narrowingvectorsearchjob.h

https://code.google.com/p/dwarftherapist/
C++ Header | 81 lines | 46 code | 11 blank | 24 comment | 4 complexity | 567911a662c26f9be7e407894972ed06 MD5 | raw file
 1/*
 2Dwarf Therapist
 3Copyright (c) 2010 Justin Ehlert
 4
 5Permission is hereby granted, free of charge, to any person obtaining a copy
 6of this software and associated documentation files (the "Software"), to deal
 7in the Software without restriction, including without limitation the rights
 8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE SOFTWARE.
22
23http://www.opensource.org/licenses/mit-license.php
24*/
25
26#ifndef NARROWINGVECTORSEARCHJOB_H
27#define NARROWINGVECTORSEARCHJOB_H
28
29#include "scannerjob.h"
30#include "defines.h"
31#include "truncatingfilelogger.h"
32#include "utils.h"
33
34class NarrowingVectorSearchJob : public ScannerJob {
35    Q_OBJECT
36public:
37    NarrowingVectorSearchJob()
38        : ScannerJob(FIND_NARROWING_VECTORS_OF_SIZE)
39    {}
40
41    void set_needle(const QByteArray &needle) {
42        m_needle = needle;
43    }
44
45    void set_search_vector(const QVector<VIRTADDR> & searchvector) {
46        m_searchvector = searchvector;
47    }
48
49    public slots:
50        void go() {
51            if (!m_ok) {
52                LOGE << "Scanner Thread couldn't connect to DF!";
53                emit quit();
54                return;
55            }
56            LOGD << "Starting Search in Thread" << QThread::currentThreadId();
57
58            emit main_scan_total_steps(0);
59            emit main_scan_progress(-1);
60            uint target_count = m_needle.toInt();
61            emit scan_message(tr("Looking for Vectors with %1 entries")
62                              .arg(target_count));
63            QVector<VIRTADDR> vectors;
64            if(m_searchvector.size() == 0) {
65                vectors = m_df->find_vectors(target_count);
66            } else {
67                vectors = m_df->find_vectors(target_count, m_searchvector);
68            }
69            LOGD << "Search complete, found " << vectors.size() << " vectors.";
70
71            emit got_result(new QVector<VIRTADDR>(vectors));
72            emit quit();
73        }
74
75private:
76    QByteArray m_needle;
77    QVector<VIRTADDR> m_searchvector;
78
79};
80
81#endif // NARROWINGVECTORSEARCHJOB_H