annotate base/StorageAdviser.h @ 661:a4faa1840384

* If a FileSource URL won't convert at all in strict mode, try again in tolerant mode (necessary for e.g. filenames with square brackets in them)
author Chris Cannam
date Tue, 19 Oct 2010 21:47:55 +0100
parents 52303ec15cd2
children cc27f35aa75c
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@168 17 #ifndef _STORAGE_ADVISER_H_
Chris@168 18 #define _STORAGE_ADVISER_H_
Chris@168 19
Chris@168 20 /**
Chris@168 21 * A utility class designed to help decide whether to store cache data
Chris@168 22 * (for example FFT outputs) in memory or on disk in the TempDirectory.
Chris@170 23 * This is basically a compendium of simple rules of thumb.
Chris@168 24 */
Chris@168 25
Chris@168 26 class StorageAdviser
Chris@168 27 {
Chris@168 28 public:
Chris@168 29 // pass to recommend() zero or more of these OR'd together
Chris@168 30 enum Criteria {
Chris@170 31 NoCriteria = 0,
Chris@170 32 SpeedCritical = 1,
Chris@170 33 PrecisionCritical = 2,
Chris@170 34 LongRetentionLikely = 4,
Chris@170 35 FrequentLookupLikely = 8
Chris@168 36 };
Chris@168 37
Chris@168 38 // recommend() returns one or two of these OR'd together
Chris@168 39 enum Recommendation {
Chris@170 40 NoRecommendation = 0,
Chris@170 41 UseMemory = 1, // Disc is strongly contraindicated
Chris@170 42 PreferMemory = 2, // Either would do; memory probably better
Chris@170 43 PreferDisc = 4, // Either would do; disc probably better
Chris@170 44 UseDisc = 8, // Probably won't fit in memory
Chris@170 45 ConserveSpace = 16,// Whatever you choose, keep it compact
Chris@170 46 UseAsMuchAsYouLike = 32 // Take my advice and there'll be space for all
Chris@168 47 };
Chris@168 48
Chris@169 49 /**
Chris@169 50 * Recommend where to store some data, given certain storage and
Chris@169 51 * recall criteria. The minimum size is the approximate amount of
Chris@170 52 * data in kilobytes that will be stored if the recommendation is
Chris@170 53 * to ConserveSpace; the maximum size is approximately the amount
Chris@169 54 * that will be used if UseAsMuchAsYouLike is returned.
Chris@170 55 *
Chris@170 56 * May throw InsufficientDiscSpace exception if there appears to
Chris@170 57 * be nowhere the minimum amount of data can be stored.
Chris@169 58 */
Chris@168 59 static Recommendation recommend(Criteria criteria,
Chris@168 60 int minimumSize,
Chris@168 61 int maximumSize);
Chris@205 62
Chris@205 63 enum AllocationArea {
Chris@205 64 MemoryAllocation,
Chris@205 65 DiscAllocation
Chris@205 66 };
Chris@205 67
Chris@205 68 /**
Chris@205 69 * Specify that we are planning to use a given amount of storage
Chris@205 70 * (in kilobytes), but haven't allocated it yet.
Chris@205 71 */
Chris@205 72 static void notifyPlannedAllocation(AllocationArea area, int size);
Chris@205 73
Chris@205 74 /**
Chris@205 75 * Specify that we have now allocated, or abandoned the allocation
Chris@205 76 * of, the given amount (in kilobytes) of a storage area that was
Chris@205 77 * previously notified using notifyPlannedAllocation.
Chris@205 78 */
Chris@205 79 static void notifyDoneAllocation(AllocationArea area, int size);
Chris@205 80
Chris@411 81 /**
Chris@411 82 * Force all subsequent recommendations to use the (perhaps
Chris@411 83 * partial) specification given here. If NoRecommendation given
Chris@411 84 * here, this will reset to the default free behaviour.
Chris@411 85 */
Chris@411 86 static void setFixedRecommendation(Recommendation recommendation);
Chris@411 87
Chris@205 88 private:
Chris@205 89 static long m_discPlanned;
Chris@205 90 static long m_memoryPlanned;
Chris@411 91 static Recommendation m_baseRecommendation;
Chris@168 92 };
Chris@168 93
Chris@168 94 #endif
Chris@168 95