CompositeSource.h (2396B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "ISource.h" 5 6 namespace AppInstaller::Repository 7 { 8 struct CompositeSource : public ISource 9 { 10 static constexpr ISourceType SourceType = ISourceType::CompositeSource; 11 12 explicit CompositeSource(std::string identifier); 13 14 CompositeSource(const CompositeSource&) = delete; 15 CompositeSource& operator=(const CompositeSource&) = delete; 16 17 CompositeSource(CompositeSource&&) = default; 18 CompositeSource& operator=(CompositeSource&&) = default; 19 20 ~CompositeSource() = default; 21 22 // ISource 23 24 // Get the source's details. 25 const SourceDetails& GetDetails() const override; 26 27 // Gets the source's identifier; a unique identifier independent of the name 28 // that will not change between a remove/add or between additional adds. 29 // Must be suitable for filesystem names. 30 const std::string& GetIdentifier() const override; 31 32 // Execute a search on the source. 33 SearchResult Search(const SearchRequest& request) const override; 34 35 // Casts to the requested type. 36 void* CastTo(ISourceType type) override; 37 38 // ~ISource 39 40 // Adds an available source to be aggregated. 41 void AddAvailableSource(const Source& source); 42 43 // Gets the available sources if the source is composite. 44 std::vector<Source> GetAvailableSources() const { return m_availableSources; } 45 46 // Checks if any available sources are present 47 bool HasAvailableSource() const { return !m_availableSources.empty(); } 48 49 // Sets the installed source to be composited. 50 void SetInstalledSource(Source source, CompositeSearchBehavior searchBehavior = CompositeSearchBehavior::Installed); 51 52 private: 53 // Performs a search when an installed source is present. 54 SearchResult SearchInstalled(const SearchRequest& request) const; 55 56 // Performs a search when no installed source is present. 57 SearchResult SearchAvailable(const SearchRequest& request) const; 58 59 Source m_installedSource; 60 std::vector<Source> m_availableSources; 61 SourceDetails m_details; 62 CompositeSearchBehavior m_searchBehavior = CompositeSearchBehavior::Installed; 63 }; 64 }