| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef SEGMENTED_SEQUENCES_H
- #define SEGMENTED_SEQUENCES_H
- #include <string>
- #include <memory>
- #include <vector>
- #include <variant>
- #include <optional>
- #include <functional>
- using SegmentedString = std::vector<std::shared_ptr<std::string>>;
- class SegmentedSequences {
- public:
- SegmentedSequences() = default;
- virtual ~SegmentedSequences() = default;
- virtual void Visit(std::function<void(SegmentedString sequence)> visitor) const = 0;
- virtual size_t MinSize() const = 0;
- };
- class SegmentedSequencesLeaf : public SegmentedSequences {
- private:
- std::shared_ptr<std::string> sequence_;
- public:
- SegmentedSequencesLeaf() = default;
- ~SegmentedSequencesLeaf() override = default;
- explicit SegmentedSequencesLeaf(std::shared_ptr<std::string> sequence);
- void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
- size_t MinSize() const override;
- const std::string& sequence() const { return *sequence_; }
- };
- class SegmentedSequencesAlternatives : public SegmentedSequences {
- private:
- std::vector<std::shared_ptr<SegmentedSequences>> alternatives_;
- size_t min_size_ = 0;
- public:
- SegmentedSequencesAlternatives() = default;
- ~SegmentedSequencesAlternatives() override = default;
- explicit SegmentedSequencesAlternatives(
- std::vector<std::shared_ptr<SegmentedSequences>> alternatives);
- void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
- size_t MinSize() const override;
- const std::vector<std::shared_ptr<SegmentedSequences>>& alternatives() const {
- return alternatives_;
- }
- };
- class SegmentedSequencesProduct : public SegmentedSequences {
- private:
- std::shared_ptr<SegmentedSequences> a_;
- std::shared_ptr<SegmentedSequences> b_;
- size_t min_size_ = 0;
- public:
- SegmentedSequencesProduct() = default;
- ~SegmentedSequencesProduct() override = default;
- SegmentedSequencesProduct(std::shared_ptr<SegmentedSequences> a,
- std::shared_ptr<SegmentedSequences> b);
- void Visit(std::function<void(SegmentedString sequence)> visitor) const override;
- size_t MinSize() const override;
- std::shared_ptr<SegmentedSequences> a() const { return a_; }
- std::shared_ptr<SegmentedSequences> b() const { return b_; }
- };
- #endif
|