SiddiqSoft.RWLEnvelope 0.10.0-main0001

This is a prerelease version of SiddiqSoft.RWLEnvelope.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SiddiqSoft.RWLEnvelope --version 0.10.0-main0001                
NuGet\Install-Package SiddiqSoft.RWLEnvelope -Version 0.10.0-main0001                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SiddiqSoft.RWLEnvelope" Version="0.10.0-main0001" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SiddiqSoft.RWLEnvelope --version 0.10.0-main0001                
#r "nuget: SiddiqSoft.RWLEnvelope, 0.10.0-main0001"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SiddiqSoft.RWLEnvelope as a Cake Addin
#addin nuget:?package=SiddiqSoft.RWLEnvelope&version=0.10.0-main0001&prerelease

// Install SiddiqSoft.RWLEnvelope as a Cake Tool
#tool nuget:?package=SiddiqSoft.RWLEnvelope&version=0.10.0-main0001&prerelease                

RWLEnvelope : A simple read-writer lock wrapper for modern C++

CodeQL Build Status alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Objective

  • Avoid re-implementing the rw-lock; standard C++ (since C++14) has a good reader-writer lock implementation.
  • Provide a simple, convenience layer atop the underlying std::unique_lock and std::shared_lock access to some type.

WE DO NOT IMPLEMENT a read-writer lock, rather we provide a simple pattern where the most frequent use of the underlying facility is in a neat package.

Requirements

You must be able to use <shared_mutex> and <mutex>

The build and tests are for Visual Studio 2019 under x64.

Usage

  • Use the nuget SiddiqSoft.RWLEnvelope
  • Copy paste..whatever works.
  • Two methods: -- Observer/mutator model with callback and custom return
#include "gtest/gtest.h"

#include "nlohmann/json.hpp"
#include "../src/RWLEnvelope.hpp"


TEST(examples, WithCallbacks)
{
	siddiqsoft::RWLEnvelope<nlohmann::json> docl({{"foo", "bar"}, {"few", "lar"}});

	// Check we have pre-change value..
	EXPECT_EQ("bar", docl.observe<std::string>([](const auto& doc) { return doc.value("foo", ""); }));

	// Modify the item
	docl.mutate<void>([](auto& doc) { doc["foo"] = "bare"; });

	// Check we have pre-change value.. Note that here we return a boolean to avoid data copy
	EXPECT_TRUE(docl.observe<bool>([](const auto& doc) { return doc.value("foo", "").find("bare") == 0; }));

	// Check to make sure that the statistics match
	auto info = nlohmann::json(docl);
	EXPECT_EQ(1, info.value("readWriteActions", 0));
}


TEST(examples, WithDirectLocks)
{
	siddiqsoft::RWLEnvelope<nlohmann::json> docl({{"foo", "bar"}, {"few", "lar"}});

	// Check we have pre-change value..
	if (const auto& [doc, rl] = docl.readLock(); rl) { EXPECT_EQ("bar", doc.value("foo", "")); }

	// Modify the item
	if (auto& [doc, wl] = docl.writeLock(); wl) { doc["foo"] = "bare"; };

	// Check we have pre-change value.. Note that here we return a boolean to avoid data copy
	if (const auto& [doc, rl] = docl.readLock(); rl) { EXPECT_TRUE(doc.value("foo", "").find("bare") == 0); }
}

<small align="right">

© 2021 Siddiq Software LLC. All rights reserved.

</small>

Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SiddiqSoft.RWLEnvelope:

Package Downloads
SiddiqSoft.CosmosClient

Azure Cosmos REST-API Client for Modern C++

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 432 12/2/2021
1.1.0 9,054 7/22/2021
1.1.0-main0001 259 7/22/2021
1.0.0 1,459 7/22/2021
0.10.0-main0001 233 7/22/2021