Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ on:
- '**'

jobs:
publish-nuget:
if: ${{ startsWith(github.ref, 'refs/tags/dotnet/') }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./dotnet
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.x
- name: Restore dependencies
run: dotnet restore
- name: Package C# library
run: dotnet pack Multiflag -c Release -o ./pkg
- name: Push to nuget.org
run: dotnet nuget push ./pkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

publish-npm:
if: ${{ startsWith(github.ref, 'refs/tags/node/') }}
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
dotnet-version: 9.x
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build /warnaserror
- name: Run tests
run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput='../coverage.xml'
- name: Report coverage
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,6 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*

*.sublime-workspace
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Multiflag is a tiny language-agnostic library that makes manipulating bitflags (
especially if you have flags that depend on each other (for example, if you're managing permissions).

- [Multiflag .NET](dotnet/README.md) [![Nuget Package](https://img.shields.io/nuget/v/Multiflag)](https://www.nuget.org/packages/Multiflag)
- [Multiflag JavaScript/TypeScript](node/README.md) [![npm](https://img.shields.io/npm/v/multiflag)](https://https://www.npmjs.com/package/multiflag)
- [Multiflag JavaScript/TypeScript](node/README.md) [![npm](https://img.shields.io/npm/v/multiflag)](https://www.npmjs.com/package/multiflag)


## What it does
Expand All @@ -27,16 +27,13 @@ This covers most of the common needs, but you can subclass `FlagSet` to work wit

## Compatible flag types

| .NET | JS | .NET (v1) | JS (v1) |
|:---------------------------------------------------------:|:----------------------------------------:|:----------:|:------------:|
| `U8BitflagSet` <br/> `EnumBitflagSet` backed by `byte` | `NumberBitflagSet` | `Flag8` | `NumberFlag` |
| `U16BitflagSet` <br/> `EnumBitflagSet` backed by `ushort` | `NumberBitflagSet` | `Flag16` | `NumberFlag` |
| `U32BitflagSet` <br/> `EnumBitflagSet` backed by `uint` | `NumberBitflagSet` | `Flag32` | `NumberFlag` |
| `U64BitflagSet` <br/> `EnumBitflagSet` backed by `ulong` | `DynamicBitflagSet` | `Flag64` | ✗ |
| `DynamicBitflagSet` | `DynamicBitflagSet` | ✗ | ✗ |
| `Base64BitflagSet` | `Base64BitflagSet` | ✗ | ✗ |
| `CollectionFlagSet` <br/> `ListFlagSet` | `CollectionFlagSet` <br/> `ArrayFlagSet` | `FlagSet` | `ArrayFlag` |
| ✗ | `NumberBitflagSet` | `FlagEnum` | `NumberFlag` |
| .NET | JS | .NET (v1) | JS (v1) |
|:---------------------------------------------------------:|:----------------------------------------:|:-------------------------------------:|:------------:|
| `U32BitflagSet` <br/> `EnumBitflagSet` backed by `uint` | `NumberBitflagSet` | `Flag8` <br/> `Flag16` <br/> `Flag32` | `NumberFlag` |
| `U64BitflagSet` <br/> `EnumBitflagSet` backed by `ulong` | `DynamicBitflagSet` | `Flag64` | ✗ |
| `DynamicBitflagSet` | `DynamicBitflagSet` | ✗ | ✗ |
| `Base64BitflagSet` | `Base64BitflagSet` | ✗ | ✗ |
| `CollectionFlagSet` <br/> `ListFlagSet` | `CollectionFlagSet` <br/> `ArrayFlagSet` | `FlagSet` | `ArrayFlag` |

## Why it exists

Expand All @@ -46,4 +43,4 @@ may come later.

## Licensing

Multiglag is available under the [MIT License](LICENSE). ⓒ 2023-2025 Louis DEVIE.
Multiflag is available under the [MIT License](LICENSE). ⓒ 2023-2025 Louis DEVIE.
11 changes: 11 additions & 0 deletions docs/Multiflag docs.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders":
[
{
"path": "source"
}
],
"settings": {
"rulers": [80]
}
}
30 changes: 30 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
alabaster==1.0.0
Babel==2.13.1
beautifulsoup4==4.12.2
certifi==2023.11.17
charset-normalizer==3.3.2
docutils==0.20.1
furo==2024.8.6
idna==3.6
imagesize==1.4.1
Jinja2==3.1.2
lxml==4.9.3
MarkupSafe==2.1.3
packaging==23.2
Pygments==2.17.2
PyYAML==6.0.2
requests==2.31.0
snowballstemmer==2.2.0
soupsieve==2.5
Sphinx==8.1.3
sphinx-basic-ng==1.0.0b2
sphinx-tabs==3.4.7
sphinxcontrib-applehelp==1.0.7
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-mermaid==1.0.0
sphinxcontrib-qthelp==1.0.6
sphinxcontrib-serializinghtml==1.1.9
tomli==2.2.1
urllib3==2.1.0
3 changes: 3 additions & 0 deletions docs/source/_static/overrides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sphinx-tabs-tab {
padding: 0.5rem 1rem !important;
}
128 changes: 128 additions & 0 deletions docs/source/common/flags.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
Flags
=====

A ``Flag`` represents some element of a set.

.. tabs::
.. code-tab:: cs

public class Flag<TSet>
{
public virtual bool IsAbstract { get; }

public virtual TSet AddTo(TSet flags);

public static TSet operator +(TSet value, Flag<TSet> flag);

public virtual TSet RemoveFrom(TSet flags);

public static TSet operator -(TSet value, Flag<TSet> flag);

public virtual bool IsIn(TSet flags);
}

.. code-tab:: ts

export class Flag<T> {
public readonly isAbstract: boolean

public addTo(flags: T): T

public removeFrom(flags: T): T

public isIn(flags: T): boolean
}

Add to set
----------

Adds a flag and its parents to a set if they are not already present. This
operation will return a new set of flags, or the same set if it hasn't been
modified. The input set will never be modified in-place.

.. tabs::
.. code-tab:: cs

var newSet = flag.AddTo(mySet);
var newSet = mySet + flag;
mySet += flag;

.. code-tab:: ts

const newSet = flag.addTo(mySet);

.. versionchanged:: 2.0
this method won't modify the set in-place anymore.
.. versionadded:: 1.0


Remove from set
---------------

Removes a flag and any of its children that appear in a set. This operation will
return a new set of flags, or the same set if it hasn't been modified. The input
set will never be modified in-place.

.. tabs::
.. code-tab:: cs

var newSet = flag.RemoveFrom(mySet);
var newSet = mySet - flag;
mySet -= flag;

.. code-tab:: ts

const newSet = flag.removeFrom(mySet);

.. versionchanged:: 2.0
this method won't modify the set in-place anymore.
.. versionadded:: 1.0


Is in set
---------

Tests if a flag and all its parents are present in a set.

.. tabs::
.. code-tab:: cs

if(flag.IsIn(mySet)) {
...
}

.. code-tab:: ts

if(flag.isIn(mySet)) {
...
}

.. versionchanged:: 2.0
this method is now called ``IsIn`` instead of ``In``.
.. versionadded:: 1.0


Is abstract
-----------

If this property is ``true``, it indicates that the flag has no value on its
own.

.. tabs::
.. code-tab:: cs

if(flag.IsAbstract) {
...
}

.. code-tab:: ts

if(flag.isAbstract) {
...
}

.. versionchanged:: 2.0
a value of ``true`` is equivalent to either ``IsAbstract`` or ``IsNothing``
being ``true`` in v1, and a value of ``false`` is equivalent to
``IsConcrete`` being ``true``.
.. versionadded:: 1.0
11 changes: 11 additions & 0 deletions docs/source/common/flagsets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Flagsets
========

A ``FlagSet`` is a group of flags that can be combined with each other.

Declaring a flagset
-------------------

Anonymous flagset
*****************

9 changes: 9 additions & 0 deletions docs/source/common/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Common APIs
===========

.. toctree::
:maxdepth: 2
:caption: Contents:

flagsets.rst
flags.rst
16 changes: 16 additions & 0 deletions docs/source/concepts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Concepts
========

Flags hierarchy
---------------

.. mermaid::
:align: center

flowchart TD
B(("B")) --> A(("A"))
C(("C")) --> A
D(("D")) --> B
E(("E")) --> B
F(("F")) --> C
class E,B,A mmd-node-added
15 changes: 12 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
# -- Project information -----------------------------------------------------

project = "Multiflag"
copyright = "2023, Louis DEVIE"
copyright = "2023-2025, Louis DEVIE"
author = "Louis DEVIE"

# The full version, including alpha/beta/rc tags
release = "1.0"
release = "2.0"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
extensions = ["sphinx_tabs.tabs", "sphinxcontrib.mermaid"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand All @@ -52,3 +52,12 @@
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]

html_css_files = ["overrides.css"]


# -- reST configuration ------------------------------------------------------

rst_prolog = """
.. role:: badge
"""
7 changes: 7 additions & 0 deletions docs/source/dotnet/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C# API
======

.. toctree::
:maxdepth: 2
:caption: Contents:

21 changes: 6 additions & 15 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
.. Multiflag documentation master file, created by
sphinx-quickstart on Sat Dec 9 14:29:33 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to Multiflag's documentation!
=====================================
Multiflag docs
==============

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
concepts
common/index.rst
dotnet/index.rst
node/index.rst
7 changes: 7 additions & 0 deletions docs/source/node/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
JavaScript API
==============

.. toctree::
:maxdepth: 2
:caption: Contents:

Loading