Skip to content

Protecting CachedValue #95

@greenwald

Description

@greenwald

Let us suppose we want to protect CachedValue's such that only the objects allowed to alter them can alter them.

using FingerPrint = void*;
constexpr UniversalFingerPrint = nullptr;

DataAccessor has private member FingerPrint FingerPrint_; created in constructor.
CachedValue has a private member FingerPrint FingerPrint_; handed in at construction.

Both classes have a const protected getter

protected:
const FingerPrint fingerPrint() const
{ return FingerPrint_; }

And now we alter:

CachedValue::setValue( ....., const FingerPrint& fp)
{
   if (fb != fingerPrint()) throw; 
   ...
}

In this way, DataAccessor decides either

  1. It gives its thumb print to the CachedValue it creates, so that only it can call setValue on it.
  2. Or it gives UniversalFingerPrint to the CachedValue as a finger print, meaning anyone can call setValue on it.

This could also all possibly be restructured such that we have a compile time error instead of a runtime error.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions