SQLiteIndexSourceV1.h (2181B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "Microsoft/SQLiteIndexSource.h" 5 6 7 namespace AppInstaller::Repository::Microsoft::details::V1 8 { 9 // The IPackage implementation for V1 index. 10 struct SQLitePackage : public std::enable_shared_from_this<SQLitePackage>, public SourceReference, public IPackage, public ICompositePackage 11 { 12 static constexpr IPackageType PackageType = IPackageType::SQLitePackage1; 13 14 SQLitePackage(const std::shared_ptr<SQLiteIndexSource>& source, SQLiteIndex::IdType idId, const std::shared_ptr<Caching::FileCache>& manifestCache, bool isInstalled); 15 16 // Inherited via IPackage 17 Utility::LocIndString GetProperty(PackageProperty property) const; 18 19 std::vector<Utility::LocIndString> GetMultiProperty(PackageMultiProperty property) const override; 20 21 std::vector<PackageVersionKey> GetVersionKeys() const override; 22 23 std::shared_ptr<IPackageVersion> GetLatestVersion() const override; 24 25 std::shared_ptr<IPackageVersion> GetVersion(const PackageVersionKey& versionKey) const override; 26 27 Source GetSource() const override; 28 29 bool IsSame(const IPackage* other) const override; 30 31 const void* CastTo(IPackageType type) const override; 32 33 // Inherited via ICompositePackage 34 std::shared_ptr<IPackage> GetInstalled() override; 35 36 std::vector<std::shared_ptr<IPackage>> GetAvailable() override; 37 38 private: 39 // Contains the information needed to map a version key to it's rows. 40 struct MapKey 41 { 42 Utility::NormalizedString Version; 43 Utility::NormalizedString Channel; 44 45 bool operator<(const MapKey& other) const; 46 }; 47 48 SQLiteIndex::IdType m_idId; 49 std::shared_ptr<Caching::FileCache> m_manifestCache; 50 bool m_isInstalled; 51 52 // To avoid removing const from the interface 53 mutable wil::srwlock m_versionKeysLock; 54 mutable std::vector<PackageVersionKey> m_versionKeys; 55 mutable std::map<MapKey, SQLiteIndex::IdType> m_versionKeysMap; 56 }; 57 }