Horizon
searcher.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid_path.hpp"
4 #include <set>
5 #include <list>
6 
7 namespace horizon {
8 class Searcher {
9 public:
10  enum class Type {
11  SYMBOL_PIN,
12  TEXT,
13  SYMBOL_REFDES,
14  SYMBOL_MPN,
15  NET_LABEL,
16  POWER_SYMBOL,
17  BUS_RIPPER,
18  PAD,
19  PACKAGE_REFDES,
20  PACKAGE_MPN
21  };
22 
23  class TypeInfo {
24  public:
25  TypeInfo(ObjectType ot);
26 
27  TypeInfo(const std::string &n, ObjectType ot = ObjectType::INVALID)
28  : name(n), name_pl(name + "s"), object_type(ot)
29  {
30  }
31  TypeInfo(const std::string &n, const std::string &n_pl, ObjectType ot = ObjectType::INVALID)
32  : name(n), name_pl(n_pl), object_type(ot)
33  {
34  }
35  const std::string name;
36  const std::string name_pl;
37  const ObjectType object_type;
38  };
39 
40  static const std::map<Type, TypeInfo> &get_type_info();
41  static const TypeInfo &get_type_info(Type type);
42 
43  class SearchQuery {
44  public:
45  void set_query(const std::string &q);
46  const std::string &get_query() const;
47  bool contains(const std::string &haystack) const;
48  std::set<Type> types;
49  std::pair<Coordf, Coordf> area_visible;
50 
51  private:
52  std::string query;
53  };
54 
55  class SearchResult {
56  public:
57  SearchResult(Type ty, const UUID &uu) : type(ty), path(uu)
58  {
59  }
60  SearchResult(Type ty, const UUID &uu, const UUID &uu2) : type(ty), path(uu, uu2)
61  {
62  }
63  Type type;
64  UUIDPath<2> path;
65  Coordi location;
66  UUID sheet;
67  bool selectable = false;
68  };
69 
70  virtual std::list<SearchResult> search(const SearchQuery &q) = 0;
71  virtual std::set<Type> get_types() const = 0;
72  virtual std::string get_display_name(const SearchResult &r) = 0;
73 
74  virtual ~Searcher()
75  {
76  }
77 
78 protected:
79  void sort_search_results(std::list<SearchResult> &results, const SearchQuery &q);
80 };
81 } // namespace horizon
horizon::Searcher::SearchResult
Definition: searcher.hpp:55
horizon::Coord< int64_t >
horizon::UUIDPath< 2 >
horizon::Searcher
Definition: searcher.hpp:8
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::Searcher::TypeInfo
Definition: searcher.hpp:23
horizon::Searcher::SearchQuery
Definition: searcher.hpp:43