segmented_sequences.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef SEGMENTED_SEQUENCES_H
  2. #define SEGMENTED_SEQUENCES_H
  3. #include <string>
  4. #include <memory>
  5. #include <vector>
  6. #include <variant>
  7. #include <optional>
  8. #include <functional>
  9. using SegmentedString = std::vector<std::shared_ptr<std::string>>;
  10. class SegmentedSequences {
  11. public:
  12. SegmentedSequences() = default;
  13. virtual ~SegmentedSequences() = default;
  14. virtual void Visit(std::function<void(SegmentedString sequence)> visitor) const = 0;
  15. virtual size_t MinSize() const = 0;
  16. };
  17. class SegmentedSequencesLeaf : public SegmentedSequences {
  18. private:
  19. std::shared_ptr<std::string> sequence_;
  20. public:
  21. SegmentedSequencesLeaf() = default;
  22. ~SegmentedSequencesLeaf() override = default;
  23. explicit SegmentedSequencesLeaf(std::shared_ptr<std::string> sequence);
  24. void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
  25. size_t MinSize() const override;
  26. const std::string& sequence() const { return *sequence_; }
  27. };
  28. class SegmentedSequencesAlternatives : public SegmentedSequences {
  29. private:
  30. std::vector<std::shared_ptr<SegmentedSequences>> alternatives_;
  31. size_t min_size_ = 0;
  32. public:
  33. SegmentedSequencesAlternatives() = default;
  34. ~SegmentedSequencesAlternatives() override = default;
  35. explicit SegmentedSequencesAlternatives(
  36. std::vector<std::shared_ptr<SegmentedSequences>> alternatives);
  37. void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
  38. size_t MinSize() const override;
  39. const std::vector<std::shared_ptr<SegmentedSequences>>& alternatives() const {
  40. return alternatives_;
  41. }
  42. };
  43. class SegmentedSequencesProduct : public SegmentedSequences {
  44. private:
  45. std::shared_ptr<SegmentedSequences> a_;
  46. std::shared_ptr<SegmentedSequences> b_;
  47. size_t min_size_ = 0;
  48. public:
  49. SegmentedSequencesProduct() = default;
  50. ~SegmentedSequencesProduct() override = default;
  51. SegmentedSequencesProduct(std::shared_ptr<SegmentedSequences> a,
  52. std::shared_ptr<SegmentedSequences> b);
  53. void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
  54. size_t MinSize() const override;
  55. std::shared_ptr<SegmentedSequences> a() const { return a_; }
  56. std::shared_ptr<SegmentedSequences> b() const { return b_; }
  57. };
  58. #endif