annotate base/StorageAdviser.h @ 1361:49b43306778b 3.0-integration

Win32 fixes
author Chris Cannam
date Tue, 10 Jan 2017 11:08:14 +0000
parents adbd16d2c1e8
children
rev   line source
Chris@334 1
Chris@168 2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@168 3
Chris@168 4 /*
Chris@168 5 Sonic Visualiser
Chris@168 6 An audio file viewer and annotation editor.
Chris@168 7 Centre for Digital Music, Queen Mary, University of London.
Chris@202 8 This file copyright 2006 QMUL.
Chris@168 9
Chris@168 10 This program is free software; you can redistribute it and/or
Chris@168 11 modify it under the terms of the GNU General Public License as
Chris@168 12 published by the Free Software Foundation; either version 2 of the
Chris@168 13 License, or (at your option) any later version. See the file
Chris@168 14 COPYING included with this distribution for more information.
Chris@168 15 */
Chris@168 16
Chris@1276 17 #ifndef SV_STORAGE_ADVISER_H
Chris@1276 18 #define SV_STORAGE_ADVISER_H
Chris@168 19
Chris@1038 20 #include <cstdlib>
Chris@1038 21
Chris@1276 22 #include <QString>
Chris@1276 23
Chris@168 24 /**
Chris@168 25 * A utility class designed to help decide whether to store cache data
Chris@168 26 * (for example FFT outputs) in memory or on disk in the TempDirectory.
Chris@170 27 * This is basically a compendium of simple rules of thumb.
Chris@168 28 */
Chris@168 29
Chris@168 30 class StorageAdviser
Chris@168 31 {
Chris@168 32 public:
Chris@168 33 // pass to recommend() zero or more of these OR'd together
Chris@168 34 enum Criteria {
Chris@170 35 NoCriteria = 0,
Chris@170 36 SpeedCritical = 1,
Chris@170 37 PrecisionCritical = 2,
Chris@170 38 LongRetentionLikely = 4,
Chris@170 39 FrequentLookupLikely = 8
Chris@168 40 };
Chris@168 41
Chris@168 42 // recommend() returns one or two of these OR'd together
Chris@168 43 enum Recommendation {
Chris@170 44 NoRecommendation = 0,
Chris@170 45 UseMemory = 1, // Disc is strongly contraindicated
Chris@170 46 PreferMemory = 2, // Either would do; memory probably better
Chris@170 47 PreferDisc = 4, // Either would do; disc probably better
Chris@170 48 UseDisc = 8, // Probably won't fit in memory
Chris@170 49 ConserveSpace = 16,// Whatever you choose, keep it compact
Chris@170 50 UseAsMuchAsYouLike = 32 // Take my advice and there'll be space for all
Chris@168 51 };
Chris@168 52
Chris@169 53 /**
Chris@169 54 * Recommend where to store some data, given certain storage and
Chris@169 55 * recall criteria. The minimum size is the approximate amount of
Chris@170 56 * data in kilobytes that will be stored if the recommendation is
Chris@170 57 * to ConserveSpace; the maximum size is approximately the amount
Chris@169 58 * that will be used if UseAsMuchAsYouLike is returned.
Chris@170 59 *
Chris@170 60 * May throw InsufficientDiscSpace exception if there appears to
Chris@170 61 * be nowhere the minimum amount of data can be stored.
Chris@169 62 */
Chris@168 63 static Recommendation recommend(Criteria criteria,
Chris@1038 64 size_t minimumSize,
Chris@1038 65 size_t maximumSize);
Chris@205 66
Chris@205 67 enum AllocationArea {
Chris@205 68 MemoryAllocation,
Chris@205 69 DiscAllocation
Chris@205 70 };
Chris@205 71
Chris@205 72 /**
Chris@205 73 * Specify that we are planning to use a given amount of storage
Chris@205 74 * (in kilobytes), but haven't allocated it yet.
Chris@205 75 */
Chris@1038 76 static void notifyPlannedAllocation(AllocationArea area, size_t size);
Chris@205 77
Chris@205 78 /**
Chris@205 79 * Specify that we have now allocated, or abandoned the allocation
Chris@205 80 * of, the given amount (in kilobytes) of a storage area that was
Chris@205 81 * previously notified using notifyPlannedAllocation.
Chris@205 82 */
Chris@1038 83 static void notifyDoneAllocation(AllocationArea area, size_t size);
Chris@205 84
Chris@411 85 /**
Chris@411 86 * Force all subsequent recommendations to use the (perhaps
Chris@411 87 * partial) specification given here. If NoRecommendation given
Chris@411 88 * here, this will reset to the default free behaviour.
Chris@411 89 */
Chris@411 90 static void setFixedRecommendation(Recommendation recommendation);
Chris@411 91
Chris@205 92 private:
Chris@1038 93 static size_t m_discPlanned;
Chris@1038 94 static size_t m_memoryPlanned;
Chris@411 95 static Recommendation m_baseRecommendation;
Chris@1276 96
Chris@1276 97 enum StorageStatus {
Chris@1276 98 Unknown,
Chris@1276 99 Insufficient,
Chris@1276 100 Marginal,
Chris@1276 101 Sufficient
Chris@1276 102 };
Chris@1276 103
Chris@1276 104 static QString criteriaToString(int);
Chris@1276 105 static QString recommendationToString(int);
Chris@1276 106 static QString storageStatusToString(StorageStatus);
Chris@168 107 };
Chris@168 108
Chris@168 109 #endif
Chris@168 110