All Projects → funkwerk → accessors

funkwerk / accessors

Licence: BSL-1.0 license
Generate D getters and setters automatically

Programming Languages

d
599 projects

Projects that are alternatives of or similar to accessors

lombok-rs
Lombok port for Rust
Stars: ✭ 31 (+55%)
Mutual labels:  setters, getters
vscode-java-saber
⚔️ To make the vscode work as Eclipse or IDEA when you are coding in java.
Stars: ✭ 28 (+40%)
Mutual labels:  setters, getters
laravel-cachable-attributes
Allows to cache attribute accessor values in an easy way.
Stars: ✭ 24 (+20%)
Mutual labels:  accessor
stateware
Smart state container with easy copy and auto memoized getters
Stars: ✭ 20 (+0%)
Mutual labels:  getters
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (+60%)
Mutual labels:  accessor
v-bucket
📦 Fast, Simple, and Lightweight State Manager for Vue 3.0 built with composition API, inspired by Vuex.
Stars: ✭ 42 (+110%)
Mutual labels:  getters
nativescript-getters
A NativeScript plugin that adds six new getters – in addition to the native "getViewById" method – to retrieve one or more views by tag, type, class, style, value pair or property.
Stars: ✭ 12 (-40%)
Mutual labels:  getters
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (+30%)
Mutual labels:  accessor
magicproperties
A little but powerful package that allows you call getters and setters implicitly in PHP.
Stars: ✭ 13 (-35%)
Mutual labels:  accessor
concurrent-resource
A header-only C++ library that allows easily creating thread-safe, concurrency friendly resources.
Stars: ✭ 17 (-15%)
Mutual labels:  accessor

accessors

Build Status License Dub Version codecov

accessors module allows to generate getters and setters automatically.

Deprecation warning: accessors has been succeeded by boilerplate.

Usage

import accessors;

class WithAccessors
{
    @Read @Write
    private int num_;

    mixin(GenerateFieldAccessors);
}

@Read and @Write generate the following two methods:

public final @property auto num() inout @nogc nothrow pure @safe
{
    return this.num_;
}

public final @property void num(int num) @nogc nothrow pure @safe
{
    this.num_ = num;
}

The accessors names are derived from the appropriate member variables by removing an underscore from the beginning or the end of the variable name.

Available user defined attributes

  • @Read
  • @ConstRead
  • @Write

As you can see there are multiple attributes that can be used to generate getters and only one for the setters. The getters differ by the return type. @Read returns an inout value, @ConstRead - a const value.

Accessor visibility

Visibility of the generated accessors is by default public, but it can be changed. In order to achieve this, you have to pass public, protected, private or package as argument to the attribute:

import accessors;

class WithAccessors
{
    @Read("public") @Write("protected")
    private int num_;

    mixin(GenerateFieldAccessors);
}

Example

import accessors;
import std.stdio;

class Person
{
    @Read @Write
    private uint age_;

    @ConstRead
    private string name_;

    this(in string name, in uint age = 0)
    {
        this.name_ = name;
        this.age_ = age;
    }

    mixin(GenerateFieldAccessors);
}

void main()
{
    auto person = new Person("Saul Kripke");

    person.age = 57;

    writeln(person.name, ": ", person.age);
}

Bugs

If you experience compile-time problems, open an issue with the information about the type of the member variable fails.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].