Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
IOdbBackend.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 using System.IO;
5 using SiliconStudio.Core.IO;
6 using SiliconStudio.Core.Serialization.Assets;
7 
8 namespace SiliconStudio.Core.Storage
9 {
10  /// <summary>
11  /// Base class for custom object database backends (ODB).
12  /// </summary>
13  public interface IOdbBackend
14  {
15  /// <summary>
16  /// Gets the asset index map.
17  /// </summary>
18  /// <value>
19  /// The asset index map.
20  /// </value>
22 
23  /// <summary>
24  /// Opens a <see cref="NativeStream" /> of the object with the specified <see cref="ObjectId" />.
25  /// </summary>
26  /// <param name="objectId">The <see cref="ObjectId" />.</param>
27  /// <param name="mode">The mode.</param>
28  /// <param name="access">The access.</param>
29  /// <param name="share">The process share mode.</param>
30  /// <returns>
31  /// A <see cref="NativeStream" /> opened from the specified <see cref="ObjectId" />.
32  /// </returns>
33  Stream OpenStream(ObjectId objectId, VirtualFileMode mode = VirtualFileMode.Open, VirtualFileAccess access = VirtualFileAccess.Read, VirtualFileShare share = VirtualFileShare.Read);
34 
35  /// <summary>
36  /// Requests that this backend read an object's length (but not its contents).
37  /// </summary>
38  /// <param name="objectId">The <see cref="ObjectId"/>.</param>
39  /// <returns>The object size.</returns>
40  int GetSize(ObjectId objectId);
41 
42  /// <summary>
43  /// Writes an object to the backing store.
44  /// The backend may need to compute the object ID and return it to the caller.
45  /// </summary>
46  /// <param name="objectId">The <see cref="ObjectId"/> if already computed, or <see cref="ObjectId.Empty"/> if not determined yet.</param>
47  /// <param name="dataStream">The data stream.</param>
48  /// <param name="length">The data length.</param>
49  /// <param name="forceWrite">Set to true to force writing the datastream even if a content is already stored with the same id. Default is false.</param>
50  /// <returns>The generated <see cref="ObjectId"/>.</returns>
51  ObjectId Write(ObjectId objectId, Stream dataStream, int length, bool forceWrite = false);
52 
53  /// <summary>
54  /// Creates a stream that will be saved to database when closed and/or disposed.
55  /// </summary>
56  /// <returns>a stream writer that should be passed to <see cref="SaveStream"/> in order to be stored in the database</returns>
57  OdbStreamWriter CreateStream();
58 
59  /// <summary>
60  /// Determines weither the object with the specified <see cref="ObjectId"/> exists.
61  /// </summary>
62  /// <param name="objectId">The <see cref="ObjectId"/> to check existence for.</param>
63  /// <returns><c>true</c> if an object with the specified <see cref="ObjectId"/> exists; otherwise, <c>false</c>.</returns>
64  bool Exists(ObjectId objectId);
65 
66  /// <summary>
67  /// Enumerates the object stored in this backend.
68  /// </summary>
69  /// <returns></returns>
70  IEnumerable<ObjectId> EnumerateObjects();
71 
72  /// <summary>
73  /// Deletes the specified <see cref="ObjectId"/>.
74  /// </summary>
75  /// <param name="objectId">The object id.</param>
76  void Delete(ObjectId objectId);
77 
78  /// <summary>
79  /// Returns the file path corresponding to the given id (in the VFS domain), if appliable.
80  /// </summary>
81  /// <param name="objectId">The <see cref="ObjectId"/>.</param>
82  /// <returns>The file path.</returns>
83  string GetFilePath(ObjectId objectId);
84  }
85 }
VirtualFileShare
File share capabilities, equivalent of System.IO.FileShare.
Base class for custom object database backends (ODB).
Definition: IOdbBackend.cs:13
VirtualFileAccess
File access equivalent of System.IO.FileAccess.
VirtualFileMode
File mode equivalent of System.IO.FileMode.
A hash to uniquely identify data.
Definition: ObjectId.cs:13