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