| 1 | using System; |
|---|
| 2 | using System.Collections.Generic; |
|---|
| 3 | using System.Text; |
|---|
| 4 | |
|---|
| 5 | namespace Eraser.Manager |
|---|
| 6 | { |
|---|
| 7 | public partial class Globals |
|---|
| 8 | { |
|---|
| 9 | internal static PRNGManager PRNGManager = new PRNGManager(); |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | /// <summary> |
|---|
| 13 | /// An interface class for all pseudorandom number generators used for the |
|---|
| 14 | /// random data erase passes. |
|---|
| 15 | /// </summary> |
|---|
| 16 | public abstract class PRNG : Random |
|---|
| 17 | { |
|---|
| 18 | public override string ToString() |
|---|
| 19 | { |
|---|
| 20 | return Name; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | /// <summary> |
|---|
| 24 | /// The name of this erase pass, used for display in the UI |
|---|
| 25 | /// </summary> |
|---|
| 26 | public abstract string Name |
|---|
| 27 | { |
|---|
| 28 | get; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | /// <summary> |
|---|
| 32 | /// The GUID for this PRNG. |
|---|
| 33 | /// </summary> |
|---|
| 34 | public abstract Guid GUID |
|---|
| 35 | { |
|---|
| 36 | get; |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /// <summary> |
|---|
| 41 | /// Class managing all the PRNG algorithms. |
|---|
| 42 | /// </summary> |
|---|
| 43 | public class PRNGManager |
|---|
| 44 | { |
|---|
| 45 | /// <summary> |
|---|
| 46 | /// Retrieves all currently registered erasure methods. |
|---|
| 47 | /// </summary> |
|---|
| 48 | /// <returns>A mutable list, with an instance of each PRNG.</returns> |
|---|
| 49 | public static Dictionary<Guid, PRNG> GetAll() |
|---|
| 50 | { |
|---|
| 51 | lock (Globals.PRNGManager.prngs) |
|---|
| 52 | return Globals.PRNGManager.prngs; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | /// <summary> |
|---|
| 56 | /// Allows plug-ins to register PRNGs with the main program. Thread-safe. |
|---|
| 57 | /// </summary> |
|---|
| 58 | /// <param name="method"></param> |
|---|
| 59 | public static void Register(PRNG prng) |
|---|
| 60 | { |
|---|
| 61 | lock (Globals.PRNGManager.prngs) |
|---|
| 62 | Globals.PRNGManager.prngs.Add(prng.GUID, prng); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /// <summary> |
|---|
| 66 | /// The list of currently registered erasure methods. |
|---|
| 67 | /// </summary> |
|---|
| 68 | private Dictionary<Guid, PRNG> prngs = new Dictionary<Guid, PRNG>(); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|