Skip to content

Commit

Permalink
Storage events (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
imurashka committed Sep 20, 2024
1 parent 9edeb75 commit ec474ce
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 273 deletions.
59 changes: 16 additions & 43 deletions Runtime/BinaryStorage.Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public partial class BinaryStorage
static partial void ThrowIfFilePathLocked(string filePath);
static partial void UnlockFilePathInEditor(string filePath);

/// <summary>
/// Creates and configures a new instance of <see cref="BinaryStorage"/> with default settings.
/// </summary>
/// <summary> Creates and configures a new instance of <see cref="BinaryStorage"/> with default settings. </summary>
/// <param name="filePath">The file path for the storage.</param>
/// <returns>A configured <see cref="BinaryStorage"/> instance.</returns>
public static BinaryStorage Get(string filePath)
Expand All @@ -24,9 +22,7 @@ public static BinaryStorage Get(string filePath)
.Build();
}

/// <summary>
/// Begins the construction of a new <see cref="BinaryStorage"/> instance.
/// </summary>
/// <summary> Begins the construction of a new <see cref="BinaryStorage"/> instance. </summary>
/// <param name="filePath">The file path for the storage.</param>
/// <returns>A <see cref="Builder"/> for configuring the <see cref="BinaryStorage"/> instance.</returns>
public static Builder Construct(string filePath)
Expand All @@ -36,9 +32,7 @@ public static Builder Construct(string filePath)
return new Builder(filePath);
}

/// <summary>
/// Deletes the storage file at the specified path.
/// </summary>
/// <summary> Deletes the storage file at the specified path. </summary>
/// <param name="storagePath">The path to the storage file.</param>
internal static void Delete(string storagePath)
{
Expand All @@ -48,9 +42,7 @@ internal static void Delete(string storagePath)
}
}

/// <summary>
/// Provides a fluent interface for configuring and building a <see cref="BinaryStorage"/> instance.
/// </summary>
/// <summary> Provides a fluent interface for configuring and building a <see cref="BinaryStorage"/> instance. </summary>
public class Builder
{
private readonly string _filePath;
Expand All @@ -64,28 +56,22 @@ internal Builder(string filePath)
_filePath = filePath;
}

/// <summary>
/// Enables automatic saving of changes to the storage.
/// </summary>
/// <summary> Enables automatic saving of changes to the storage. </summary>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
public Builder EnableAutoSaveOnChange()
{
_autoSave = true;
return this;
}

/// <summary>
/// Specifies the behavior when a requested key is not found in the storage.
/// </summary>
/// <summary> Specifies the behavior when a requested key is not found in the storage. </summary>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
public Builder SetMissingKeyBehaviour(MissingKeyBehavior behavior)
{
_missingKeyBehavior = behavior;
return this;
}
/// <summary>
/// Specifies the behavior when the type of value associated with a key does not match the expected type.
/// </summary>
/// <summary> Specifies the behavior when the type of value associated with a key does not match the expected type. </summary>
/// <param name="behavior">The type mismatch behavior.</param>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
public Builder SetTypeMismatchBehaviour(TypeMismatchBehaviour behavior)
Expand All @@ -94,9 +80,7 @@ public Builder SetTypeMismatchBehaviour(TypeMismatchBehaviour behavior)
return this;
}

/// <summary>
/// Adds serializers for primitive types to the storage configuration.
/// </summary>
/// <summary> Adds serializers for primitive types to the storage configuration. </summary>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
public Builder AddPrimitiveTypes()
{
Expand Down Expand Up @@ -124,9 +108,7 @@ public Builder AddPrimitiveTypes()
.AddTypeSerializer(Vector3IntSerializer.Shared);
}

/// <summary>
/// Adds a serializer for a specified type to the storage configuration.
/// </summary>
/// <summary> Adds a serializer for a specified type to the storage configuration. </summary>
/// <typeparam name="T">The type to be serialized.</typeparam>
/// <param name="typeSerializer">The serializer for the specified type.</param>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
Expand All @@ -141,9 +123,7 @@ public Builder AddTypeSerializer<T>(TypeSerializer<T> typeSerializer)
return this;
}

/// <summary>
/// Adds support for a specified enum type to the storage configuration.
/// </summary>
/// <summary> Adds support for a specified enum type to the storage configuration. </summary>
/// <typeparam name="T">The enum type to be supported.</typeparam>
/// <param name="useFullName">Whether to use the full name of the enum type.</param>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
Expand Down Expand Up @@ -185,9 +165,7 @@ public Builder SupportEnum<T>(bool useFullName = false)
return this;
}

/// <summary>
/// Adds support for lists of a specified type to the storage configuration.
/// </summary>
/// <summary> Adds support for lists of a specified type to the storage configuration. </summary>
/// <typeparam name="T">The type of elements in the list.</typeparam>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
/// <exception cref="CantSupportCollectionOfException">Thrown if the specified type is not supported.</exception>
Expand All @@ -201,9 +179,7 @@ public Builder SupportListsOf<T>()
return AddTypeSerializer(new CollectionTypeSerializer<T, ReactiveList<T>>(section.Serializer));
}

/// <summary>
/// Adds support for sets of a specified type to the storage configuration.
/// </summary>
/// <summary> Adds support for sets of a specified type to the storage configuration. </summary>
/// <typeparam name="T">The type of elements in the set.</typeparam>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
/// <exception cref="CantSupportCollectionOfException">Thrown if the specified type is not supported.</exception>
Expand All @@ -217,9 +193,7 @@ public Builder SupportSetsOf<T>()
return AddTypeSerializer(new CollectionTypeSerializer<T, ReactiveSet<T>>(section.Serializer));
}

/// <summary>
/// Adds support for dictionaries of specified key and value types to the storage configuration.
/// </summary>
/// <summary> Adds support for dictionaries of specified key and value types to the storage configuration. </summary>
/// <typeparam name="TKey">The type of the dictionary keys.</typeparam>
/// <typeparam name="TValue">The type of the dictionary values.</typeparam>
/// <returns>The current <see cref="Builder"/> instance for method chaining.</returns>
Expand All @@ -236,11 +210,10 @@ public Builder SupportDictionariesOf<TKey, TValue>()
return AddTypeSerializer(new CollectionTypeSerializer<KeyValuePair<TKey, TValue>, ReactiveDictionary<TKey, TValue>>(kvSerializer));
}

/// <summary>
/// Builds and returns the configured <see cref="BinaryStorage"/> instance.
/// </summary>
/// <summary> Builds and returns the configured <see cref="BinaryStorage"/> instance. </summary>
/// <returns>The configured <see cref="BinaryStorage"/> instance.</returns>
/// <exception cref="Exception">Thrown if the storage fails to load data from disk.</exception>
/// <exception cref="ObjectDisposedException">Thrown if the storage is disposed.</exception>
/// <exception cref="IOException"> An I/O error occurred </exception>
public BinaryStorage Build()
{
try
Expand Down
Loading

0 comments on commit ec474ce

Please sign in to comment.